diff --git a/src/lib/common/api.js b/src/lib/common/api.js index 441acff..b2bfef3 100644 --- a/src/lib/common/api.js +++ b/src/lib/common/api.js @@ -284,17 +284,17 @@ api.getJSON = function (options, objOptions, callback) { objOptions._path = options.path; - joola.io.socket.emit(routeID, objOptions); + joola.io.emit(routeID, objOptions); joola.events.emit('rpc:start', 1); joola.events.emit('bandwidth', lengthInUtf8Bytes(JSON.stringify(objOptions))); var shouldOn = objOptions && (objOptions.realtime || (objOptions.options && Array.isArray(objOptions.options) && objOptions.options.length > 0 && objOptions.options[0].realtime)); if (objOptions && objOptions.options && objOptions.options.realtime) shouldOn = true; if (shouldOn) { - joola.io.socket.on(routeID + ':done', processResponse); + joola.io.on(routeID + ':done', processResponse); } else { - joola.io.socket.once(routeID + ':done', processResponse); + joola.io.once(routeID + ':done', processResponse); } } }; diff --git a/src/lib/index.js b/src/lib/index.js index 95055a3..7e767e7 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -172,31 +172,32 @@ joola.init = function (options, callback) { throw new Error('joola host not specified'); var io = require('socket.io-client'); - joola.io = io; - joola.io.socket = joola.io.connect(joola.options.host); - joola.io.socket.on('event', function (data) { + joola.io = io.connect(joola.options.host, {'force new connection': true }); + joola.io.on('error', function (reason) { + joola.connected = false; + joola.emit('disconnected', reason); }); - joola.io.socket.on('disconnect', function (reason) { + joola.io.on('disconnect', function (reason) { joola.connected = false; joola.emit('disconnected', reason); }); - joola.io.socket.on('connect_error', function (err) { + joola.io.on('connect_error', function (err) { joola.connected = false; if (!joola.online) throw new Error('Failed to connect to Joola engine: ' + err); joola.emit('disconnected', err); }); - joola.io.socket.on('connect_timeout', function (err) { + joola.io.on('connect_timeout', function (err) { joola.connected = false; if (!joola.online) throw new Error('Failed to connect to Joola engine: Timeout'); joola.emit('disconnected', 'timeout'); }); - joola.io.socket.on('connect', function () { + joola.io.on('connect', function () { joola.connected = true; if (!joola.online) { joola.online = true; - joola.bringOnline(callback); + joola.bringOnline(callback); } joola.emit('connected'); });