Skip to content

Commit

Permalink
Merge branch 'master' into subject-filter-by-tag
Browse files Browse the repository at this point in the history
  • Loading branch information
pallavi2209 committed Oct 24, 2016
2 parents 8d6489b + eb5ae26 commit 2af7b2a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 28 additions & 1 deletion view/perspectiveBeta/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const ONE = 1;

const DEBUG_REALTIME = window.location.href.split(/[&\?]/)
.includes('debug=REALTIME');
const WEBSOCKET_ONLY = window.location.href.split(/[&\?]/)
.includes('protocol=websocket');

const REQ_HEADERS = {
Authorization: u.getCookie('Authorization'),
Expand Down Expand Up @@ -131,11 +133,36 @@ 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) {
/*
* options is used here to set the transport type. For example to only use
* websockets as the transport protocol the options object will be
* { transports: ['websocket'] }. The regex is used to trim the white spaces
* and since clientProtocol is a string of comma seperated values,
* the split function is used to split them out by comma and convert
* it to an array.
*/
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);
let socket;
if (WEBSOCKET_ONLY) {
socket = io(namespace, { transports: ['websocket'] });
} else {
socket = io(namespace, options);
}

socket.on(eventsQueue.eventType.INTRNL_SUBJ_ADD, (data) => {
handleEvent(data, eventsQueue.eventType.INTRNL_SUBJ_ADD);
});
Expand Down
2 changes: 2 additions & 0 deletions view/perspectiveBeta/perspective.pug
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ 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

0 comments on commit 2af7b2a

Please sign in to comment.