Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
requirejs = require 'requirejs'
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
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'
if status[1] is 'STREAM-SENSING'
@emit "streamSensing"
else @emit 'connected'
when 'DISCONNECTED' then @emit 'disconnected'
# Connect to Lightstreamer
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