Skip to content

Commit

Permalink
Merge 94126a9 into a402180
Browse files Browse the repository at this point in the history
  • Loading branch information
shriramshankar committed Oct 21, 2016
2 parents a402180 + 94126a9 commit 7ba98ed
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function start() { // eslint-disable-line max-statements

const app = express();
const httpServer = require('http').Server(app);

const io = require('socket.io')(httpServer);
const socketIOSetup = require('./realtime/setupSocketIO');
socketIOSetup.setupNamespace(io);
Expand Down
1 change: 1 addition & 0 deletions view/loadView.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ module.exports = function loadView(app, passport) {
trackingId: viewConfig.trackingId,
user: req.user,
eventThrottle: viewConfig.realtimeEventThrottleMilliseconds,
transportProtocol: viewConfig.socketIOtransportProtocol,
};

const templateVars = Object.assign(
Expand Down
13 changes: 12 additions & 1 deletion view/perspective/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,22 @@ function handleEvent(eventData, eventTypeName) {
function setupSocketIOClient(persBody) {
const namespace = u.getNamespaceString(persBody);

/*
* if the transprotocol is set, initialize the socketio client with
* the transport protocol options. The transProtocol variable is set in
* perspective.pug
*/
const options = {};
const clientProtocol = transProtocol;
if (clientProtocol !== 'undefined') {
options.transports = clientProtocol.replace(/\s*,\s*/g, ',').split(',');
}

/*
* Note: The "io" variable is defined by the "/socket.io.js" script included
* in perspective.pug.
*/
const socket = io(namespace);
const socket = io(namespace, options);
socket.on(eventsQueue.eventType.INTRNL_SUBJ_ADD, (data) => {
handleEvent(data, eventsQueue.eventType.INTRNL_SUBJ_ADD);
});
Expand Down
3 changes: 3 additions & 0 deletions view/perspective/perspective.pug
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ html(lang = 'en')
script(src='/static/socket.io.js')
script.
var realtimeEventThrottleMilliseconds = #{eventThrottle};
script.
var transProtocol = '#{transportProtocol}';

script
if queryParams
| var queryParams = !{queryParams}
Expand Down
4 changes: 4 additions & 0 deletions viewConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ const DEFAULT_THROTTLE_MILLISECS = 4000;
const realtimeEventThrottleMilliseconds =
pe.realtimeEventThrottleMilliseconds || DEFAULT_THROTTLE_MILLISECS;

const socketIOtransportProtocol = pe.SOCKETIO_TRANSPORT_PROTOCOL || 'undefined';
module.exports = {
// Make the Google Analytics trackingId available in /view.
trackingId: pe.GOOGLE_ANALYTICS_ID || 'N/A',

// Make the throttle time available in /view.
realtimeEventThrottleMilliseconds,

// Expose the socketIOtransportProtocol variable in the /view
socketIOtransportProtocol,
};

0 comments on commit 7ba98ed

Please sign in to comment.