Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 7d8e854

Browse files
authored
Reduce messages when lots of participants join at same time (#877)
* Reduce messages when lots of participants join at same time
1 parent e5c68db commit 7d8e854

File tree

6 files changed

+58
-11
lines changed

6 files changed

+58
-11
lines changed

source/agent/conference/conference.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,16 +528,18 @@ var Conference = function (rpcClient, selfRpcId) {
528528

529529
const sendMsg = function(from, to, msg, data) {
530530
log.debug('sendMsg, from:', from, 'to:', to, 'msg:', msg, 'data:', data);
531-
if (to === 'all') {
532-
for (var participant_id in participants) {
533-
sendMsgTo(participant_id, msg, data);
531+
if (to === 'all' || to === 'others') {
532+
// Broadcast message to portal
533+
let excludes = (to === 'others') ? [from] : [];
534+
let portals = new Set();
535+
for (let pptId in participants) {
536+
portals.add(participants[pptId].getPortal());
534537
}
535-
} else if (to === 'others') {
536-
for (var participant_id in participants) {
537-
if (participant_id !== from) {
538-
sendMsgTo(participant_id, msg, data);
538+
portals.forEach((portal) => {
539+
if (portal) {
540+
rpcReq.broadcast(portal, selfRpcId, excludes, msg, data);
539541
}
540-
}
542+
});
541543
} else {
542544
sendMsgTo(to, msg, data);
543545
}

source/agent/conference/rpcRequest.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ var RpcRequest = function(rpcChannel) {
6666
return rpcChannel.makeRPC(portal, 'notify', [participantId, event, data]);
6767
};
6868

69+
that.broadcast = function(portal, controller, excludeList, event, data) {
70+
return rpcChannel.makeRPC(portal, 'broadcast', [controller, excludeList, event, data]);
71+
};
72+
6973
that.dropUser = function(portal, participantId) {
7074
return rpcChannel.makeRPC(portal, 'drop', [participantId]);
7175
};

source/agent/conference/test/rpcRequest_test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('rpcRequest.terminate', function() {
134134
});
135135
});
136136

137-
describe('rpcRequest.getRoomConfig/onSessionSignaling/mediaOnOff/sendMsg/dropUser', function() {
137+
describe('rpcRequest.getRoomConfig/onSessionSignaling/mediaOnOff/sendMsg/broadcast/dropUser', function() {
138138
it('Should succeed if rpcChannel.makeRPC succeeds.', function() {
139139
var mockRpcChannel = sinon.createStubInstance(rpcChannel);
140140
mockRpcChannel.makeRPC = sinon.stub();
@@ -145,6 +145,7 @@ describe('rpcRequest.getRoomConfig/onSessionSignaling/mediaOnOff/sendMsg/dropUse
145145
var mediaOnOff = req.mediaOnOff('rpcIdOfWorkerNode', 'sessionId', 'video', 'in', 'off');
146146
var onSessionSignaling = req.onSessionSignaling('rpcIdOfWorkerNode', 'sessionId', 'soacObj');
147147
var sendMsg = req.sendMsg('rpcIdOfPortal', 'participantId', 'event-name', 'msgObj');
148+
var broadcast = req.broadcast('rpcIdOfPortal', 'controller', ['participantId'], 'event-name', 'msgObj');
148149
var dropUser = req.dropUser('rpcIdOfPortal', 'participantId');
149150

150151

@@ -153,10 +154,11 @@ describe('rpcRequest.getRoomConfig/onSessionSignaling/mediaOnOff/sendMsg/dropUse
153154
expect(mediaOnOff).to.become('ok-or-data'),
154155
expect(onSessionSignaling).to.become('ok-or-data'),
155156
expect(sendMsg).to.become('ok-or-data'),
157+
expect(broadcast).to.become('ok-or-data'),
156158
expect(dropUser).to.become('ok-or-data')
157159
])
158160
.then(function() {
159-
expect(mockRpcChannel.makeRPC.callCount).to.equal(5);
161+
expect(mockRpcChannel.makeRPC.callCount).to.equal(6);
160162
});
161163
});
162164

@@ -170,17 +172,19 @@ describe('rpcRequest.getRoomConfig/onSessionSignaling/mediaOnOff/sendMsg/dropUse
170172
var mediaOnOff = req.mediaOnOff('rpcIdOfWorkerNode', 'sessionId', 'video', 'in', 'off');
171173
var onSessionSignaling = req.onSessionSignaling('rpcIdOfWorkerNode', 'sessionId', 'soacObj');
172174
var sendMsg = req.sendMsg('rpcIdOfPortal', 'participantId', 'event-name', 'msgObj');
175+
var broadcast = req.broadcast('rpcIdOfPortal', 'controller', ['participantId'], 'event-name', 'msgObj');
173176
var dropUser = req.dropUser('rpcIdOfPortal', 'participantId');
174177

175178
return Promise.all([
176179
expect(getRoomConfig).to.be.rejectedWith('timeout-or-error'),
177180
expect(mediaOnOff).to.be.rejectedWith('timeout-or-error'),
178181
expect(onSessionSignaling).to.be.rejectedWith('timeout-or-error'),
179182
expect(sendMsg).to.be.rejectedWith('timeout-or-error'),
183+
expect(broadcast).to.be.rejectedWith('timeout-or-error'),
180184
expect(dropUser).to.be.rejectedWith('timeout-or-error')
181185
])
182186
.then(function() {
183-
expect(mockRpcChannel.makeRPC.callCount).to.equal(5);
187+
expect(mockRpcChannel.makeRPC.callCount).to.equal(6);
184188
});
185189
});
186190
});

source/portal/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ var rpcPublic = {
241241
} else {
242242
callback('callback', 'error', 'Invalid token for WebTransport.');
243243
}
244+
},
245+
broadcast: function(controller, excludeList, event, data, callback) {
246+
socketio_server && socketio_server.broadcast(controller, excludeList, event, data);
247+
callback('callback', 'ok');
244248
}
245249
};
246250

source/portal/socketIOServer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,18 @@ var SocketIOServer = function(spec, portal, observer) {
455455
}
456456
};
457457

458+
that.broadcast = function(controller, excludeList, event, data) {
459+
log.debug('broadcast controller:', controller, 'exclude:', excludeList, 'event:', event, 'data:', data);
460+
portal.getParticipantsByController('node', controller)
461+
.then(function (receivers) {
462+
for (let clientId of receivers) {
463+
if (!excludeList.includes(clientId)) {
464+
clients[clientId].notify(event, data);
465+
}
466+
}
467+
});
468+
}
469+
458470
that.drop = function(participantId) {
459471
if (participantId === 'all') {
460472
for(var pid in clients) {

source/portal/test/socketIOServer_v10Client_test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,27 @@ describe('Notifying events to clients.', function() {
744744
});
745745
});
746746
});
747+
748+
it('Broadcasting the joined clients should succeed.', function(done) {
749+
var client = sioClient.connect(serverUrl, {reconnect: false, secure: false, 'force new connection': true});
750+
751+
client.on('broadcast-event', function(data) {
752+
expect(data).to.equal('broadcast-data');
753+
done();
754+
});
755+
756+
client.on('connect', function() {
757+
mockPortal.join = sinon.stub();
758+
mockPortal.join.resolves(JSON.parse(JSON.stringify(presenter_join_result)));
759+
760+
client.emit('login', jsLoginInfo, function(status, resp) {
761+
mockPortal.join = null;
762+
expect(status).to.equal('ok');
763+
server.broadcast(['excludeClient'], 'broadcast-event', 'broadcast-data');
764+
});
765+
});
766+
});
767+
747768
});
748769

749770
describe('Drop users from sessions.', function() {

0 commit comments

Comments
 (0)