diff --git a/client/bbb-html5-client/iotest.coffee b/client/bbb-html5-client/iotest.coffee index 9f7aa204291902620a6cab33b55cb8bd67f8f890..b3a45f7adbb6c4f722e488b7ad3c9b6917d11fa3 100755 --- a/client/bbb-html5-client/iotest.coffee +++ b/client/bbb-html5-client/iotest.coffee @@ -1,9 +1,9 @@ postal = require('postal') -{SocketIoMessageHandler} = require './lib/clientproxy' +proxy = require './lib/clientproxy' crypto = require 'crypto' -io = require('socket.io').listen(3019) -sio = new SocketIoMessageHandler(io) +proxy.listen(3019) + diff --git a/client/bbb-html5-client/lib/clientproxy.coffee b/client/bbb-html5-client/lib/clientproxy.coffee index e00f8d8cfd750827ebdd8ac654a6aff4a4929457..8a1f7a3b6c0c8273a7eba596dba3f7eeb0bb6f67 100755 --- a/client/bbb-html5-client/lib/clientproxy.coffee +++ b/client/bbb-html5-client/lib/clientproxy.coffee @@ -1,42 +1,39 @@ -{Controller} = require './controller' +socketio = require('socket.io') + +controller = require './controller' log = require './bbblogger' MESSAGE = "message" -class SocketIoMessageHandler - constructor: (io) -> - @io = io - @controller = new Controller(@) - @initialize() - - initialize: () -> - @io.sockets.on('connection', (socket) -> - console.log("Client has connected.") - log.debug("LOG: Client has connected.") - socket.on('message', (jsonMsg) -> - log.debug("Received message #{jsonMsg}") - handleMessage(socket, @controller, jsonMsg) - ) - socket.on('disconnect', () -> - handleClientDisconnected socket - ) - ) +io = null -exports.SocketIoMessageHandler = SocketIoMessageHandler +exports.listen = (app) -> + io = socketio.listen(app) + io.sockets.on('connection', (socket) -> + console.log("Client has connected.") + log.debug("LOG: Client has connected.") + socket.on('message', (jsonMsg) -> + log.debug("Received message #{jsonMsg}") + handleMessage(socket, jsonMsg) + ) + socket.on('disconnect', () -> + handleClientDisconnected socket + ) + ) handleClientDisconnected = (socket) -> log.debug("LOG: Client has disconnected.") -handleMessage = (socket, controller, message) -> +handleMessage = (socket, message) -> if message.name? - handleValidMessage(socket, controller, message) + handleValidMessage(socket, message) else log.error({error: "Invalid message", message: JSON.stringify(message)}) -handleValidMessage = (socket, controller, message) -> +handleValidMessage = (socket, message) -> switch message.name when 'authenticateMessage' - handleLoginMessage socket, controller, message + handleLoginMessage socket, message when 'Sandra' connectJackNumber 22 when 'Toby' @@ -44,15 +41,15 @@ handleValidMessage = (socket, controller, message) -> else console.log('I am sorry, your call cannot be connected') -handleLoginMessage = (socket, controller, data) -> +handleLoginMessage = (socket, data) -> controller.processLoginMessage(data, (err, result) -> if (err) message = {name: "authenticationReply", error: err} - sendMessageToClient message + sendMessageToClient socket, message else message = {name: "authenticationReply", data: result} - sendMessageToClient message - ) + sendMessageToClient socket, message + ) sendMessageToClient = (socket, message) -> socket.emit(MESSAGE, JSON.stringify(message)) @@ -61,3 +58,9 @@ sendMessageToClient = (socket, message) -> + + + + + + diff --git a/client/bbb-html5-client/lib/controller.coffee b/client/bbb-html5-client/lib/controller.coffee index c1339b98b5ede9deede3fc227565d663e5768805..02daf3b6684202a1b45a8ba58edf124cfea59019 100755 --- a/client/bbb-html5-client/lib/controller.coffee +++ b/client/bbb-html5-client/lib/controller.coffee @@ -1,22 +1,16 @@ bus = require './messagebus' -logger = require './bbblogger' +log = require './bbblogger' -class Controller - constructor: (clientProxy) -> - @proxy = clientProxy - - processLoginMessage = (data, callback) -> - bus.sendMessage(data, (err, result) -> - if (err) - errLog = {message: "Authentication Failure", reason: err, data: data} - log.error(JSON.stringify(errLog)) - callback(err, null) +exports.processLoginMessage = (data, callback) -> + bus.sendMessage(data, (err, result) -> + if (err) + errLog = {message: "Authentication Failure", reason: err, data: data} + log.error(JSON.stringify(errLog)) + callback(err, null) + else + console.log("SUCCESS: #{result}") + if result.error? + callback(result.error, null) else - console.log("SUCCESS: #{result}") - if result.error? - callback(result.error, null) - else - callback(null, result.data) - ) - -exports.Controller = Controller \ No newline at end of file + callback(null, result.data) + ) diff --git a/client/bbb-html5-client/lib/messagebus.coffee b/client/bbb-html5-client/lib/messagebus.coffee index be8662456ba585a340514cc8a0a7f30ce3fd9f54..6ed23a237a6e515366a09fdc771149458fc3b844 100755 --- a/client/bbb-html5-client/lib/messagebus.coffee +++ b/client/bbb-html5-client/lib/messagebus.coffee @@ -2,34 +2,16 @@ postal = require('postal') redisrpc = require './redispubsub' crypto = require 'crypto' -io = require('socket.io').listen(3009) - -io.sockets.on('connection', (socket) -> - console.log("Connected") - socket.on('login', (data) -> - console.log("User login #{data}") - sendMessage(data, (err, result) -> - if (err) - console.log("ERROR: #{err}") - else - console.log("SUCCESS: #{result}") - socket.emit('authenticated', JSON.stringify(result)) - ) - ) - - socket.on('event', (data) -> - console.log("Server received event.") - ) - - socket.on('disconnect', () -> - console.log("Server disconnect event.") - ) - - socket.emit('ready') -) +receiveMessage = (callback) -> + postal.subscribe({ + channel: replyTo.channel, + topic: replyTo.topic, + callback: (msg, envelope) -> + callback( msg.err, msg.data ) + }) -sendMessage = (data, callback) -> +exports.sendMessage = (data, callback) -> replyTo = { channel: 'model.data', topic: 'get.' + crypto.randomBytes(16).toString('hex')