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

Commit dbc6545

Browse files
committed
Separate rtcController and quicController.
Conference sessions over QUIC used to be handled by accessController. But a recent change added rtcController, moved some logicals out of accessController. So we need to either have a quicController or extend rtcController or accessController. This change adds a quicController. However, it would be better to redesign the interface of *Controller, and create a single controller for each conference.
1 parent 7665f4d commit dbc6545

File tree

6 files changed

+338
-31
lines changed

6 files changed

+338
-31
lines changed

source/agent/conference/accessController.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var path = require('path');
88
var url = require('url');
99
var log = require('./logger').logger.getLogger('AccessController');
1010

11-
module.exports.create = function(spec, rpcReq, on_session_established, on_session_aborted, on_session_signaling, rtc_controller) {
11+
module.exports.create = function(spec, rpcReq, on_session_established, on_session_aborted, on_session_signaling, rtc_controller, quic_controller) {
1212
var that = {},
1313
cluster_name = spec.clusterName,
1414
self_rpc_id = spec.selfRpcId,
@@ -192,6 +192,9 @@ module.exports.create = function(spec, rpcReq, on_session_established, on_sessio
192192
if (sessionOptions.type === 'webrtc') {
193193
return rtc_controller.initiate(participantId, sessionId, direction, origin, sessionOptions, formatPreference);
194194
}
195+
if (sessionOptions.type === 'quic') {
196+
return quic_controller.initiate(participantId, sessionId, direction, origin, sessionOptions, formatPreference);
197+
}
195198
if (sessions[sessionId]) {
196199
return Promise.reject('Session exists');
197200
}
@@ -256,7 +259,9 @@ module.exports.create = function(spec, rpcReq, on_session_established, on_sessio
256259
that.terminate = function(sessionId, direction, reason) {
257260
log.debug('terminate, sessionId:', sessionId, 'direction:', direction);
258261
if (!sessions[sessionId]) {
259-
return rtc_controller.terminate(sessionId, direction, reason);
262+
rtc_controller.terminate(sessionId, direction, reason);
263+
quic_controller.terminate(sessionId, direction, reason);
264+
return;
260265
}
261266

262267
var session = sessions[sessionId];

source/agent/conference/conference.js

Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var AccessController = require('./accessController');
1111
var RoomController = require('./roomController');
1212
var dataAccess = require('./data_access');
1313
var Participant = require('./participant');
14+
const { QuicController } = require('./quicController');
1415

1516
// Logger
1617
var log = logger.getLogger('Conference');
@@ -101,6 +102,7 @@ var Conference = function (rpcClient, selfRpcId) {
101102
accessController;
102103

103104
var rtcController;
105+
let quicController;
104106

105107
/*
106108
* {
@@ -412,6 +414,25 @@ var Conference = function (rpcClient, selfRpcId) {
412414
onSessionAborted(data.owner, sessionId, data.direction, data.reason);
413415
});
414416

417+
quicController = new QuicController(room_id, rpcReq, selfRpcId, global.config.clusterName || 'owt-cluster');
418+
quicController.on('session-established', (sessionInfo) => {
419+
const sessionId = sessionInfo.id;
420+
const media = { tracks: sessionInfo.tracks };
421+
let direction = sessionInfo.direction;
422+
const transport = sessionInfo.transport;
423+
const conferenceSessionInfo = {
424+
locality: transport.locality,
425+
media: media,
426+
data: sessionInfo.data,
427+
info: { type: 'quic', owner: transport.owner }
428+
};
429+
onSessionEstablished(transport.owner, sessionId, direction, conferenceSessionInfo);
430+
});
431+
432+
quicController.on('session-aborted', (sessionId, data) => {
433+
onSessionAborted(data.owner, sessionId, data.direction, data.reason);
434+
});
435+
415436
accessController = AccessController.create({clusterName: global.config.cluster.name || 'owt-cluster',
416437
selfRpcId: selfRpcId,
417438
inRoom: room_id,
@@ -421,7 +442,8 @@ var Conference = function (rpcClient, selfRpcId) {
421442
onSessionEstablished,
422443
onSessionAborted,
423444
onLocalSessionSignaling,
424-
rtcController);
445+
rtcController,
446+
quicController);
425447
resolve('ok');
426448
},
427449
function onError(reason) {
@@ -463,9 +485,13 @@ var Conference = function (rpcClient, selfRpcId) {
463485
if (pid !== 'admin' && rtcController) {
464486
pl.push(rtcController.terminateByOwner(pid));
465487
}
488+
if (pid != 'admin' && quicController) {
489+
pl.push(quicController.terminateByOwner(pid));
490+
}
466491
}
467492
accessController && pl.push(accessController.participantLeave('admin'));
468493
rtcController && pl.push(rtcController.terminateByOwner('admin'));
494+
quicController && pl.push(quicController.terminateByOwner('admin'));
469495

470496
return Promise.all(pl)
471497
.then(() => {
@@ -918,14 +944,14 @@ var Conference = function (rpcClient, selfRpcId) {
918944
}
919945

920946
return accessController.participantLeave(participantId)
921-
.then(() => rtcController.terminateByOwner(participantId))
922-
.then(() => removeParticipant(participantId))
923-
.then((result) => {
947+
.then(() => {
948+
rtcController.terminateByOwner(participantId);
949+
quicController.terminateByOwner(participantId);
950+
})
951+
.then(() => removeParticipant(participantId))
952+
.then((result) => {
924953
callback('callback', 'ok');
925-
selfClean();
926-
}, (e) => {
927-
callback('callback', 'error', e.message ? e.message : e);
928-
});
954+
selfClean(); }, (e) => { callback('callback', 'error', e.message ? e.message : e); });
929955
};
930956

931957
that.onSessionSignaling = function(sessionId, signaling, callback) {
@@ -964,7 +990,7 @@ var Conference = function (rpcClient, selfRpcId) {
964990
type: subDesc.type,
965991
transport: subDesc.transport,
966992
transportId: subDesc.transport.id,
967-
tracks: subDesc.media.tracks,
993+
tracks: subDesc.media ? subDesc.media.tracks : undefined,
968994
data: subDesc.data,
969995
legacy: subDesc.legacy,
970996
};
@@ -1038,22 +1064,23 @@ var Conference = function (rpcClient, selfRpcId) {
10381064
var origin = participants[participantId].getOrigin();
10391065
var format_preference;
10401066
if (pubInfo.type === 'webrtc' || pubInfo.type === 'quic') {
1041-
const rtcPubInfo = translateRtcPubIfNeeded(pubInfo);
1042-
if (rtcPubInfo.tracks) {
1043-
// Set formatPreference
1044-
rtcPubInfo.tracks.forEach(track => {
1045-
track.formatPreference = { optional : room_config.mediaIn[track.type] };
1046-
});
1047-
}
1048-
initiateStream(streamId, {owner: participantId, type: pubInfo.type, origin});
1049-
return rtcController.initiate(participantId, streamId, 'in', participants[participantId].getOrigin(), rtcPubInfo)
1050-
.then((result) => {
1051-
callback('callback', result);
1052-
})
1053-
.catch((e) => {
1054-
removeStream(streamId);
1055-
callback('callback', 'error', e.message ? e.message : e);
1056-
});
1067+
const controller = pubInfo.type === 'webrtc' ? rtcController : quicController;
1068+
const rtcPubInfo = translateRtcPubIfNeeded(pubInfo);
1069+
if (rtcPubInfo.tracks) {
1070+
// Set formatPreference
1071+
rtcPubInfo.tracks.forEach(track => {
1072+
track.formatPreference = { optional : room_config.mediaIn[track.type] };
1073+
});
1074+
}
1075+
initiateStream(streamId, { owner : participantId, type : pubInfo.type, origin });
1076+
return controller.initiate(participantId, streamId, 'in', participants[participantId].getOrigin(), rtcPubInfo)
1077+
.then((result) => {
1078+
callback('callback', result);
1079+
})
1080+
.catch((e) => {
1081+
removeStream(streamId);
1082+
callback('callback', 'error', e.message ? e.message : e);
1083+
});
10571084
}
10581085

10591086
initiateStream(streamId, {owner: participantId, type: pubInfo.type, origin});
@@ -1241,7 +1268,7 @@ var Conference = function (rpcClient, selfRpcId) {
12411268
if (subDesc.type === 'webrtc') {
12421269
audioTrack = subDesc.media.tracks.find(t => t.type === 'audio');
12431270
videoTrack = subDesc.media.tracks.find(t => t.type === 'video');
1244-
} else {
1271+
} else if (subDesc.media) {
12451272
audioTrack = subDesc.media.audio;
12461273
videoTrack = subDesc.media.video;
12471274
}
@@ -1275,6 +1302,7 @@ var Conference = function (rpcClient, selfRpcId) {
12751302
} else {
12761303
var format_preference;
12771304
if (subDesc.type === 'webrtc' || subDesc.type === 'quic') {
1305+
const controller = subDesc.type === 'webrtc' ? rtcController : quicController;
12781306
const rtcSubInfo = translateRtcSubIfNeeded(subDesc);
12791307
if (rtcSubInfo.tracks){
12801308
// Set formatPreference
@@ -1294,14 +1322,14 @@ var Conference = function (rpcClient, selfRpcId) {
12941322
}
12951323

12961324
initiateSubscription(subscriptionId, subDesc, {owner: participantId, type: subDesc.type});
1297-
return rtcController.initiate(participantId, subscriptionId, 'out', participants[participantId].getOrigin(), rtcSubInfo)
1325+
return controller.initiate(participantId, subscriptionId, 'out', participants[participantId].getOrigin(), rtcSubInfo)
12981326
.then((result) => {
12991327
const releasedSource = rtcSubInfo.tracks ? rtcSubInfo.tracks.find(track => {
13001328
const sourceStreamId = trackOwners[track.from] || track.from;
13011329
return !streams[sourceStreamId];
13021330
}) : undefined;
13031331
if (releasedSource) {
1304-
rtcController.terminate(participantId, subscriptionId, 'Participant terminate');
1332+
controller.terminate(participantId, subscriptionId, 'Participant terminate');
13051333
return Promise.reject('Target audio/video stream early released');
13061334
}
13071335
callback('callback', result);
@@ -1766,7 +1794,7 @@ var Conference = function (rpcClient, selfRpcId) {
17661794
that.onSessionProgress = function(sessionId, direction, sessionStatus) {
17671795
log.debug('onSessionProgress, sessionId:', sessionId, 'direction:', direction, 'sessionStatus:', sessionStatus);
17681796
if (sessionStatus.data) {
1769-
rtcController.onSessionProgress(sessionId, sessionStatus);
1797+
quicController && quicController.onSessionProgress(sessionId, sessionStatus);
17701798
} else {
17711799
accessController && accessController.onSessionStatus(sessionId, sessionStatus);
17721800
}
@@ -2627,6 +2655,8 @@ var Conference = function (rpcClient, selfRpcId) {
26272655
dropParticipants(message.id);
26282656
} else if (message.purpose === 'webrtc') {
26292657
rtcController && rtcController.terminateByLocality(message.type, message.id);
2658+
} else if (message.purpose === 'quic') {
2659+
quicController && quicController.terminateByLocality(message.type, message.id);
26302660
} else if (message.purpose === 'recording' ||
26312661
message.purpose === 'streaming' ||
26322662
message.purpose === 'analytics') {

source/agent/conference/dist.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"conference.js",
1616
"accessController.js",
1717
"rtcController.js",
18+
"quicController.js",
1819
"stream.js",
1920
"subscription.js",
2021
"../index.js",

source/agent/conference/log4js_configuration.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"AccessController": "INFO",
2020
"RoomController": "INFO",
2121
"RtcController": "INFO",
22+
"QuicController": "INFO",
2223
"Stream": "INFO",
2324
"Subscription": "INFO",
2425
"WorkingAgent": "INFO",

0 commit comments

Comments
 (0)