vani-meeting-client 2.2.3-beta6 → 2.2.3-beta8

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.
@@ -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
  }
@@ -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;
@@ -1,6 +1,8 @@
1
1
  export declare class PeerConnection {
2
2
  rtcPeerConnection: any;
3
3
  offer: any;
4
+ remoteOffer: any;
4
5
  answer: any;
6
+ remoteAnswer: any;
5
7
  userId: string;
6
8
  }
@@ -8,6 +8,16 @@ 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>;
13
23
  private sendWebrtcMessage;
@@ -54,12 +54,57 @@ import { BaseVideoCallHandler } from "./BaseVideoCallHandler";
54
54
  import log from 'loglevel';
55
55
  import { LogLevel } from "../model/MeetingStartRequest";
56
56
  import { DynamicLibHelper } from "../utility/DynamicLibHelper";
57
- import { PeerConnection } from "../model/PeerConnection";
58
57
  var WebrtcHandler = /** @class */ (function (_super) {
59
58
  __extends(WebrtcHandler, _super);
60
59
  function WebrtcHandler() {
61
60
  var _this = _super !== null && _super.apply(this, arguments) || this;
62
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
+ }); };
63
108
  _this.sendWebrtcMessage = function (data) {
64
109
  _this.communicationHandler.sendWebSocketMessage(WebrtcMessageType.WebrtcMessage, data);
65
110
  };
@@ -83,9 +128,26 @@ var WebrtcHandler = /** @class */ (function (_super) {
83
128
  // throw new Error("Method not implemented.");
84
129
  };
85
130
  WebrtcHandler.prototype.onSocketMessage = function (websocketCallHandler) {
131
+ var _a;
86
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
+ }
87
146
  if (websocketCallHandler.type === WebrtcMessageType.SendOffer) {
88
- console.log("New Offer", websocketCallHandler.data);
147
+ this.onNewOffer(data);
148
+ }
149
+ else if (websocketCallHandler.type === WebrtcMessageType.SendAnswer) {
150
+ this.onNewAnswer(data);
89
151
  }
90
152
  // throw new Error("Method not implemented.");
91
153
  };
@@ -112,11 +174,8 @@ var WebrtcHandler = /** @class */ (function (_super) {
112
174
  console.log("onUserJoined ", participant);
113
175
  isOfferInitParticipant = this.isOfferInitParticipant(participant);
114
176
  if (!!isOfferInitParticipant) return [3 /*break*/, 2];
115
- if (!selfParticpant.getPeerConnections().has(participant.userId)) {
116
- selfParticpant.getPeerConnections().set(participant.userId, new PeerConnection());
117
- }
118
- peerConnectionObject = selfParticpant.getPeerConnections().get(participant.userId);
119
- peerConnection = this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
177
+ peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(participant.userId);
178
+ peerConnection = peerConnectionObject.rtcPeerConnection ? peerConnectionObject.rtcPeerConnection : this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
120
179
  if (!peerConnection) return [3 /*break*/, 2];
121
180
  peerConnection.addTransceiver("audio", { direction: "sendrecv" });
122
181
  peerConnection.addTransceiver("video", { direction: "sendrecv" });
@@ -125,6 +184,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
125
184
  offer = _a.sent();
126
185
  peerConnection.setLocalDescription(offer);
127
186
  peerConnectionObject.offer = offer;
187
+ peerConnectionObject.rtcPeerConnection = peerConnection;
128
188
  // send offer to peer
129
189
  console.log("offer", offer);
130
190
  messageJson = { to: participant.userId, type: WebrtcMessageType.SendOffer, data: offer };
@@ -488,6 +488,7 @@ var WebsocketHandler = /** @class */ (function (_super) {
488
488
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
489
489
  this.lastPingTimeStamp = new Date().getTime();
490
490
  // this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("lastPingTimeStamp time ", this.lastPingTimeStamp)
491
+ console.log("message", message);
491
492
  var messagejson = JSON.parse(message);
492
493
  if (messagejson.type && messagejson.data) {
493
494
  var type = messagejson.type;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vani-meeting-client",
3
- "version": "2.2.3beta6",
3
+ "version": "2.2.3beta8",
4
4
  "description": "Vani Meeting Clinet SDK",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",