-
-
Save minibikini/2b9a8852ff893cca33fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requirejs = require 'requirejs' | |
requirejs.config | |
deps: __dirname + '/../vendor/lightstreamer_node.js' | |
nodeRequire: require | |
LightstreamerClient = requirejs "LightstreamerClient" | |
Subscription = requirejs "Subscription" | |
SimpleLoggerProvider = requirejs 'SimpleLoggerProvider' | |
ConsoleAppender = requirejs 'ConsoleAppender' | |
loggerProvider = new SimpleLoggerProvider | |
loggerProvider.addLoggerAppender new ConsoleAppender "DEBUG" | |
LightstreamerClient.setLoggerProvider loggerProvider | |
class Client | |
connect: (cb) -> | |
unless @account or @account.lightstreamerEndpoint? or @cst? or @securityToken? or @account.clientId? | |
return cb new Error "Not logged in" | |
@once 'connected', cb | |
# Instantiate Lightstreamer client instance | |
@ls = new LightstreamerClient @account.lightstreamerEndpoint, 'InVisionProvider' | |
# console.log @account.clientId, "CST-#{@cst}|XST-#{@securityToken}" | |
# Set up login credentials: client | |
@ls.connectionDetails.setUser @account.clientId | |
@ls.connectionDetails.setPassword "CST-#{@cst}|XST-#{@securityToken}" | |
# Add connection event listener callback functions | |
# Note: the Lightstreamer library will transparently attempt to reconnect a number of times | |
# in the event of communicationss errors | |
@ls.addListener | |
onListenEnd: => console.log('ListenEnd') | |
# onListenStart: => @emit 'connected' | |
onPropertyChange: => (data) => console.log 'PropertyChange', data | |
onServerError: (code, msg) => @emit 'error', code: code, message: msg | |
onShareAbort: => console.log('ShareAbort') | |
onStatusChange: (chngStatus) => | |
console.log 'onStatusChange', chngStatus | |
status = chngStatus.split ':' | |
switch status[0] | |
when 'CONNECTING' then @emit 'connecting' | |
when 'CONNECTED' | |
if status[1] is 'STREAM-SENSING' | |
@emit "streamSensing" | |
else @emit 'connected' | |
when 'DISCONNECTED' then @emit 'disconnected' | |
# Connect to Lightstreamer | |
try | |
@ls.connect() | |
catch error | |
console.error 'connection error', error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment