webgme-engine
Version:
WebGME server and Client API without a GUI
42 lines (31 loc) • 1.24 kB
JavaScript
/*globals define*/
/*eslint-env node*/
/**
* //TODO: Consider moving this to src/server/..
* Socket io client used on the server. Typical use-case is from the users.
* @author pmeijer / https://github.com/pmeijer
*/
define(['socket.io-client'], function (io) {
'use strict';
function IoClient(hostUrl, webgmeToken, mainLogger, gmeConfig) {
var logger = mainLogger.fork('socketio-nodeclient');
this.connect = function (callback) {
var socketIoOptions = JSON.parse(JSON.stringify(gmeConfig.socketIO.clientOptions));
logger.debug('Connecting to "' + hostUrl + '" with options', {metadata: socketIoOptions});
if (webgmeToken) {
socketIoOptions.extraHeaders = {
Cookie: gmeConfig.authentication.jwt.cookieId + '=' + webgmeToken
};
logger.debug('webgmeToken was defined adding it as an extra header in the cookie..');
}
callback(null, io(hostUrl, socketIoOptions));
};
this.getToken = function () {
return webgmeToken;
};
this.setToken = function (newToken) {
webgmeToken = newToken;
};
}
return IoClient;
});