CRSocket

This class extends CRStateMachine

It facilitates bidirectional communication between controller and responder clients

Contstructor

CRSocket(config, clientRole)
Parameters
config
CRConfig object, required
Configuration parameters and methods
clientRole
String, required
The role of the client ("controller" or "responder")

Properties

See also CRStateMachine properties

clientId
String, readOnly
The current clientId, used to identify the current client process. Automatically generated and maintained.
accessToken
String, read/write, default = ""
The current accessToken, used to identify the current user and determine access rights.
partnerClientId
String, read/write, default = ""
The clientId of the current partnerClient
active
Boolean, readOnly
True when the client is active (visible, online, not paused, and not unloading) and has been assigned a clientId. Corresponds to the active meta state.
connected
Boolean, readOnly
True if the socket is active and connected to an eventSource. Corresponds to the connected meta state.
paired
Boolean, readOnly
True if the socket is connected, has been assigned a partnerClientId and has not been rejected by this partner. Corresponds to the paired meta state.
readyToSend
Boolean, readOnly
True if the socket is able to send events to a partner client, even though it may not be able to receive events. (If the browser engine is offline, event requests will be buffered.)

Methods

See also CRStateMachine methods

init()
Initiates dynamic variables and activates the object
sendEvent(eventType, eventSubType = "", eventParams = [], buffered = false, logged = false, interceptable = true)
Generates and sends a CREvent object if the socket is readyToSend
See CREventSender.genCrEvent for details.
localStorageSet(key, value)
Saves a value in localSorage, with key prepended by the current appId and clientRole (appId_clientRole_key).
Parameters
key
String, required
value
String, required
localStorageGet(key) → String
Retrieves a value from localSorage, with key prepended by the current appId and clientRole (appId_clientRole_key).
Parameters
key
String, required
localStorageRemove(key)
Removes a value from localSorage, with key prepended by the current appId and clientRole (appId_clientRole_key).
Parameters
key
String, required

Events

See also CRStateMachine events.

clientIdChanged
Delivers a MessageEvent object containing the new clientId.
accessTokenChanged
Delivers a MessageEvent object containing the new accessToken.
partnerClientIdChanged
Delivers a MessageEvent object containing the new partnerClientId.
eventReceived
Delivers a CREvent object received by the socket.

States

See also the States section in the Protocol page.

passive
The client is not active
readyToConnect
The client is active, but the socket has not connected to an eventSource, either because it has not been assigned an accessToken, or because a previous connection attempt has been aborted by the server.
connecting
The socket is active, has been assigned an accessToken and is trying to connect to an eventSource.
readyToPair
The socket is connected, but cannot reach out to a partner client, either because it has not been assigned a partnerClientId, or because a previous pairing attempt has been rejected by the partner.
searching
The socket is paired, but has not received any events from the partner within the last partnerActiveMaxEventInDt millisecs.
interacting
The socket is paired and has received at least one event from the partner within the last partnerActiveMaxEventInDt millisecs.