mezon-js 2.9.70 → 2.9.71

Sign up to get free protection for your applications and to get access to all the features.
@@ -6817,43 +6817,9 @@ var _DefaultSocket = class _DefaultSocket {
6817
6817
  } else if (message.token_sent_event) {
6818
6818
  this.ontokensent(message.token_sent_event);
6819
6819
  } else if (message.message_button_clicked) {
6820
- this.handleMessageButtonClick(
6821
- message.message_button_clicked
6822
- );
6823
- } else if (message.call_request) {
6824
- console.log("message.call_request", message.call_request);
6825
- yield this.adapter.getRTCPeerConnection().setRemoteDescription(
6826
- new RTCSessionDescription({
6827
- type: "offer",
6828
- sdp: message.call_request.sdp
6829
- })
6830
- );
6831
- const answer = yield this.adapter.getRTCPeerConnection().createAnswer();
6832
- yield this.adapter.getRTCPeerConnection().setLocalDescription(answer);
6833
- yield this.sendCallAccept({
6834
- sdp: answer.sdp,
6835
- type: "answer"
6836
- });
6837
- this.onCallRequest(message.call_request);
6838
- } else if (message.call_accept) {
6839
- console.log("message.call_accept", message.call_accept);
6840
- yield this.adapter.getRTCPeerConnection().setRemoteDescription(
6841
- new RTCSessionDescription({
6842
- type: "answer",
6843
- sdp: message.call_accept.sdp
6844
- })
6845
- );
6846
- this.onCallAccept(message.call_accept);
6847
- } else if (message.ice_candidate_init) {
6848
- console.log("message.ice_candidate_init", message.ice_candidate_init);
6849
- const rtcIceCandidate = new RTCIceCandidate({
6850
- candidate: message.ice_candidate_init.candidate,
6851
- sdpMid: message.ice_candidate_init.sdpMid || "audio",
6852
- sdpMLineIndex: message.ice_candidate_init.sdpMLineIndex || 0,
6853
- usernameFragment: message.ice_candidate_init.usernameFragment || void 0
6854
- });
6855
- yield this.adapter.getRTCPeerConnection().addIceCandidate(rtcIceCandidate);
6856
- this.onIceCandidateInit(message.ice_candidate_init);
6820
+ this.onmessagebuttonclicked(message.message_button_clicked);
6821
+ } else if (message.webrtc_signaling_fwd) {
6822
+ this.onwebrtcsignalingfwd(message.webrtc_signaling_fwd);
6857
6823
  } else {
6858
6824
  if (this.verbose && window && window.console) {
6859
6825
  console.log("Unrecognized message received: %o", message);
@@ -7131,24 +7097,14 @@ var _DefaultSocket = class _DefaultSocket {
7131
7097
  console.log(tokenSentEvent);
7132
7098
  }
7133
7099
  }
7134
- handleMessageButtonClick(messageButtonClicked) {
7100
+ onmessagebuttonclicked(messageButtonClicked) {
7135
7101
  if (this.verbose && window && window.console) {
7136
7102
  console.log(messageButtonClicked);
7137
7103
  }
7138
7104
  }
7139
- onCallRequest(callRequest) {
7140
- if (this.verbose && window && window.console) {
7141
- console.log(callRequest);
7142
- }
7143
- }
7144
- onCallAccept(callAccept) {
7145
- if (this.verbose && window && window.console) {
7146
- console.log(callAccept);
7147
- }
7148
- }
7149
- onIceCandidateInit(iceCandidateInit) {
7105
+ onwebrtcsignalingfwd(event) {
7150
7106
  if (this.verbose && window && window.console) {
7151
- console.log(iceCandidateInit);
7107
+ console.log(event);
7152
7108
  }
7153
7109
  }
7154
7110
  send(message, sendTimeout = _DefaultSocket.DefaultSendTimeoutMs) {
@@ -7176,54 +7132,6 @@ var _DefaultSocket = class _DefaultSocket {
7176
7132
  }
7177
7133
  });
7178
7134
  }
7179
- getRTCPeerConnection() {
7180
- return this.adapter.getRTCPeerConnection();
7181
- }
7182
- startCall(localVideoRef, remoteVideoRef, grant_permissions) {
7183
- return __async(this, null, function* () {
7184
- this.adapter.getRTCPeerConnection().onicecandidate = (event) => {
7185
- if (event && event.candidate) {
7186
- this.sendICECandidateInit({ candidate: event == null ? void 0 : event.candidate });
7187
- }
7188
- };
7189
- this.adapter.getRTCPeerConnection().ontrack = (event) => {
7190
- if (remoteVideoRef) {
7191
- remoteVideoRef.srcObject = event.streams[0];
7192
- }
7193
- };
7194
- const stream = yield navigator.mediaDevices.getUserMedia(grant_permissions);
7195
- if (localVideoRef) {
7196
- localVideoRef.srcObject = stream;
7197
- }
7198
- stream.getTracks().forEach(
7199
- (track) => {
7200
- var _a;
7201
- return (_a = this.adapter.getRTCPeerConnection()) == null ? void 0 : _a.addTrack(track, stream);
7202
- }
7203
- );
7204
- const offer = yield this.adapter.getRTCPeerConnection().createOffer();
7205
- yield this.adapter.getRTCPeerConnection().setLocalDescription(offer);
7206
- yield this.sendCallRequest({
7207
- sdp: offer == null ? void 0 : offer.sdp,
7208
- type: "offer"
7209
- });
7210
- });
7211
- }
7212
- sendCallRequest(req) {
7213
- return __async(this, null, function* () {
7214
- return yield this.send({ call_request: req });
7215
- });
7216
- }
7217
- sendCallAccept(req) {
7218
- return __async(this, null, function* () {
7219
- return yield this.send({ call_accept: req });
7220
- });
7221
- }
7222
- sendICECandidateInit(req) {
7223
- return __async(this, null, function* () {
7224
- return yield this.send({ ice_candidate_init: req });
7225
- });
7226
- }
7227
7135
  followUsers(userIds) {
7228
7136
  return __async(this, null, function* () {
7229
7137
  const response = yield this.send({ status_follow: { user_ids: userIds } });
@@ -7445,6 +7353,22 @@ var _DefaultSocket = class _DefaultSocket {
7445
7353
  return response.check_name_existed_event;
7446
7354
  });
7447
7355
  }
7356
+ forwardWebrtcSignaling(receiver_id, data_type, json_data) {
7357
+ return __async(this, null, function* () {
7358
+ const response = yield this.send({
7359
+ webrtc_signaling_fwd: { receiver_id, data_type, json_data }
7360
+ });
7361
+ return response.webrtc_signaling_fwd;
7362
+ });
7363
+ }
7364
+ handleMessageButtonClick(message_id, channel_id, button_id, sender_id, user_id) {
7365
+ return __async(this, null, function* () {
7366
+ const response = yield this.send({
7367
+ message_button_clicked: { message_id, channel_id, button_id, sender_id, user_id }
7368
+ });
7369
+ return response.webrtc_signaling_fwd;
7370
+ });
7371
+ }
7448
7372
  pingPong() {
7449
7373
  return __async(this, null, function* () {
7450
7374
  if (!this.adapter.isOpen()) {
@@ -6788,43 +6788,9 @@ var _DefaultSocket = class _DefaultSocket {
6788
6788
  } else if (message.token_sent_event) {
6789
6789
  this.ontokensent(message.token_sent_event);
6790
6790
  } else if (message.message_button_clicked) {
6791
- this.handleMessageButtonClick(
6792
- message.message_button_clicked
6793
- );
6794
- } else if (message.call_request) {
6795
- console.log("message.call_request", message.call_request);
6796
- yield this.adapter.getRTCPeerConnection().setRemoteDescription(
6797
- new RTCSessionDescription({
6798
- type: "offer",
6799
- sdp: message.call_request.sdp
6800
- })
6801
- );
6802
- const answer = yield this.adapter.getRTCPeerConnection().createAnswer();
6803
- yield this.adapter.getRTCPeerConnection().setLocalDescription(answer);
6804
- yield this.sendCallAccept({
6805
- sdp: answer.sdp,
6806
- type: "answer"
6807
- });
6808
- this.onCallRequest(message.call_request);
6809
- } else if (message.call_accept) {
6810
- console.log("message.call_accept", message.call_accept);
6811
- yield this.adapter.getRTCPeerConnection().setRemoteDescription(
6812
- new RTCSessionDescription({
6813
- type: "answer",
6814
- sdp: message.call_accept.sdp
6815
- })
6816
- );
6817
- this.onCallAccept(message.call_accept);
6818
- } else if (message.ice_candidate_init) {
6819
- console.log("message.ice_candidate_init", message.ice_candidate_init);
6820
- const rtcIceCandidate = new RTCIceCandidate({
6821
- candidate: message.ice_candidate_init.candidate,
6822
- sdpMid: message.ice_candidate_init.sdpMid || "audio",
6823
- sdpMLineIndex: message.ice_candidate_init.sdpMLineIndex || 0,
6824
- usernameFragment: message.ice_candidate_init.usernameFragment || void 0
6825
- });
6826
- yield this.adapter.getRTCPeerConnection().addIceCandidate(rtcIceCandidate);
6827
- this.onIceCandidateInit(message.ice_candidate_init);
6791
+ this.onmessagebuttonclicked(message.message_button_clicked);
6792
+ } else if (message.webrtc_signaling_fwd) {
6793
+ this.onwebrtcsignalingfwd(message.webrtc_signaling_fwd);
6828
6794
  } else {
6829
6795
  if (this.verbose && window && window.console) {
6830
6796
  console.log("Unrecognized message received: %o", message);
@@ -7102,24 +7068,14 @@ var _DefaultSocket = class _DefaultSocket {
7102
7068
  console.log(tokenSentEvent);
7103
7069
  }
7104
7070
  }
7105
- handleMessageButtonClick(messageButtonClicked) {
7071
+ onmessagebuttonclicked(messageButtonClicked) {
7106
7072
  if (this.verbose && window && window.console) {
7107
7073
  console.log(messageButtonClicked);
7108
7074
  }
7109
7075
  }
7110
- onCallRequest(callRequest) {
7111
- if (this.verbose && window && window.console) {
7112
- console.log(callRequest);
7113
- }
7114
- }
7115
- onCallAccept(callAccept) {
7116
- if (this.verbose && window && window.console) {
7117
- console.log(callAccept);
7118
- }
7119
- }
7120
- onIceCandidateInit(iceCandidateInit) {
7076
+ onwebrtcsignalingfwd(event) {
7121
7077
  if (this.verbose && window && window.console) {
7122
- console.log(iceCandidateInit);
7078
+ console.log(event);
7123
7079
  }
7124
7080
  }
7125
7081
  send(message, sendTimeout = _DefaultSocket.DefaultSendTimeoutMs) {
@@ -7147,54 +7103,6 @@ var _DefaultSocket = class _DefaultSocket {
7147
7103
  }
7148
7104
  });
7149
7105
  }
7150
- getRTCPeerConnection() {
7151
- return this.adapter.getRTCPeerConnection();
7152
- }
7153
- startCall(localVideoRef, remoteVideoRef, grant_permissions) {
7154
- return __async(this, null, function* () {
7155
- this.adapter.getRTCPeerConnection().onicecandidate = (event) => {
7156
- if (event && event.candidate) {
7157
- this.sendICECandidateInit({ candidate: event == null ? void 0 : event.candidate });
7158
- }
7159
- };
7160
- this.adapter.getRTCPeerConnection().ontrack = (event) => {
7161
- if (remoteVideoRef) {
7162
- remoteVideoRef.srcObject = event.streams[0];
7163
- }
7164
- };
7165
- const stream = yield navigator.mediaDevices.getUserMedia(grant_permissions);
7166
- if (localVideoRef) {
7167
- localVideoRef.srcObject = stream;
7168
- }
7169
- stream.getTracks().forEach(
7170
- (track) => {
7171
- var _a;
7172
- return (_a = this.adapter.getRTCPeerConnection()) == null ? void 0 : _a.addTrack(track, stream);
7173
- }
7174
- );
7175
- const offer = yield this.adapter.getRTCPeerConnection().createOffer();
7176
- yield this.adapter.getRTCPeerConnection().setLocalDescription(offer);
7177
- yield this.sendCallRequest({
7178
- sdp: offer == null ? void 0 : offer.sdp,
7179
- type: "offer"
7180
- });
7181
- });
7182
- }
7183
- sendCallRequest(req) {
7184
- return __async(this, null, function* () {
7185
- return yield this.send({ call_request: req });
7186
- });
7187
- }
7188
- sendCallAccept(req) {
7189
- return __async(this, null, function* () {
7190
- return yield this.send({ call_accept: req });
7191
- });
7192
- }
7193
- sendICECandidateInit(req) {
7194
- return __async(this, null, function* () {
7195
- return yield this.send({ ice_candidate_init: req });
7196
- });
7197
- }
7198
7106
  followUsers(userIds) {
7199
7107
  return __async(this, null, function* () {
7200
7108
  const response = yield this.send({ status_follow: { user_ids: userIds } });
@@ -7416,6 +7324,22 @@ var _DefaultSocket = class _DefaultSocket {
7416
7324
  return response.check_name_existed_event;
7417
7325
  });
7418
7326
  }
7327
+ forwardWebrtcSignaling(receiver_id, data_type, json_data) {
7328
+ return __async(this, null, function* () {
7329
+ const response = yield this.send({
7330
+ webrtc_signaling_fwd: { receiver_id, data_type, json_data }
7331
+ });
7332
+ return response.webrtc_signaling_fwd;
7333
+ });
7334
+ }
7335
+ handleMessageButtonClick(message_id, channel_id, button_id, sender_id, user_id) {
7336
+ return __async(this, null, function* () {
7337
+ const response = yield this.send({
7338
+ message_button_clicked: { message_id, channel_id, button_id, sender_id, user_id }
7339
+ });
7340
+ return response.webrtc_signaling_fwd;
7341
+ });
7342
+ }
7419
7343
  pingPong() {
7420
7344
  return __async(this, null, function* () {
7421
7345
  if (!this.adapter.isOpen()) {
package/dist/socket.d.ts CHANGED
@@ -584,19 +584,10 @@ export interface MessageButtonClicked {
584
584
  sender_id: string;
585
585
  user_id: string;
586
586
  }
587
- export interface CallRequest {
588
- type: string;
589
- sdp: string;
590
- }
591
- export interface CallAccept {
592
- type: string;
593
- sdp: string;
594
- }
595
- export interface ICECandidateInit {
596
- candidate: string;
597
- sdpMid: string | undefined;
598
- sdpMLineIndex: number | undefined;
599
- usernameFragment: string | undefined;
587
+ export interface WebrtcSignalingFwd {
588
+ receiverId: string;
589
+ dataType: number;
590
+ jsonData: string;
600
591
  }
601
592
  /** A socket connection to Mezon server. */
602
593
  export interface Socket {
@@ -604,7 +595,6 @@ export interface Socket {
604
595
  isOpen(): boolean;
605
596
  /** Connect to the server. */
606
597
  connect(session: Session, createStatus: boolean, platform: string, connectTimeoutMs?: number, signal?: AbortSignal): Promise<Session>;
607
- getRTCPeerConnection(): RTCPeerConnection;
608
598
  /** Disconnect from the server. */
609
599
  disconnect(fireDisconnectEvent: boolean): void;
610
600
  /** Subscribe to one or more users for their status updates. */
@@ -699,10 +689,10 @@ export interface Socket {
699
689
  setHeartbeatTimeoutMs(ms: number): void;
700
690
  getHeartbeatTimeoutMs(): number;
701
691
  checkDuplicateName(name: string, condition_id: string, type: number): Promise<CheckNameExistedEvent>;
702
- handleMessageButtonClick: (message_button_clicked: MessageButtonClicked) => void;
703
- onCallRequest: (call_request: CallRequest) => void;
704
- onCallAccept: (call_accept: CallAccept) => void;
705
- onIceCandidateInit: (ice_candidate_init: ICECandidateInit) => void;
692
+ handleMessageButtonClick: (message_id: string, channel_id: string, button_id: string, sender_id: string, user_id: string) => Promise<MessageButtonClicked>;
693
+ onmessagebuttonclicked: (event: MessageButtonClicked) => void;
694
+ forwardWebrtcSignaling: (receiverId: string, dataType: number, jsonData: string) => Promise<WebrtcSignalingFwd>;
695
+ onwebrtcsignalingfwd: (event: WebrtcSignalingFwd) => void;
706
696
  oneventcreated: (clan_event_created: ApiCreateEventRequest) => void;
707
697
  oncoffeegiven: (give_coffee_event: ApiGiveCoffeeEvent) => void;
708
698
  oneventemoji: (event_emoji: EventEmoji) => void;
@@ -715,24 +705,6 @@ export interface Socket {
715
705
  onpermissionchanged: (permission_changed_event: PermissionChangedEvent) => void;
716
706
  onunmuteevent: (unmute_event: UnmuteEvent) => void;
717
707
  ontokensent: (token: ApiTokenSentEvent) => void;
718
- sendCallRequest(req: {
719
- type: string;
720
- sdp: string;
721
- }): Promise<void>;
722
- sendCallAccept(req: {
723
- type: string;
724
- sdp: string;
725
- }): Promise<void>;
726
- sendICECandidateInit(req: {
727
- candidate: string;
728
- sdpMid: string | undefined;
729
- sdpMLineIndex: number | undefined;
730
- usernameFragment: string | undefined;
731
- }): Promise<void>;
732
- startCall(localVideoRef: any, remoteVideoRef: any, grant_permissions: {
733
- video: boolean;
734
- audio: boolean;
735
- }): Promise<void>;
736
708
  }
737
709
  /** Reports an error received from a socket message. */
738
710
  export interface SocketError {
@@ -807,30 +779,9 @@ export declare class DefaultSocket implements Socket {
807
779
  onpermissionchanged(permission_changed_event: PermissionChangedEvent): void;
808
780
  onunmuteevent(unmute_event: UnmuteEvent): void;
809
781
  ontokensent(tokenSentEvent: ApiTokenSentEvent): void;
810
- handleMessageButtonClick(messageButtonClicked: MessageButtonClicked): void;
811
- onCallRequest(callRequest: CallRequest): void;
812
- onCallAccept(callAccept: CallAccept): void;
813
- onIceCandidateInit(iceCandidateInit: ICECandidateInit): void;
814
- send(message: ChannelJoin | ChannelLeave | ChannelMessageSend | ChannelMessageUpdate | CustomStatusEvent | ChannelMessageRemove | MessageTypingEvent | LastSeenMessageEvent | Rpc | StatusFollow | StatusUnfollow | StatusUpdate | Ping | CallRequest | CallAccept | ICECandidateInit, sendTimeout?: number): Promise<any>;
815
- getRTCPeerConnection(): RTCPeerConnection;
816
- startCall(localVideoRef: any, remoteVideoRef: any, grant_permissions: {
817
- video: boolean;
818
- audio: boolean;
819
- }): Promise<void>;
820
- sendCallRequest(req: {
821
- type: string;
822
- sdp?: string;
823
- }): Promise<void>;
824
- sendCallAccept(req: {
825
- type: string;
826
- sdp?: string;
827
- }): Promise<void>;
828
- sendICECandidateInit(req: {
829
- candidate: string;
830
- sdpMid?: string | undefined;
831
- sdpMLineIndex?: number | undefined;
832
- usernameFragment?: string | undefined;
833
- }): Promise<void>;
782
+ onmessagebuttonclicked(messageButtonClicked: MessageButtonClicked): void;
783
+ onwebrtcsignalingfwd(event: WebrtcSignalingFwd): void;
784
+ send(message: ChannelJoin | ChannelLeave | ChannelMessageSend | ChannelMessageUpdate | CustomStatusEvent | ChannelMessageRemove | MessageTypingEvent | LastSeenMessageEvent | Rpc | StatusFollow | StatusUnfollow | StatusUpdate | Ping | WebrtcSignalingFwd | MessageButtonClicked, sendTimeout?: number): Promise<any>;
834
785
  followUsers(userIds: string[]): Promise<Status>;
835
786
  joinClanChat(clan_id: string): Promise<ClanJoin>;
836
787
  joinChat(clan_id: string, channel_id: string, channel_type: number, is_public: boolean): Promise<Channel>;
@@ -849,6 +800,8 @@ export declare class DefaultSocket implements Socket {
849
800
  writeVoiceLeaved(id: string, clanId: string, voiceChannelId: string, voiceUserId: string): Promise<VoiceLeavedEvent>;
850
801
  writeCustomStatus(clan_id: string, status: string): Promise<CustomStatusEvent>;
851
802
  checkDuplicateName(name: string, condition_id: string, type: number): Promise<CheckNameExistedEvent>;
803
+ forwardWebrtcSignaling(receiver_id: string, data_type: number, json_data: string): Promise<WebrtcSignalingFwd>;
804
+ handleMessageButtonClick(message_id: string, channel_id: string, button_id: string, sender_id: string, user_id: string): Promise<MessageButtonClicked>;
852
805
  private pingPong;
853
806
  }
854
807
  export {};
@@ -37,7 +37,6 @@ export interface WebSocketAdapter {
37
37
  close(): void;
38
38
  connect(scheme: string, host: string, port: string, createStatus: boolean, token: string, platform: string, signal?: AbortSignal): void;
39
39
  send(message: any): void;
40
- getRTCPeerConnection(): RTCPeerConnection;
41
40
  }
42
41
  /**
43
42
  * SocketCloseHandler defines a lambda that handles WebSocket close events.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mezon-js",
3
3
 
4
- "version": "2.9.70",
4
+ "version": "2.9.71",
5
5
 
6
6
  "scripts": {
7
7
  "build": "npx tsc && npx rollup -c --bundleConfigAsCjs && node build.mjs"
package/socket.ts CHANGED
@@ -827,21 +827,10 @@ export interface MessageButtonClicked {
827
827
  user_id: string;
828
828
  }
829
829
 
830
- export interface CallRequest {
831
- type: string;
832
- sdp: string;
833
- }
834
-
835
- export interface CallAccept {
836
- type: string;
837
- sdp: string;
838
- }
839
-
840
- export interface ICECandidateInit {
841
- candidate: string;
842
- sdpMid: string | undefined;
843
- sdpMLineIndex: number | undefined;
844
- usernameFragment: string | undefined;
830
+ export interface WebrtcSignalingFwd {
831
+ receiverId: string;
832
+ dataType: number;
833
+ jsonData: string;
845
834
  }
846
835
 
847
836
  /** A socket connection to Mezon server. */
@@ -858,8 +847,6 @@ export interface Socket {
858
847
  signal?: AbortSignal
859
848
  ): Promise<Session>;
860
849
 
861
- getRTCPeerConnection(): RTCPeerConnection;
862
-
863
850
  /** Disconnect from the server. */
864
851
  disconnect(fireDisconnectEvent: boolean): void;
865
852
 
@@ -1113,15 +1100,17 @@ export interface Socket {
1113
1100
  type: number
1114
1101
  ): Promise<CheckNameExistedEvent>;
1115
1102
 
1116
- handleMessageButtonClick: (
1117
- message_button_clicked: MessageButtonClicked
1118
- ) => void;
1103
+ handleMessageButtonClick: (message_id: string,
1104
+ channel_id: string,
1105
+ button_id: string,
1106
+ sender_id: string,
1107
+ user_id: string) => Promise<MessageButtonClicked>;
1119
1108
 
1120
- onCallRequest: (call_request: CallRequest) => void;
1109
+ onmessagebuttonclicked: (event: MessageButtonClicked) => void;
1121
1110
 
1122
- onCallAccept: (call_accept: CallAccept) => void;
1111
+ forwardWebrtcSignaling: (receiverId: string, dataType: number, jsonData: string) => Promise<WebrtcSignalingFwd>;
1123
1112
 
1124
- onIceCandidateInit: (ice_candidate_init: ICECandidateInit) => void;
1113
+ onwebrtcsignalingfwd: (event: WebrtcSignalingFwd) => void;
1125
1114
 
1126
1115
  oneventcreated: (clan_event_created: ApiCreateEventRequest) => void;
1127
1116
 
@@ -1153,21 +1142,7 @@ export interface Socket {
1153
1142
 
1154
1143
  onunmuteevent: (unmute_event: UnmuteEvent) => void;
1155
1144
 
1156
- ontokensent: (token: ApiTokenSentEvent) => void;
1157
-
1158
- sendCallRequest(req: { type: string; sdp: string }): Promise<void>;
1159
- sendCallAccept(req: { type: string; sdp: string }): Promise<void>;
1160
- sendICECandidateInit(req: {
1161
- candidate: string;
1162
- sdpMid: string | undefined;
1163
- sdpMLineIndex: number | undefined;
1164
- usernameFragment: string | undefined;
1165
- }): Promise<void>;
1166
- startCall(
1167
- localVideoRef: any,
1168
- remoteVideoRef: any,
1169
- grant_permissions: { video: boolean; audio: boolean }
1170
- ): Promise<void>;
1145
+ ontokensent: (token: ApiTokenSentEvent) => void;
1171
1146
  }
1172
1147
 
1173
1148
  /** Reports an error received from a socket message. */
@@ -1420,53 +1395,9 @@ export class DefaultSocket implements Socket {
1420
1395
  } else if (message.token_sent_event) {
1421
1396
  this.ontokensent(<ApiTokenSentEvent>message.token_sent_event);
1422
1397
  } else if (message.message_button_clicked) {
1423
- this.handleMessageButtonClick(
1424
- <MessageButtonClicked>message.message_button_clicked
1425
- );
1426
- } else if (message.call_request) {
1427
- console.log("message.call_request", message.call_request);
1428
- await this.adapter.getRTCPeerConnection().setRemoteDescription(
1429
- new RTCSessionDescription({
1430
- type: "offer",
1431
- sdp: message.call_request.sdp,
1432
- })
1433
- );
1434
- const answer = await this.adapter
1435
- .getRTCPeerConnection()
1436
- .createAnswer();
1437
- await this.adapter.getRTCPeerConnection().setLocalDescription(answer);
1438
- // Check if WebSocket is initialized before sending message
1439
- await this.sendCallAccept({
1440
- sdp: answer.sdp,
1441
- type: "answer",
1442
- });
1443
-
1444
- this.onCallRequest(<CallRequest>message.call_request);
1445
- } else if (message.call_accept) {
1446
- console.log("message.call_accept", message.call_accept);
1447
- await this.adapter.getRTCPeerConnection().setRemoteDescription(
1448
- new RTCSessionDescription({
1449
- type: "answer",
1450
- sdp: message.call_accept.sdp,
1451
- })
1452
- );
1453
-
1454
- this.onCallAccept(<CallAccept>message.call_accept);
1455
- } else if (message.ice_candidate_init) {
1456
- console.log("message.ice_candidate_init", message.ice_candidate_init);
1457
- const rtcIceCandidate = new RTCIceCandidate({
1458
- candidate: message.ice_candidate_init.candidate,
1459
- sdpMid: message.ice_candidate_init.sdpMid || "audio",
1460
- sdpMLineIndex: message.ice_candidate_init.sdpMLineIndex || 0,
1461
- usernameFragment:
1462
- message.ice_candidate_init.usernameFragment || undefined,
1463
- });
1464
-
1465
- await this.adapter
1466
- .getRTCPeerConnection()
1467
- .addIceCandidate(rtcIceCandidate);
1468
-
1469
- this.onIceCandidateInit(<ICECandidateInit>message.ice_candidate_init);
1398
+ this.onmessagebuttonclicked( <MessageButtonClicked>message.message_button_clicked);
1399
+ } else if (message.webrtc_signaling_fwd) {
1400
+ this.onwebrtcsignalingfwd(<WebrtcSignalingFwd>message.webrtc_signaling_fwd);
1470
1401
  } else {
1471
1402
  if (this.verbose && window && window.console) {
1472
1403
  console.log("Unrecognized message received: %o", message);
@@ -1798,27 +1729,15 @@ export class DefaultSocket implements Socket {
1798
1729
  }
1799
1730
  }
1800
1731
 
1801
- handleMessageButtonClick(messageButtonClicked: MessageButtonClicked) {
1732
+ onmessagebuttonclicked(messageButtonClicked: MessageButtonClicked) {
1802
1733
  if (this.verbose && window && window.console) {
1803
1734
  console.log(messageButtonClicked);
1804
1735
  }
1805
1736
  }
1806
1737
 
1807
- onCallRequest(callRequest: CallRequest) {
1808
- if (this.verbose && window && window.console) {
1809
- console.log(callRequest);
1810
- }
1811
- }
1812
-
1813
- onCallAccept(callAccept: CallAccept) {
1738
+ onwebrtcsignalingfwd(event: WebrtcSignalingFwd) {
1814
1739
  if (this.verbose && window && window.console) {
1815
- console.log(callAccept);
1816
- }
1817
- }
1818
-
1819
- onIceCandidateInit(iceCandidateInit: ICECandidateInit) {
1820
- if (this.verbose && window && window.console) {
1821
- console.log(iceCandidateInit);
1740
+ console.log(event);
1822
1741
  }
1823
1742
  }
1824
1743
 
@@ -1837,9 +1756,8 @@ export class DefaultSocket implements Socket {
1837
1756
  | StatusUnfollow
1838
1757
  | StatusUpdate
1839
1758
  | Ping
1840
- | CallRequest
1841
- | CallAccept
1842
- | ICECandidateInit,
1759
+ | WebrtcSignalingFwd
1760
+ | MessageButtonClicked,
1843
1761
  sendTimeout = DefaultSocket.DefaultSendTimeoutMs
1844
1762
  ): Promise<any> {
1845
1763
  const untypedMessage = message as any;
@@ -1871,66 +1789,6 @@ export class DefaultSocket implements Socket {
1871
1789
  });
1872
1790
  }
1873
1791
 
1874
- getRTCPeerConnection(): RTCPeerConnection {
1875
- return this.adapter.getRTCPeerConnection();
1876
- }
1877
-
1878
- async startCall(
1879
- localVideoRef: any,
1880
- remoteVideoRef: any,
1881
- grant_permissions: { video: boolean; audio: boolean }
1882
- ): Promise<void> {
1883
- // setup peer connection
1884
- this.adapter.getRTCPeerConnection().onicecandidate = (event: any) => {
1885
- if (event && event.candidate) {
1886
- this.sendICECandidateInit({ candidate: event?.candidate });
1887
- }
1888
- };
1889
-
1890
- this.adapter.getRTCPeerConnection().ontrack = (event) => {
1891
- // Display remote stream in remote video element
1892
- if (remoteVideoRef) {
1893
- remoteVideoRef.srcObject = event.streams[0];
1894
- }
1895
- };
1896
- // Get user media
1897
- const stream = await navigator.mediaDevices.getUserMedia(grant_permissions);
1898
- if (localVideoRef) {
1899
- localVideoRef.srcObject = stream;
1900
- }
1901
- // Add tracks to PeerConnection
1902
- stream
1903
- .getTracks()
1904
- .forEach((track) =>
1905
- this.adapter.getRTCPeerConnection()?.addTrack(track, stream)
1906
- );
1907
-
1908
- // Create offer and send it to backend via WebSocket
1909
- const offer = await this.adapter.getRTCPeerConnection().createOffer();
1910
- await this.adapter.getRTCPeerConnection().setLocalDescription(offer);
1911
- await this.sendCallRequest({
1912
- sdp: offer?.sdp,
1913
- type: "offer",
1914
- });
1915
- }
1916
-
1917
- async sendCallRequest(req: { type: string; sdp?: string }): Promise<void> {
1918
- return await this.send({ call_request: req });
1919
- }
1920
-
1921
- async sendCallAccept(req: { type: string; sdp?: string }): Promise<void> {
1922
- return await this.send({ call_accept: req });
1923
- }
1924
-
1925
- async sendICECandidateInit(req: {
1926
- candidate: string;
1927
- sdpMid?: string | undefined;
1928
- sdpMLineIndex?: number | undefined;
1929
- usernameFragment?: string | undefined;
1930
- }): Promise<void> {
1931
- return await this.send({ ice_candidate_init: req });
1932
- }
1933
-
1934
1792
  async followUsers(userIds: string[]): Promise<Status> {
1935
1793
  const response = await this.send({ status_follow: { user_ids: userIds } });
1936
1794
  return response.status;
@@ -2233,6 +2091,25 @@ export class DefaultSocket implements Socket {
2233
2091
  return response.check_name_existed_event;
2234
2092
  }
2235
2093
 
2094
+ async forwardWebrtcSignaling(receiver_id: string, data_type: number, json_data: string): Promise<WebrtcSignalingFwd> {
2095
+ const response = await this.send({
2096
+ webrtc_signaling_fwd: { receiver_id: receiver_id, data_type: data_type, json_data: json_data },
2097
+ });
2098
+ return response.webrtc_signaling_fwd;
2099
+ }
2100
+
2101
+ async handleMessageButtonClick (
2102
+ message_id: string,
2103
+ channel_id: string,
2104
+ button_id: string,
2105
+ sender_id: string,
2106
+ user_id: string): Promise<MessageButtonClicked> {
2107
+ const response = await this.send({
2108
+ message_button_clicked: { message_id: message_id, channel_id: channel_id, button_id: button_id, sender_id: sender_id, user_id: user_id },
2109
+ });
2110
+ return response.webrtc_signaling_fwd;
2111
+ }
2112
+
2236
2113
  private async pingPong(): Promise<void> {
2237
2114
  if (!this.adapter.isOpen()) {
2238
2115
  return;
@@ -53,9 +53,6 @@ export interface WebSocketAdapter {
53
53
  signal?: AbortSignal
54
54
  ): void;
55
55
  send(message: any): void;
56
-
57
- // RTC Peer Connection
58
- getRTCPeerConnection(): RTCPeerConnection;
59
56
  }
60
57
 
61
58
  /**