vani-meeting-server 1.1.6 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/models/WebSocketServerStartRequest.js +1 -1
- package/lib/sfu/SFUEachRoomHandler.d.ts +5 -0
- package/lib/sfu/SFUEachRoomHandler.js +103 -1
- package/lib/sfu/SFUEachRoomUserHandler.js +3 -2
- package/lib/utility/Constant.d.ts +14 -1
- package/lib/utility/Constant.js +17 -3
- package/lib/websocket/EachSocketConnectionHandler.d.ts +1 -0
- package/lib/websocket/EachSocketConnectionHandler.js +1 -0
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WebSocketServerStartRequest = void 0;
|
|
4
4
|
class WebSocketServerStartRequest {
|
|
5
5
|
port = 4010;
|
|
6
|
-
redisUrl = "redis://127.0.0.1:
|
|
6
|
+
redisUrl = "redis://127.0.0.1:6379";
|
|
7
7
|
redisDBIndex = 5;
|
|
8
8
|
redisRoomDestoryTimeOutInSec = 1800;
|
|
9
9
|
rtcMinPort = 40000;
|
|
@@ -27,6 +27,7 @@ export interface SFUEachRoomHandlerInterface {
|
|
|
27
27
|
getAllRecvRouterForRoom(): Router[];
|
|
28
28
|
getSendRouterForRoom(): Router;
|
|
29
29
|
addAudioObserverForProducer(audioProducer: Producer): void;
|
|
30
|
+
onNewProducer(producer: Producer, participant: Participant): void;
|
|
30
31
|
pipeToRoute(producer: Producer): Promise<void>;
|
|
31
32
|
}
|
|
32
33
|
export declare class SFUEachRoomHandler extends BaseSFUWebsocket implements SFUEachRoomHandlerInterface {
|
|
@@ -34,6 +35,8 @@ export declare class SFUEachRoomHandler extends BaseSFUWebsocket implements SFUE
|
|
|
34
35
|
private sendRouter?;
|
|
35
36
|
private roomId;
|
|
36
37
|
roomPaticipants: Map<string, SFUEachRoomUserHandler>;
|
|
38
|
+
private plainTransportForAudio?;
|
|
39
|
+
private plainTransportForVideo?;
|
|
37
40
|
private workers?;
|
|
38
41
|
private sendWorkerIndex;
|
|
39
42
|
private audioObserver?;
|
|
@@ -50,7 +53,9 @@ export declare class SFUEachRoomHandler extends BaseSFUWebsocket implements SFUE
|
|
|
50
53
|
getAllRecvRouterForRoom(): Router[];
|
|
51
54
|
getSendRouterForRoom(): Router;
|
|
52
55
|
pipeToRoute(producer: Producer): Promise<void>;
|
|
56
|
+
onNewProducer(producer: Producer, participant: Participant): Promise<void>;
|
|
53
57
|
addAudioObserverForProducer(audioProducer: Producer): Promise<void>;
|
|
54
58
|
onUserLeft(participant: Participant): void;
|
|
59
|
+
private startBroadcasting;
|
|
55
60
|
cleanUp(): void;
|
|
56
61
|
}
|
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.SFUEachRoomHandler = void 0;
|
|
4
27
|
const BaseSFUWebsocket_1 = require("../base/BaseSFUWebsocket");
|
|
5
28
|
const RedisHandler_1 = require("../lib/redis/RedisHandler");
|
|
6
29
|
const Event_1 = require("../models/Event");
|
|
7
|
-
const Constant_1 = require("../utility/Constant");
|
|
30
|
+
const Constant_1 = __importStar(require("../utility/Constant"));
|
|
8
31
|
const EventEmitterHandler_1 = require("../utility/EventEmitterHandler");
|
|
9
32
|
const EachSocketConnectionHandler_1 = require("../websocket/EachSocketConnectionHandler");
|
|
10
33
|
const SFUEachRoomUserHandler_1 = require("./SFUEachRoomUserHandler");
|
|
@@ -13,6 +36,8 @@ class SFUEachRoomHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
13
36
|
sendRouter;
|
|
14
37
|
roomId;
|
|
15
38
|
roomPaticipants = new Map();
|
|
39
|
+
plainTransportForAudio;
|
|
40
|
+
plainTransportForVideo;
|
|
16
41
|
workers;
|
|
17
42
|
sendWorkerIndex = -1;
|
|
18
43
|
audioObserver;
|
|
@@ -22,12 +47,16 @@ class SFUEachRoomHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
22
47
|
this.workers = workers;
|
|
23
48
|
this.sendWorkerIndex = sendWorkerIndex;
|
|
24
49
|
this.cleanUp = this.cleanUp.bind(this);
|
|
50
|
+
this.startBroadcasting = this.startBroadcasting.bind(this);
|
|
25
51
|
}
|
|
26
52
|
onNewMessage(payload, participant) {
|
|
27
53
|
// console.log(payload)
|
|
28
54
|
if (payload.type === EachSocketConnectionHandler_1.SFUMessageType.GetRouterRtpCapabilities) {
|
|
29
55
|
this.onGetRTPCapabilities(participant);
|
|
30
56
|
}
|
|
57
|
+
else if (payload.type === EachSocketConnectionHandler_1.SFUMessageType.StartBroadcasting) {
|
|
58
|
+
this.startBroadcasting(payload.message);
|
|
59
|
+
}
|
|
31
60
|
else {
|
|
32
61
|
const sfuEachRoomUser = this.getEachRoomUserFromParticipant(participant);
|
|
33
62
|
if (sfuEachRoomUser) {
|
|
@@ -154,6 +183,24 @@ class SFUEachRoomHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
154
183
|
}
|
|
155
184
|
}
|
|
156
185
|
}
|
|
186
|
+
async onNewProducer(producer, participant) {
|
|
187
|
+
if (producer && producer.closed === false) {
|
|
188
|
+
if (this.plainTransportForAudio && producer.kind === "audio") {
|
|
189
|
+
this.plainTransportForAudio.consume({
|
|
190
|
+
producerId: producer.id,
|
|
191
|
+
rtpCapabilities: this.sendRouter.rtpCapabilities,
|
|
192
|
+
paused: false,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
else if (this.plainTransportForVideo && producer.kind === "video") {
|
|
196
|
+
this.plainTransportForVideo.consume({
|
|
197
|
+
producerId: producer.id,
|
|
198
|
+
rtpCapabilities: this.sendRouter.rtpCapabilities,
|
|
199
|
+
paused: false,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
157
204
|
async addAudioObserverForProducer(audioProducer) {
|
|
158
205
|
if (this.audioObserver) {
|
|
159
206
|
console.log("addAudioObserverForProducer", audioProducer.appData.userId);
|
|
@@ -166,6 +213,61 @@ class SFUEachRoomHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
166
213
|
this.roomPaticipants.delete(participant.userId);
|
|
167
214
|
}
|
|
168
215
|
}
|
|
216
|
+
async startBroadcasting(payload) {
|
|
217
|
+
const isAudioRequired = payload.message.isAudioRequired;
|
|
218
|
+
const isVideoRequired = payload.message.isVideoRequired;
|
|
219
|
+
const connectToIp = payload.message.connectToIp;
|
|
220
|
+
if (isAudioRequired && this.plainTransportForAudio === undefined) {
|
|
221
|
+
this.plainTransportForAudio = await this.sendRouter?.createPlainTransport(await Constant_1.default.plainTransportConfiguration());
|
|
222
|
+
if (this.plainTransportForAudio) {
|
|
223
|
+
const port = payload.message.audio.port;
|
|
224
|
+
const rtcpPort = payload.message.audio.rtcpPort;
|
|
225
|
+
await this.plainTransportForAudio.connect({
|
|
226
|
+
ip: connectToIp,
|
|
227
|
+
port: port,
|
|
228
|
+
rtcpPort: rtcpPort,
|
|
229
|
+
});
|
|
230
|
+
this.getAllProducerForRoom().forEach((eachRoomProducer) => {
|
|
231
|
+
if (eachRoomProducer && eachRoomProducer.producer && eachRoomProducer.producer.closed === false && eachRoomProducer.producer.kind === 'audio') {
|
|
232
|
+
try {
|
|
233
|
+
this.plainTransportForAudio?.consume({
|
|
234
|
+
producerId: eachRoomProducer.producer.id,
|
|
235
|
+
rtpCapabilities: this.sendRouter.rtpCapabilities,
|
|
236
|
+
paused: false,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
catch (err) {
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (isVideoRequired && this.plainTransportForVideo === undefined) {
|
|
246
|
+
this.plainTransportForVideo = await this.sendRouter?.createPlainTransport(await Constant_1.default.plainTransportConfiguration());
|
|
247
|
+
if (this.plainTransportForVideo) {
|
|
248
|
+
const port = payload.message.video.port;
|
|
249
|
+
const rtcpPort = payload.message.video.rtcpPort;
|
|
250
|
+
await this.plainTransportForVideo.connect({
|
|
251
|
+
ip: connectToIp,
|
|
252
|
+
port: port,
|
|
253
|
+
rtcpPort: rtcpPort,
|
|
254
|
+
});
|
|
255
|
+
this.getAllProducerForRoom().forEach((eachRoomProducer) => {
|
|
256
|
+
if (eachRoomProducer && eachRoomProducer.producer && eachRoomProducer.producer.closed === false && eachRoomProducer.producer.kind === 'video') {
|
|
257
|
+
try {
|
|
258
|
+
this.plainTransportForVideo?.consume({
|
|
259
|
+
producerId: eachRoomProducer.producer.id,
|
|
260
|
+
rtpCapabilities: this.sendRouter.rtpCapabilities,
|
|
261
|
+
paused: false,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
169
271
|
cleanUp() {
|
|
170
272
|
console.debug("Clean Up Room Id ", this.roomId);
|
|
171
273
|
RedisHandler_1.RedisHandler.getInstance().cleanUpRoomId(this.roomId);
|
|
@@ -227,6 +227,7 @@ class SFUEachRoomUserHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
227
227
|
if (producer.closed === false) {
|
|
228
228
|
await this.roomHandlerDataSource.pipeToRoute(producer);
|
|
229
229
|
this.producers.push(producer);
|
|
230
|
+
this.roomHandlerDataSource.onNewProducer(producer, this.selfParticipant);
|
|
230
231
|
this.redisBroadcastMessageToTopic(this.selfParticipant.roomId, this.preapreClientMessageBody(false, this.selfParticipant, this.preapreWebSocketMessageBody(EachSocketConnectionHandler_1.SFUMessageType.OnNewProducer, { producer: { id: producer.id, appData: producer.appData } })));
|
|
231
232
|
}
|
|
232
233
|
}
|
|
@@ -261,7 +262,7 @@ class SFUEachRoomUserHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
261
262
|
return;
|
|
262
263
|
}
|
|
263
264
|
if (!this.webrtcSendTransport || this.webrtcSendTransport.closed) {
|
|
264
|
-
this.webrtcSendTransport = await this.sendRouter?.createWebRtcTransport(await
|
|
265
|
+
this.webrtcSendTransport = await this.sendRouter?.createWebRtcTransport(await Constant_1.default.webrtcTransportConfiguration());
|
|
265
266
|
if (this.webrtcSendTransport) {
|
|
266
267
|
this.webrtcSendTransport.appData.type = 'send';
|
|
267
268
|
this.webrtcSendTransport.appData.userId = participant.userId;
|
|
@@ -297,7 +298,7 @@ class SFUEachRoomUserHandler extends BaseSFUWebsocket_1.BaseSFUWebsocket {
|
|
|
297
298
|
return;
|
|
298
299
|
}
|
|
299
300
|
if (!this.webrtcRecieveTransport || this.webrtcRecieveTransport.closed) {
|
|
300
|
-
this.webrtcRecieveTransport = await this.sendRouter?.createWebRtcTransport(await
|
|
301
|
+
this.webrtcRecieveTransport = await this.sendRouter?.createWebRtcTransport(await Constant_1.default.webrtcTransportConfiguration());
|
|
301
302
|
if (this.webrtcRecieveTransport) {
|
|
302
303
|
this.webrtcRecieveTransport.appData.type = 'consumer';
|
|
303
304
|
this.webrtcRecieveTransport.appData.userId = participant.userId;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RtpCodecCapability } from "mediasoup/node/lib/RtpParameters";
|
|
2
2
|
export declare const mediaCodecs: RtpCodecCapability[];
|
|
3
|
-
export
|
|
3
|
+
export declare function webrtcTransportConfiguration(): Promise<{
|
|
4
4
|
listenIps: {
|
|
5
5
|
ip: string;
|
|
6
6
|
announcedIp: string | undefined;
|
|
@@ -13,3 +13,16 @@ export default function webrtcTransportConfiguration(): Promise<{
|
|
|
13
13
|
sctpSendBufferSize: number;
|
|
14
14
|
enableSctp: boolean;
|
|
15
15
|
}>;
|
|
16
|
+
export declare function plainTransportConfiguration(): Promise<{
|
|
17
|
+
comedia: boolean;
|
|
18
|
+
rtcpMux: boolean;
|
|
19
|
+
listenIp: {
|
|
20
|
+
ip: string;
|
|
21
|
+
announcedIp: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
declare const _default: {
|
|
25
|
+
plainTransportConfiguration: typeof plainTransportConfiguration;
|
|
26
|
+
webrtcTransportConfiguration: typeof webrtcTransportConfiguration;
|
|
27
|
+
};
|
|
28
|
+
export default _default;
|
package/lib/utility/Constant.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mediaCodecs = void 0;
|
|
3
|
+
exports.plainTransportConfiguration = exports.webrtcTransportConfiguration = exports.mediaCodecs = void 0;
|
|
4
4
|
const ServerHandler_1 = require("../ServerHandler");
|
|
5
5
|
const publicIp = require('public-ip');
|
|
6
6
|
let publicIpAddress;
|
|
@@ -49,7 +49,7 @@ async function webrtcTransportConfiguration() {
|
|
|
49
49
|
publicIpAddress = await publicIp.v4();
|
|
50
50
|
}
|
|
51
51
|
return {
|
|
52
|
-
listenIps: [{ ip: '
|
|
52
|
+
listenIps: [{ ip: '127.0.0.1', announcedIp: publicIpAddress }],
|
|
53
53
|
enableUdp: true,
|
|
54
54
|
enableTcp: true,
|
|
55
55
|
preferUdp: !ServerHandler_1.ServerHandler.getInstance().serverStartRequest.isTCPConnection,
|
|
@@ -59,4 +59,18 @@ async function webrtcTransportConfiguration() {
|
|
|
59
59
|
enableSctp: true,
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
exports.
|
|
62
|
+
exports.webrtcTransportConfiguration = webrtcTransportConfiguration;
|
|
63
|
+
;
|
|
64
|
+
async function plainTransportConfiguration() {
|
|
65
|
+
if (!publicIpAddress) {
|
|
66
|
+
publicIpAddress = await publicIp.v4();
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
comedia: false,
|
|
70
|
+
rtcpMux: false,
|
|
71
|
+
listenIp: { ip: '127.0.0.1', announcedIp: publicIpAddress },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
exports.plainTransportConfiguration = plainTransportConfiguration;
|
|
75
|
+
;
|
|
76
|
+
exports.default = { plainTransportConfiguration, webrtcTransportConfiguration };
|
|
@@ -35,6 +35,7 @@ export declare enum SFUMessageType {
|
|
|
35
35
|
SFUMessage = "sfuMessage",
|
|
36
36
|
GetRouterRtpCapabilities = "routerRtpCapabilities",
|
|
37
37
|
OnRouterRtpCapabilities = "onRouterRtpCapabilities",
|
|
38
|
+
StartBroadcasting = "startBroadcasting",
|
|
38
39
|
OnTransportConnect = "transportConnect",
|
|
39
40
|
OnCreateTransports = "createTransports",
|
|
40
41
|
OnTransportConnectDone = "transportConnectDone",
|
|
@@ -44,6 +44,7 @@ var SFUMessageType;
|
|
|
44
44
|
SFUMessageType["SFUMessage"] = "sfuMessage";
|
|
45
45
|
SFUMessageType["GetRouterRtpCapabilities"] = "routerRtpCapabilities";
|
|
46
46
|
SFUMessageType["OnRouterRtpCapabilities"] = "onRouterRtpCapabilities";
|
|
47
|
+
SFUMessageType["StartBroadcasting"] = "startBroadcasting";
|
|
47
48
|
SFUMessageType["OnTransportConnect"] = "transportConnect";
|
|
48
49
|
SFUMessageType["OnCreateTransports"] = "createTransports";
|
|
49
50
|
SFUMessageType["OnTransportConnectDone"] = "transportConnectDone";
|