R.Uplink Class
The Uplink micro-protocol is a simple set of conventions to implement real-time reactive Flux over the wire.
The frontend and the backend server share 2 means of communications :
- a WebSocket-like (socket.io wrapper) duplex connection to handshake and subscribe to keys/listen to events
- regulars HTTP requests (front -> back) to actually get data from the stores
PROTOCOL:
Connection/reconnection:
Client: bind socket
Server: Acknowledge connection
Client: send "handshake" { guid: guid }
Server: send "handshake-ack" { recovered: bool } (recover previous session if existing based upon guid; recovered is true iff previous session existed)
Stores:
Client: send "subscribeTo" { key: key }
Server: send "update" { key: key }
Client: XHR GET /uplink/key
Events:
Client: send "listenTo" { eventName: eventName }
Server: send "event" { eventName: eventName, params: params }
Actions:
Client: XHR POST /uplink/action { params: params }
Other notifications:
Server: send "debug": { debug: debug } Debug-level message
Server: send "log" { log: log } Log-level message
Server: send "warn": { warn: warn } Warn-level message
Server: send "err": { err: err } Error-level message
Item Index
Methods
- _destroyInClient
- _destroyInClient
- _getFullUrl
- _handleDebug
- _handleDisconnect
- _handleDisconnect
- _handleError
- _handleEvent
- _handleHandshakeAck
- _handleLog
- _handleUnload
- _handleUpdate
- _handleWarn
- _initInClient
- _initInServer
- _listenTo
- _performUpdateIfNecessary
- _shouldFetchKey
- _subscribeTo
- _subscribeTo
- _unlistenFrom
- destroy
- dispatch
- fetch
- listenTo
- subscribeTo
- subscribeTo
- unlistenFrom
- Uplink
Methods
_destroyInClient
()
private
Does nothing
Returns:
void0
_destroyInClient
()
private
Simply closes the socket
_getFullUrl
-
suffix
-
listener
Parameters:
-
suffix
String -
listener
Object
_handleDebug
-
params
Parameters:
-
params
Object
_handleDisconnect
-
params
Parameters:
-
params
String
_handleDisconnect
()
private
Occurs after a connection. When a connection is established, the client sends a signal "handshake".
_handleError
-
params
Parameters:
-
params
Object
_handleEvent
-
params
Parameters:
-
params
String
_handleHandshakeAck
-
params
Identifies if the pid of the server has changed (due to a potential reboot server-side) since the last client connection.
If this is the case, a page reload is performed
Parameters:
-
params
Object
_handleLog
-
params
Parameters:
-
params
Object
_handleUnload
-
prevHandler
Occurs when a client unloads the document
Parameters:
-
prevHandler
FunctionThe function to execute when the page will be unloaded
Returns:
function
_handleUpdate
-
params
Triggered when a data is updated according to the specific key
Call corresponding function key
Parameters:
-
params
ObjectThe specific key
_handleWarn
-
params
Parameters:
-
params
Object
_initInClient
()
private
Creating io connection client-side in order to use sockets
_initInServer
()
private
Server-side
_listenTo
-
eventName
Sends the listener signal "listenTo"
Parameters:
-
eventName
StringThe eventName to listen
_performUpdateIfNecessary
-
key
-
entry
Determines if the the data must be fetched
Parameters:
-
key
String -
entry
Object
Returns:
fn The Function to call
_shouldFetchKey
-
key
-
entry
Parameters:
-
key
String -
entry
Object
Returns:
bool The boolean
_subscribeTo
()
String
private
Notifies the uplink-server that a subscription is required by client
Returns:
key The key to subscribe
_subscribeTo
()
String
private
Notifies the uplink-server that a subscription is over
Returns:
key The key to unsubscribe
_unlistenFrom
-
eventName
Sends the unlistener signal "unlistenFrom"
Parameters:
-
eventName
StringThe eventName to listen
destroy
()
Destroy socket client-side
dispatch
-
action
-
params
Dispatches an action by POST request from the uplink-server
Parameters:
-
action
ObjectThe specific action to dispatch
-
params
Object
Returns:
object Fetched data according to the specified action
fetch
-
key
Fetch data by GET request from the uplink-server
Parameters:
-
key
StringThe key to fetch
Returns:
object Fetched data according to the key
listenTo
-
eventName
-
fn
Create a listener according to a specific name
Parameters:
-
eventName
StringThe eventName to listen
-
fn
FunctionThe function to execute when triggered
Returns:
listener The created listener
subscribeTo
-
key
-
subscription
Removes a subscription to a key
Parameters:
-
key
StringThe key to subscribe
-
subscription
Object
subscribeTo
-
key
-
fn
Etablishes a subscription to a key, and call the specified function when _handleUpdate occurs
Parameters:
-
key
StringThe key to subscribe
-
fn
FunctionThe function to execute
Returns:
subscription The created subscription
unlistenFrom
-
eventName
-
listener
Remove a listener
Parameters:
-
eventName
StringThe eventName to remove
-
listener
Object
Uplink
-
httpEndpoint
-
socketEndpoint
-
guid
-
shouldReloadOnServerRestart
Initializes the uplink according to the specifications provided
Parameters:
-
httpEndpoint
Object -
socketEndpoint
Object -
guid
Object -
shouldReloadOnServerRestart
Object