vani-meeting-client 2.2.3-beta1 → 2.2.3-beta10
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/model/Participant.d.ts +1 -0
- package/lib/model/Participant.js +7 -0
- package/lib/model/PeerConnection.d.ts +2 -0
- package/lib/video-call-handler/WebrtcHandler.d.ts +11 -0
- package/lib/video-call-handler/WebrtcHandler.js +82 -13
- package/lib/websocket-handler/WebsocketHandler.d.ts +1 -0
- package/lib/websocket-handler/WebsocketHandler.js +6 -0
- package/package.json +1 -1
|
@@ -15,5 +15,6 @@ export declare class Participant {
|
|
|
15
15
|
isRecordingUser: boolean;
|
|
16
16
|
private peerConnections;
|
|
17
17
|
getPeerConnections: () => Map<string, PeerConnection>;
|
|
18
|
+
getPeerConnectionsViaUserId: (userId: string) => PeerConnection;
|
|
18
19
|
constructor(_userId: string, _roomId: string, _userData?: any, _isAdmin?: boolean);
|
|
19
20
|
}
|
package/lib/model/Participant.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PeerConnection } from "./PeerConnection";
|
|
1
2
|
var Participant = /** @class */ (function () {
|
|
2
3
|
function Participant(_userId, _roomId, _userData, _isAdmin) {
|
|
3
4
|
if (_userData === void 0) { _userData = {}; }
|
|
@@ -20,6 +21,12 @@ var Participant = /** @class */ (function () {
|
|
|
20
21
|
}
|
|
21
22
|
return _this.peerConnections;
|
|
22
23
|
};
|
|
24
|
+
this.getPeerConnectionsViaUserId = function (userId) {
|
|
25
|
+
if (!_this.getPeerConnections().has(userId)) {
|
|
26
|
+
_this.getPeerConnections().set(userId, new PeerConnection());
|
|
27
|
+
}
|
|
28
|
+
return _this.getPeerConnections().get(userId);
|
|
29
|
+
};
|
|
23
30
|
this.userId = _userId;
|
|
24
31
|
this.roomId = _roomId;
|
|
25
32
|
this.userData = _userData;
|
|
@@ -8,8 +8,19 @@ export declare class WebrtcHandler extends BaseVideoCallHandler {
|
|
|
8
8
|
resumeIncomingTrack(track: Track): void;
|
|
9
9
|
pauseIncomingTrack(track: Track): void;
|
|
10
10
|
onSocketMessage(websocketCallHandler: WebSocketMessageBody): void;
|
|
11
|
+
onNewOffer: (data: {
|
|
12
|
+
sdp: string;
|
|
13
|
+
type: string;
|
|
14
|
+
sender: Participant;
|
|
15
|
+
}) => Promise<void>;
|
|
16
|
+
onNewAnswer: (data: {
|
|
17
|
+
sdp: string;
|
|
18
|
+
type: string;
|
|
19
|
+
sender: Participant;
|
|
20
|
+
}) => Promise<void>;
|
|
11
21
|
onAllParticipants(participants: Participant[]): Promise<void>;
|
|
12
22
|
onUserJoined(participant: Participant): Promise<void>;
|
|
23
|
+
private sendWebrtcMessage;
|
|
13
24
|
init(): Promise<void>;
|
|
14
25
|
onReconnect(): Promise<void>;
|
|
15
26
|
stopTrack(track: Track): void;
|
|
@@ -49,16 +49,65 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
49
49
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
|
+
import { WebrtcMessageType } from "../websocket-handler/WebsocketHandler";
|
|
52
53
|
import { BaseVideoCallHandler } from "./BaseVideoCallHandler";
|
|
53
54
|
import log from 'loglevel';
|
|
54
55
|
import { LogLevel } from "../model/MeetingStartRequest";
|
|
55
56
|
import { DynamicLibHelper } from "../utility/DynamicLibHelper";
|
|
56
|
-
import { PeerConnection } from "../model/PeerConnection";
|
|
57
57
|
var WebrtcHandler = /** @class */ (function (_super) {
|
|
58
58
|
__extends(WebrtcHandler, _super);
|
|
59
59
|
function WebrtcHandler() {
|
|
60
60
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
61
61
|
_this.dynamicLibHelper = (new DynamicLibHelper());
|
|
62
|
+
_this.onNewOffer = function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
63
|
+
var selfParticpant, participant, peerConnectionObject, peerConnection, answer, messageJson;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
selfParticpant = this.communicationHandler.getSelfParticipant();
|
|
68
|
+
participant = data.sender;
|
|
69
|
+
peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(participant.userId);
|
|
70
|
+
if (peerConnectionObject) {
|
|
71
|
+
peerConnectionObject.remoteOffer = data.sdp;
|
|
72
|
+
}
|
|
73
|
+
peerConnection = peerConnectionObject.rtcPeerConnection ? peerConnectionObject.rtcPeerConnection : this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
|
|
74
|
+
if (!peerConnection) return [3 /*break*/, 2];
|
|
75
|
+
peerConnection.setRemoteDescription(peerConnectionObject.remoteOffer);
|
|
76
|
+
peerConnection.addTransceiver("audio", { direction: "sendrecv" });
|
|
77
|
+
peerConnection.addTransceiver("video", { direction: "sendrecv" });
|
|
78
|
+
return [4 /*yield*/, peerConnection.createAnswer()];
|
|
79
|
+
case 1:
|
|
80
|
+
answer = _a.sent();
|
|
81
|
+
peerConnection.setLocalDescription(answer);
|
|
82
|
+
peerConnectionObject.answer = answer;
|
|
83
|
+
peerConnectionObject.rtcPeerConnection = peerConnection;
|
|
84
|
+
console.log("answer", answer);
|
|
85
|
+
messageJson = { to: participant.userId, type: WebrtcMessageType.SendAnswer, data: answer };
|
|
86
|
+
this.sendWebrtcMessage(messageJson);
|
|
87
|
+
_a.label = 2;
|
|
88
|
+
case 2: return [2 /*return*/];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}); };
|
|
92
|
+
_this.onNewAnswer = function (data) { return __awaiter(_this, void 0, void 0, function () {
|
|
93
|
+
var selfParticpant, participant, peerConnectionObject, peerConnection;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
selfParticpant = this.communicationHandler.getSelfParticipant();
|
|
96
|
+
participant = data.sender;
|
|
97
|
+
peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(participant.userId);
|
|
98
|
+
if (peerConnectionObject) {
|
|
99
|
+
peerConnectionObject.remoteAnswer = data.sdp;
|
|
100
|
+
}
|
|
101
|
+
peerConnection = peerConnectionObject.rtcPeerConnection ? peerConnectionObject.rtcPeerConnection : this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
|
|
102
|
+
if (peerConnection) {
|
|
103
|
+
peerConnection.setRemoteDescription(peerConnectionObject.remoteAnswer);
|
|
104
|
+
}
|
|
105
|
+
return [2 /*return*/];
|
|
106
|
+
});
|
|
107
|
+
}); };
|
|
108
|
+
_this.sendWebrtcMessage = function (data) {
|
|
109
|
+
_this.communicationHandler.sendWebSocketMessage(WebrtcMessageType.WebrtcMessage, data);
|
|
110
|
+
};
|
|
62
111
|
_this.isOfferInitParticipant = function (participant) {
|
|
63
112
|
var selfParticpant = _this.communicationHandler.getSelfParticipant();
|
|
64
113
|
if (participant.userId > selfParticpant.userId) {
|
|
@@ -79,6 +128,27 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
79
128
|
// throw new Error("Method not implemented.");
|
|
80
129
|
};
|
|
81
130
|
WebrtcHandler.prototype.onSocketMessage = function (websocketCallHandler) {
|
|
131
|
+
var _a;
|
|
132
|
+
console.log("websocketCallHandler", websocketCallHandler);
|
|
133
|
+
var data = websocketCallHandler.data;
|
|
134
|
+
if (websocketCallHandler.data.message) {
|
|
135
|
+
data = websocketCallHandler.data.message;
|
|
136
|
+
}
|
|
137
|
+
if (data.sender && data.sender._id) {
|
|
138
|
+
var participant = this.communicationHandler.participantByUserId(data.sender._id);
|
|
139
|
+
if (!participant) {
|
|
140
|
+
data.sender = (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.addParticipantIfNotExist(data.sender, false);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
data.sender = participant;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (websocketCallHandler.type === WebrtcMessageType.SendOffer) {
|
|
147
|
+
this.onNewOffer(data);
|
|
148
|
+
}
|
|
149
|
+
else if (websocketCallHandler.type === WebrtcMessageType.SendAnswer) {
|
|
150
|
+
this.onNewAnswer(data);
|
|
151
|
+
}
|
|
82
152
|
// throw new Error("Method not implemented.");
|
|
83
153
|
};
|
|
84
154
|
WebrtcHandler.prototype.onAllParticipants = function (participants) {
|
|
@@ -94,22 +164,18 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
94
164
|
};
|
|
95
165
|
WebrtcHandler.prototype.onUserJoined = function (participant) {
|
|
96
166
|
return __awaiter(this, void 0, void 0, function () {
|
|
97
|
-
var selfParticpant, isOfferInitParticipant, peerConnectionObject, peerConnection, offer;
|
|
167
|
+
var selfParticpant, isOfferInitParticipant, peerConnectionObject, peerConnection, offer, messageJson;
|
|
98
168
|
return __generator(this, function (_a) {
|
|
99
169
|
switch (_a.label) {
|
|
100
170
|
case 0:
|
|
101
171
|
selfParticpant = this.communicationHandler.getSelfParticipant();
|
|
102
172
|
console.log(selfParticpant);
|
|
103
|
-
debugger;
|
|
104
173
|
if (!(selfParticpant.userId !== participant.userId && !selfParticpant.getPeerConnections().has(participant.userId))) return [3 /*break*/, 2];
|
|
105
174
|
console.log("onUserJoined ", participant);
|
|
106
175
|
isOfferInitParticipant = this.isOfferInitParticipant(participant);
|
|
107
176
|
if (!!isOfferInitParticipant) return [3 /*break*/, 2];
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
peerConnectionObject = selfParticpant.getPeerConnections().get(participant.userId);
|
|
112
|
-
peerConnection = this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
|
|
177
|
+
peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(participant.userId);
|
|
178
|
+
peerConnection = peerConnectionObject.rtcPeerConnection ? peerConnectionObject.rtcPeerConnection : this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
|
|
113
179
|
if (!peerConnection) return [3 /*break*/, 2];
|
|
114
180
|
peerConnection.addTransceiver("audio", { direction: "sendrecv" });
|
|
115
181
|
peerConnection.addTransceiver("video", { direction: "sendrecv" });
|
|
@@ -118,8 +184,11 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
118
184
|
offer = _a.sent();
|
|
119
185
|
peerConnection.setLocalDescription(offer);
|
|
120
186
|
peerConnectionObject.offer = offer;
|
|
187
|
+
peerConnectionObject.rtcPeerConnection = peerConnection;
|
|
121
188
|
// send offer to peer
|
|
122
189
|
console.log("offer", offer);
|
|
190
|
+
messageJson = { to: participant.userId, type: WebrtcMessageType.SendOffer, data: offer };
|
|
191
|
+
this.sendWebrtcMessage(messageJson);
|
|
123
192
|
_a.label = 2;
|
|
124
193
|
case 2: return [2 /*return*/];
|
|
125
194
|
}
|
|
@@ -138,16 +207,16 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
138
207
|
throw new Error("Method not implemented.");
|
|
139
208
|
};
|
|
140
209
|
WebrtcHandler.prototype.stopTrack = function (track) {
|
|
141
|
-
throw new Error("Method not implemented.");
|
|
210
|
+
// throw new Error("Method not implemented.");
|
|
142
211
|
};
|
|
143
212
|
WebrtcHandler.prototype.pauseTrack = function (track) {
|
|
144
|
-
throw new Error("Method not implemented.");
|
|
213
|
+
// throw new Error("Method not implemented.");
|
|
145
214
|
};
|
|
146
215
|
WebrtcHandler.prototype.resumeTrack = function (track) {
|
|
147
|
-
throw new Error("Method not implemented.");
|
|
216
|
+
// throw new Error("Method not implemented.");
|
|
148
217
|
};
|
|
149
218
|
WebrtcHandler.prototype.sendTrack = function (track) {
|
|
150
|
-
throw new Error("Method not implemented.");
|
|
219
|
+
// throw new Error("Method not implemented.");
|
|
151
220
|
};
|
|
152
221
|
WebrtcHandler.prototype.createDataChannel = function () {
|
|
153
222
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -157,7 +226,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
157
226
|
});
|
|
158
227
|
};
|
|
159
228
|
WebrtcHandler.prototype.sendMessageViaDataChannel = function (messagePayload) {
|
|
160
|
-
throw new Error('Method not implemented.');
|
|
229
|
+
// throw new Error('Method not implemented.');
|
|
161
230
|
};
|
|
162
231
|
return WebrtcHandler;
|
|
163
232
|
}(BaseVideoCallHandler));
|
|
@@ -88,6 +88,7 @@ export var WebSocketBasicEvents;
|
|
|
88
88
|
export var WebrtcMessageType;
|
|
89
89
|
(function (WebrtcMessageType) {
|
|
90
90
|
WebrtcMessageType["SendOffer"] = "SendOffer";
|
|
91
|
+
WebrtcMessageType["WebrtcMessage"] = "WebrtcMessage";
|
|
91
92
|
WebrtcMessageType["SendAnswer"] = "SendAnswer";
|
|
92
93
|
})(WebrtcMessageType || (WebrtcMessageType = {}));
|
|
93
94
|
export var SFUMessageType;
|
|
@@ -487,6 +488,7 @@ var WebsocketHandler = /** @class */ (function (_super) {
|
|
|
487
488
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
488
489
|
this.lastPingTimeStamp = new Date().getTime();
|
|
489
490
|
// this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("lastPingTimeStamp time ", this.lastPingTimeStamp)
|
|
491
|
+
console.log("message", message);
|
|
490
492
|
var messagejson = JSON.parse(message);
|
|
491
493
|
if (messagejson.type && messagejson.data) {
|
|
492
494
|
var type = messagejson.type;
|
|
@@ -610,9 +612,13 @@ var WebsocketHandler = /** @class */ (function (_super) {
|
|
|
610
612
|
}
|
|
611
613
|
};
|
|
612
614
|
WebsocketHandler.prototype.isVideoCallControllerMessageType = function (type) {
|
|
615
|
+
console.log("isVideoCallControllerMessageType", type);
|
|
613
616
|
if (Object.values(SFUMessageType).includes(type)) {
|
|
614
617
|
return true;
|
|
615
618
|
}
|
|
619
|
+
else if (Object.values(WebrtcMessageType).includes(type)) {
|
|
620
|
+
return true;
|
|
621
|
+
}
|
|
616
622
|
return false;
|
|
617
623
|
};
|
|
618
624
|
return WebsocketHandler;
|