Documentation
¶
Overview ¶
Package messaging provides the implemetation to connect to pubnub api. Build Date: Sep 5, 2014 Version: 3.6
Index ¶
- func DecryptString(cipherKey string, message string) (retVal interface{}, err error)
- func EncryptString(cipherKey string, message string) string
- func GenUuid() (string, error)
- func GetNonSubscribeTimeout() uint16
- func GetSubscribeTimeout() uint16
- func Logging() bool
- func LoggingEnabled(val bool)
- func ParseInterfaceData(myInterface interface{}) string
- func ParseJSON(contents []byte, cipherKey string) (string, string, string, error)
- func SetConnectTimeout(val uint16)
- func SetIV(val string)
- func SetLogOutput(val io.Writer)
- func SetMaxRetries(val int)
- func SetNonSubscribeTimeout(val uint16)
- func SetOrigin(val string)
- func SetProxy(proxyServerVal string, proxyPortVal int, proxyUserVal string, ...)
- func SetResumeOnReconnect(val bool)
- func SetRetryInterval(val uint16)
- func SetSubscribeTimeout(val uint16)
- func VersionInfo() string
- type Pubnub
- func (pub *Pubnub) Abort()
- func (pub *Pubnub) AuditPresence(channel string, callbackChannel chan []byte, errorChannel chan []byte)
- func (pub *Pubnub) AuditSubscribe(channel string, callbackChannel chan []byte, errorChannel chan []byte)
- func (pub *Pubnub) CloseExistingConnection()
- func (pub *Pubnub) GetAuthenticationKey() string
- func (pub *Pubnub) GetPresenceHeartbeat() uint16
- func (pub *Pubnub) GetPresenceHeartbeatInterval() uint16
- func (pub *Pubnub) GetTime(callbackChannel chan []byte, errorChannel chan []byte)
- func (pub *Pubnub) GetUUID() string
- func (pub *Pubnub) GetUserState(channel string, callbackChannel chan []byte, errorChannel chan []byte)
- func (pub *Pubnub) GlobalHereNow(showUuid bool, includeUserState bool, callbackChannel chan []byte, ...)
- func (pub *Pubnub) GrantPresence(channel string, read bool, write bool, ttl int, callbackChannel chan []byte, ...)
- func (pub *Pubnub) GrantSubscribe(channel string, read bool, write bool, ttl int, callbackChannel chan []byte, ...)
- func (pub *Pubnub) HereNow(channel string, showUuid bool, includeUserState bool, ...)
- func (pub *Pubnub) History(channel string, limit int, start int64, end int64, reverse bool, ...)
- func (pub *Pubnub) PresenceUnsubscribe(channels string, callbackChannel chan []byte, errorChannel chan []byte)
- func (pub *Pubnub) Publish(channel string, message interface{}, callbackChannel chan []byte, ...)
- func (pub *Pubnub) SetAuthenticationKey(val string)
- func (pub *Pubnub) SetPresenceHeartbeat(val uint16)
- func (pub *Pubnub) SetPresenceHeartbeatInterval(val uint16)
- func (pub *Pubnub) SetUUID(val string)
- func (pub *Pubnub) SetUserStateJSON(channel string, jsonString string, callbackChannel chan []byte, ...)
- func (pub *Pubnub) SetUserStateKeyVal(channel string, key string, val string, callbackChannel chan []byte, ...)
- func (pub *Pubnub) Subscribe(channels string, timetoken string, callbackChannel chan []byte, ...)
- func (pub *Pubnub) Unsubscribe(channels string, callbackChannel chan []byte, errorChannel chan []byte)
- func (pub *Pubnub) WhereNow(uuid string, callbackChannel chan []byte, errorChannel chan []byte)
- type PubnubUnitTest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecryptString ¶
DecryptString decodes encrypted string using the cipherKey
It accepts the following parameters: cipherKey: cipher key to use to decrypt. message: to encrypted.
returns the unencoded encrypted string, error if any.
func EncryptString ¶
EncryptString creates the base64 encoded encrypted string using the cipherKey. It accepts the following parameters: cipherKey: cipher key to use to encrypt. message: to encrypted.
returns the base64 encoded encrypted string.
func GetNonSubscribeTimeout ¶
func GetNonSubscribeTimeout() uint16
GetNonSubscribeTimeout gets the value of nonSubscribeTimeout
func GetSubscribeTimeout ¶
func GetSubscribeTimeout() uint16
GetSubscribeTimeout gets the value of subscribeTimeout
func Logging ¶
func Logging() bool
Logging gets the value of loggingEnabled If true logs will be written to a file
func LoggingEnabled ¶
func LoggingEnabled(val bool)
LoggingEnabled sets the value of loggingEnabled If true logs will be written to the logfileWriter In addition to LoggingEnabled you also need to init the logfileWriter using SetLogOutput
func ParseInterfaceData ¶
func ParseInterfaceData(myInterface interface{}) string
ParseInterfaceData formats the data to string as per the type of the data.
It accepts the following parameters: myInterface: the interface data to parse and convert to string.
returns: the data in string format.
func ParseJSON ¶
ParseJSON parses the json data. It extracts the actual data (value 0), Timetoken/from time in case of detailed history (value 1), pubnub channelname/timetoken/to time in case of detailed history (value 2).
It accepts the following parameters: contents: the contents to parse. cipherKey: the key to decrypt the messages (can be empty).
returns: data: as string. Timetoken/from time in case of detailed history as string. pubnub channelname/timetoken/to time in case of detailed history (value 2). error if any.
func SetConnectTimeout ¶
func SetConnectTimeout(val uint16)
SetConnectTimeout sets the value of connectTimeout.
func SetLogOutput ¶
SetLogOutput sets the full path of the logfile Default name is pubnubMessaging.log and is located in the same dir from where the go file is run In addition to this LoggingEnabled should be true for this to work.
func SetNonSubscribeTimeout ¶
func SetNonSubscribeTimeout(val uint16)
SetNonSubscribeTimeout sets the value of nonsubscribeTimeout.
func SetOrigin ¶
func SetOrigin(val string)
SetOrigin sets the value of _origin. Should be called before PubnubInit
func SetProxy ¶
func SetProxy(proxyServerVal string, proxyPortVal int, proxyUserVal string, proxyPasswordVal string)
SetProxy sets the global variables for the parameters. It also sets the proxyServerEnabled value to true.
It accepts the following parameters: proxyServer proxy server name or ip. proxyPort proxy port. proxyUser proxyUserName. proxyPassword proxyPassword.
func SetResumeOnReconnect ¶
func SetResumeOnReconnect(val bool)
SetResumeOnReconnect sets the value of resumeOnReconnect.
func SetRetryInterval ¶
func SetRetryInterval(val uint16)
SetRetryInterval sets the value of retryInterval.
func SetSubscribeTimeout ¶
func SetSubscribeTimeout(val uint16)
SetSubscribeTimeout sets the value of subscribeTimeout.
func VersionInfo ¶
func VersionInfo() string
VersionInfo returns the version of the this code along with the build date.
Types ¶
type Pubnub ¶
Pubnub structure. origin stores the root url value of pubnub api in the current instance. publishKey stores the user specific Publish Key in the current instance. subscribeKey stores the user specific Subscribe Key in the current instance. secretKey stores the user specific Secret Key in the current instance. cipherKey stores the user specific Cipher Key in the current instance. authenticationKey stores the Authentication Key in the current instance. isSSL is true if enabled, else is false for the current instance. uuid is the unique identifier, it can be a custom value or is automatically generated. subscribedChannels keeps a list of subscribed Pubnub channels by the user in the a comma separated string. timeToken is the current value of the servertime. This will be used to appened in each request. sentTimeToken: This is the timetoken sent to the server with the request resetTimeToken: In case of a new request or an error this variable is set to true so that the timeToken will be set to 0 in the next request. presenceChannels: All the presence responses will be routed to this channel. It stores the response channels for each pubnub channel as map using the pubnub channel name as the key. subscribeChannels: All the subscribe responses will be routed to this channel. It stores the response channels for each pubnub channel as map using the pubnub channel name as the key. presenceErrorChannels: All the presence error responses will be routed to this channel. It stores the response channels for each pubnub channel as map using the pubnub channel name as the key. subscribeErrorChannels: All the subscribe error responses will be routed to this channel. It stores the response channels for each pubnub channel as map using the pubnub channel name as the key. newSubscribedChannels keeps a list of the new subscribed Pubnub channels by the user in the a comma separated string, before they are appended to the Pubnub SubscribedChannels. isPresenceHeartbeatRunning a variable to keep a check on the presence heartbeat's status Mutex to lock the operations on the instance
func NewPubnub ¶
func NewPubnub(publishKey string, subscribeKey string, secretKey string, cipherKey string, sslOn bool, customUuid string) *Pubnub
NewPubnub initializes pubnub struct with the user provided values. And then initiates the origin by appending the protocol based upon the sslOn argument. Then it uses the customuuid or generates the uuid.
It accepts the following parameters: publishKey is the user specific Publish Key. Mandatory. subscribeKey is the user specific Subscribe Key. Mandatory. secretKey is the user specific Secret Key. Accepts empty string if not used. cipherKey stores the user specific Cipher Key. Accepts empty string if not used. sslOn is true if enabled, else is false. customUuid is the unique identifier, it can be a custom value or sent as empty for automatic generation.
returns the pointer to Pubnub instance.
func (*Pubnub) Abort ¶
func (pub *Pubnub) Abort()
Abort is the struct Pubnub's instance method that closes the open connections for both subscribe and non-subscribe requests.
It also sends a leave request for all the subscribed channel and sets the pub.SubscribedChannels as empty to break the loop in the func StartSubscribeLoop
func (*Pubnub) AuditPresence ¶
func (pub *Pubnub) AuditPresence(channel string, callbackChannel chan []byte, errorChannel chan []byte)
AuditPresence will make a call to display the permissions for a channel or subkey
channel is options and if not provided will set the permissions at subkey level
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) AuditSubscribe ¶
func (pub *Pubnub) AuditSubscribe(channel string, callbackChannel chan []byte, errorChannel chan []byte)
AuditSubscribe will make a call to display the permissions for a channel or subkey
channel is options and if not provided will set the permissions at subkey level
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) CloseExistingConnection ¶
func (pub *Pubnub) CloseExistingConnection()
CloseExistingConnection closes the open subscribe/presence connection.
func (*Pubnub) GetAuthenticationKey ¶
GetAuthenticationKey gets the value of authentication key
func (*Pubnub) GetPresenceHeartbeat ¶
GetPresenceHeartbeat gets the value of presenceHeartbeat
func (*Pubnub) GetPresenceHeartbeatInterval ¶
GetPresenceHeartbeatInterval gets the value of presenceHeartbeatInterval
func (*Pubnub) GetTime ¶
GetTime is the struct Pubnub's instance method that calls the ExecuteTime method to process the time request. . It accepts the following parameters: callbackChannel on which to send the response. errorChannel on which to send the error response.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) GetUserState ¶
func (pub *Pubnub) GetUserState(channel string, callbackChannel chan []byte, errorChannel chan []byte)
GetUserState is the struct Pubnub's instance method which creates and posts the GetUserState request to get the connected users details.
It accepts the following parameters: channel: a single value of the pubnub channel. callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) GlobalHereNow ¶
func (pub *Pubnub) GlobalHereNow(showUuid bool, includeUserState bool, callbackChannel chan []byte, errorChannel chan []byte)
GlobalHereNow is the struct Pubnub's instance method which creates and posts the globalherenow request to get the connected users details.
It accepts the following parameters: showUuid: if true uuids of devices will be fetched in the respose includeUserState: if true the user states of devices will be fetched in the respose callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) GrantPresence ¶
func (pub *Pubnub) GrantPresence(channel string, read bool, write bool, ttl int, callbackChannel chan []byte, errorChannel chan []byte)
GrantPresence is used to give a presence channel read, write permissions and set TTL values for it. To grant a permission set read or write as true to revoke all perms set read and write false and ttl as -1
channel is options and if not provided will set the permissions at subkey level
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) GrantSubscribe ¶
func (pub *Pubnub) GrantSubscribe(channel string, read bool, write bool, ttl int, callbackChannel chan []byte, errorChannel chan []byte)
GrantSubscribe is used to give a subscribe channel read, write permissions and set TTL values for it. To grant a permission set read or write as true to revoke all perms set read and write false and ttl as -1
channel is options and if not provided will set the permissions at subkey level
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) HereNow ¶
func (pub *Pubnub) HereNow(channel string, showUuid bool, includeUserState bool, callbackChannel chan []byte, errorChannel chan []byte)
HereNow is the struct Pubnub's instance method which creates and posts the herenow request to get the connected users details.
It accepts the following parameters: channel: a single value of the pubnub channel. callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) History ¶
func (pub *Pubnub) History(channel string, limit int, start int64, end int64, reverse bool, callbackChannel chan []byte, errorChannel chan []byte)
History is the struct Pubnub's instance method which creates and post the History request for a single pubnub channel.
It parses the response to get the data and return it to the channel.
It accepts the following parameters: channel: a single value of the pubnub channel. limit: number of history messages to return. start: start time from where to begin the history messages. end: end time till where to get the history messages. reverse: to fetch the messages in ascending order callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) PresenceUnsubscribe ¶
func (pub *Pubnub) PresenceUnsubscribe(channels string, callbackChannel chan []byte, errorChannel chan []byte)
PresenceUnsubscribe is the struct Pubnub's instance method which unsubscribes a pubnub presence channel(s) from the subscribe loop.
If all the pubnub channels are not removed the method StartSubscribeLoop will take care of it by starting a new loop. When the pubnub channel(s) are removed it creates and posts a leave request.
It accepts the following parameters: channels: the pubnub channel(s) in a comma separated string. callbackChannel: Channel on which to send the response back. errorChannel: channel to send an error response to.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) Publish ¶
func (pub *Pubnub) Publish(channel string, message interface{}, callbackChannel chan []byte, errorChannel chan []byte)
Publish is the struct Pubnub's instance method that creates a publish request and calls SendPublishRequest to post the request.
It calls the InvalidChannel and InvalidMessage methods to validate the Pubnub channels and message. Calls the GetHmacSha256 to generate a signature if a secretKey is to be used. Creates the publish url Calls json marshal Calls the EncryptString method is the cipherkey is used and calls json marshal Closes the channel after the response is received
It accepts the following parameters: channel: The Pubnub channel to which the message is to be posted. message: message to be posted. callbackChannel: Channel on which to send the response back. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) SetAuthenticationKey ¶
SetAuthenticationKey sets the value of authentication key
func (*Pubnub) SetPresenceHeartbeat ¶
SetPresenceHeartbeat sets the value of presence heartbeat. When the presence heartbeat is set the presenceHeartbeatInterval is automatically set to (presenceHeartbeat / 2) - 1 Starts the presence heartbeat request if both presenceHeartbeatInterval and presenceHeartbeat are set and a presence notifications are subsribed
func (*Pubnub) SetPresenceHeartbeatInterval ¶
SetPresenceHeartbeatInterval sets the value of presenceHeartbeatInterval. If the value is greater than presenceHeartbeat and there is a value set for presenceHeartbeat then is automatically set to (presenceHeartbeat / 2) - 1 Starts the presence heartbeat request if both presenceHeartbeatInterval and presenceHeartbeat are set and a presence notifications are subsribed
func (*Pubnub) SetUserStateJSON ¶
func (pub *Pubnub) SetUserStateJSON(channel string, jsonString string, callbackChannel chan []byte, errorChannel chan []byte)
SetUserStateJSON is the struct Pubnub's instance method which creates and posts the User state request using JSON as input
It accepts the following parameters: channel: a single value of the pubnub channel. jsonString: the user state in JSON format. If invalid an error will be thrown callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) SetUserStateKeyVal ¶
func (pub *Pubnub) SetUserStateKeyVal(channel string, key string, val string, callbackChannel chan []byte, errorChannel chan []byte)
SetUserStateKeyVal is the struct Pubnub's instance method which creates and posts the userstate request using a key/val map
It accepts the following parameters: channel: a single value of the pubnub channel. key: user states key value: user stated value callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) Subscribe ¶
func (pub *Pubnub) Subscribe(channels string, timetoken string, callbackChannel chan []byte, isPresenceSubscribe bool, errorChannel chan []byte)
Subscribe is the struct Pubnub's instance method which checks for the InvalidChannels and returns if true. Initaiates the presence and subscribe response channels. It creates a map for callback and error response channels for each pubnub channel using the pubnub channel name as the key. If muliple channels are passed then the same callback or error channel is used.
If there is no existing subscribe/presence loop running then it starts a new loop with the new pubnub channels. Else closes the existing connections and starts a new loop
It accepts the following parameters: channels: comma separated pubnub channel list. timetoken: if timetoken is present the subscribe request is sent using this timetoken callbackChannel: Channel on which to send the response back. isPresenceSubscribe: tells the method that presence subscription is requested. errorChannel: channel to send an error response to.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) Unsubscribe ¶
func (pub *Pubnub) Unsubscribe(channels string, callbackChannel chan []byte, errorChannel chan []byte)
Unsubscribe is the struct Pubnub's instance method which unsubscribes a pubnub subscribe channel(s) from the subscribe loop.
If all the pubnub channels are not removed the method StartSubscribeLoop will take care of it by starting a new loop. Closes the channel c when the processing is complete
It accepts the following parameters: channels: the pubnub channel(s) in a comma separated string. callbackChannel: Channel on which to send the response back. errorChannel: channel to send an error response to.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
func (*Pubnub) WhereNow ¶
WhereNow is the struct Pubnub's instance method which creates and posts the wherenow request to get the connected users details.
It accepts the following parameters: uuid: devcie uuid to pass to the wherenow query callbackChannel on which to send the response. errorChannel on which the error response is sent.
Both callbackChannel and errorChannel are mandatory. If either is nil the code will panic
type PubnubUnitTest ¶
type PubnubUnitTest struct { }
PubnubUnitTest structure used to expose some data for unit tests.
func (*PubnubUnitTest) GetSentTimeToken ¶
func (pubtest *PubnubUnitTest) GetSentTimeToken(pub *Pubnub) string
GetSentTimeToken returns the timetoken sent to the server, is used only for unit tests
func (*PubnubUnitTest) GetTimeToken ¶
func (pubtest *PubnubUnitTest) GetTimeToken(pub *Pubnub) string
GetTimeToken returns the latest timetoken received from the server, is used only for unit tests