-
Notifications
You must be signed in to change notification settings - Fork 48
/
socketIOEmitter.js
38 lines (31 loc) · 1.15 KB
/
socketIOEmitter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Copyright (c) 2016, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or
* https://opensource.org/licenses/BSD-3-Clause
*/
/**
* ./realtime/socketIOEmitter.js
*/
'use strict'; // eslint-disable-line strict
const rtUtils = require('./utils');
const initEvent = 'refocus.internal.realtime.perspective.namespace.initialize';
const featureToggles = require('feature-toggles');
module.exports = (io, key, mssgObj) => {
const obj = rtUtils.parseObject(mssgObj[key], key);
const newObjectAsString = rtUtils.getNewObjAsString(key, obj);
// Initialize namespace when perspective initialize namespace event is sent
if (key.startsWith(initEvent)) {
rtUtils.initializeNamespace(obj, io);
}
for (const nsp in io.nsps) {
if (nsp && rtUtils.shouldIEmitThisObj(nsp, obj)) {
// newObjectAsString contains { key: {new: obj }}
io.of(nsp).emit(key, newObjectAsString);
if (featureToggles.isFeatureEnabled('instrumentRealtimeEvents')) {
console.log(`[RT] namespace=${nsp} bytes=${newObjectAsString.length}`);
}
}
}
};