mezon-js 2.9.69 → 2.9.70

Sign up to get free protection for your applications and to get access to all the features.
@@ -6510,7 +6510,9 @@ var WebSocketAdapterText = class {
6510
6510
  this._socket.onmessage = (evt) => {
6511
6511
  const message = JSON.parse(evt.data);
6512
6512
  if (message.party_data && message.party_data.data) {
6513
- message.party_data.data = new Uint8Array(decode2(message.party_data.data));
6513
+ message.party_data.data = new Uint8Array(
6514
+ decode2(message.party_data.data)
6515
+ );
6514
6516
  }
6515
6517
  value(message);
6516
6518
  };
@@ -6534,12 +6536,21 @@ var WebSocketAdapterText = class {
6534
6536
  this.close();
6535
6537
  });
6536
6538
  }
6537
- const url = `${scheme}${host}:${port}/ws?lang=en&status=${encodeURIComponent(createStatus.toString())}&token=${encodeURIComponent(token)}&paltform=${encodeURIComponent(platform)}`;
6539
+ const url = `${scheme}${host}:${port}/ws?lang=en&status=${encodeURIComponent(
6540
+ createStatus.toString()
6541
+ )}&token=${encodeURIComponent(token)}&paltform=${encodeURIComponent(
6542
+ platform
6543
+ )}`;
6538
6544
  this._socket = new WebSocket(url);
6545
+ this._pcRef = new RTCPeerConnection({
6546
+ iceServers: [{ urls: "stun:stun.l.google.com:19302" }]
6547
+ });
6539
6548
  }
6540
6549
  close() {
6541
- var _a;
6542
- (_a = this._socket) == null ? void 0 : _a.close();
6550
+ var _a, _b;
6551
+ (_a = this._pcRef) == null ? void 0 : _a.close();
6552
+ this._pcRef = void 0;
6553
+ (_b = this._socket) == null ? void 0 : _b.close();
6543
6554
  this._socket = void 0;
6544
6555
  }
6545
6556
  send(msg) {
@@ -6554,6 +6565,9 @@ var WebSocketAdapterText = class {
6554
6565
  }
6555
6566
  this._socket.send(JSON.stringify(msg));
6556
6567
  }
6568
+ getRTCPeerConnection() {
6569
+ return this._pcRef;
6570
+ }
6557
6571
  };
6558
6572
 
6559
6573
  // socket.ts
@@ -6582,14 +6596,22 @@ var _DefaultSocket = class _DefaultSocket {
6582
6596
  return Promise.resolve(session);
6583
6597
  }
6584
6598
  const scheme = this.useSSL ? "wss://" : "ws://";
6585
- this.adapter.connect(scheme, this.host, this.port, createStatus, session.token, platform, signal);
6599
+ this.adapter.connect(
6600
+ scheme,
6601
+ this.host,
6602
+ this.port,
6603
+ createStatus,
6604
+ session.token,
6605
+ platform,
6606
+ signal
6607
+ );
6586
6608
  this.adapter.onClose = (evt) => {
6587
6609
  this.ondisconnect(evt);
6588
6610
  };
6589
6611
  this.adapter.onError = (evt) => {
6590
6612
  this.onerror(evt);
6591
6613
  };
6592
- this.adapter.onMessage = (message) => {
6614
+ this.adapter.onMessage = (message) => __async(this, null, function* () {
6593
6615
  if (this.verbose && window && window.console) {
6594
6616
  console.log("Response: %o", JSON.stringify(message));
6595
6617
  }
@@ -6632,9 +6654,13 @@ var _DefaultSocket = class _DefaultSocket {
6632
6654
  } else if (message.last_seen_message_event) {
6633
6655
  this.onlastseenupdated(message.last_seen_message_event);
6634
6656
  } else if (message.status_presence_event) {
6635
- this.onstatuspresence(message.status_presence_event);
6657
+ this.onstatuspresence(
6658
+ message.status_presence_event
6659
+ );
6636
6660
  } else if (message.stream_presence_event) {
6637
- this.onstreampresence(message.stream_presence_event);
6661
+ this.onstreampresence(
6662
+ message.stream_presence_event
6663
+ );
6638
6664
  } else if (message.stream_data) {
6639
6665
  this.onstreamdata(message.stream_data);
6640
6666
  } else if (message.channel_message) {
@@ -6694,25 +6720,41 @@ var _DefaultSocket = class _DefaultSocket {
6694
6720
  };
6695
6721
  this.onchannelmessage(e);
6696
6722
  } else if (message.message_typing_event) {
6697
- this.onmessagetyping(message.message_typing_event);
6723
+ this.onmessagetyping(
6724
+ message.message_typing_event
6725
+ );
6698
6726
  } else if (message.message_reaction_event) {
6699
- this.onmessagereaction(message.message_reaction_event);
6727
+ this.onmessagereaction(
6728
+ message.message_reaction_event
6729
+ );
6700
6730
  } else if (message.channel_presence_event) {
6701
- this.onchannelpresence(message.channel_presence_event);
6731
+ this.onchannelpresence(
6732
+ message.channel_presence_event
6733
+ );
6702
6734
  } else if (message.last_pin_message_event) {
6703
- this.onpinmessage(message.last_pin_message_event);
6735
+ this.onpinmessage(
6736
+ message.last_pin_message_event
6737
+ );
6704
6738
  } else if (message.custom_status_event) {
6705
6739
  this.oncustomstatus(message.custom_status_event);
6706
6740
  } else if (message.user_channel_added_event) {
6707
- this.onuserchanneladded(message.user_channel_added_event);
6741
+ this.onuserchanneladded(
6742
+ message.user_channel_added_event
6743
+ );
6708
6744
  } else if (message.add_clan_user_event) {
6709
6745
  this.onuserclanadded(message.add_clan_user_event);
6710
6746
  } else if (message.user_profile_updated_event) {
6711
- this.onuserprofileupdate(message.user_profile_updated_event);
6747
+ this.onuserprofileupdate(
6748
+ message.user_profile_updated_event
6749
+ );
6712
6750
  } else if (message.user_channel_removed_event) {
6713
- this.onuserchannelremoved(message.user_channel_removed_event);
6751
+ this.onuserchannelremoved(
6752
+ message.user_channel_removed_event
6753
+ );
6714
6754
  } else if (message.user_clan_removed_event) {
6715
- this.onuserclanremoved(message.user_clan_removed_event);
6755
+ this.onuserclanremoved(
6756
+ message.user_clan_removed_event
6757
+ );
6716
6758
  } else if (message.clan_event_created) {
6717
6759
  this.oneventcreated(message.clan_event_created);
6718
6760
  } else if (message.give_coffee_event) {
@@ -6720,23 +6762,69 @@ var _DefaultSocket = class _DefaultSocket {
6720
6762
  } else if (message.role_assign_event) {
6721
6763
  this.onroleassign(message.role_assign_event);
6722
6764
  } else if (message.streaming_started_event) {
6723
- this.onstreamingchannelstarted(message.streaming_started_event);
6765
+ this.onstreamingchannelstarted(
6766
+ message.streaming_started_event
6767
+ );
6724
6768
  } else if (message.streaming_ended_event) {
6725
- this.onstreamingchannelended(message.streaming_ended_event);
6769
+ this.onstreamingchannelended(
6770
+ message.streaming_ended_event
6771
+ );
6726
6772
  } else if (message.streaming_joined_event) {
6727
- this.onstreamingchanneljoined(message.streaming_joined_event);
6773
+ this.onstreamingchanneljoined(
6774
+ message.streaming_joined_event
6775
+ );
6728
6776
  } else if (message.streaming_leaved_event) {
6729
- this.onstreamingchannelleaved(message.streaming_leaved_event);
6777
+ this.onstreamingchannelleaved(
6778
+ message.streaming_leaved_event
6779
+ );
6730
6780
  } else if (message.permission_set_event) {
6731
6781
  this.onpermissionset(message.permission_set_event);
6732
6782
  } else if (message.permission_changed_event) {
6733
- this.onpermissionchanged(message.permission_changed_event);
6783
+ this.onpermissionchanged(
6784
+ message.permission_changed_event
6785
+ );
6734
6786
  } else if (message.unmute_event) {
6735
6787
  this.onunmuteevent(message.unmute_event);
6736
6788
  } else if (message.token_sent_event) {
6737
6789
  this.ontokensent(message.token_sent_event);
6738
6790
  } else if (message.message_button_clicked) {
6739
- this.handleMessageButtonClick(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);
6740
6828
  } else {
6741
6829
  if (this.verbose && window && window.console) {
6742
6830
  console.log("Unrecognized message received: %o", message);
@@ -6757,7 +6845,7 @@ var _DefaultSocket = class _DefaultSocket {
6757
6845
  executor.resolve(message);
6758
6846
  }
6759
6847
  }
6760
- };
6848
+ });
6761
6849
  return new Promise((resolve, reject) => {
6762
6850
  this.adapter.onOpen = (evt) => {
6763
6851
  if (this.verbose && window && window.console) {
@@ -7019,6 +7107,21 @@ var _DefaultSocket = class _DefaultSocket {
7019
7107
  console.log(messageButtonClicked);
7020
7108
  }
7021
7109
  }
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) {
7121
+ if (this.verbose && window && window.console) {
7122
+ console.log(iceCandidateInit);
7123
+ }
7124
+ }
7022
7125
  send(message, sendTimeout = _DefaultSocket.DefaultSendTimeoutMs) {
7023
7126
  const untypedMessage = message;
7024
7127
  return new Promise((resolve, reject) => {
@@ -7026,9 +7129,13 @@ var _DefaultSocket = class _DefaultSocket {
7026
7129
  reject("Socket connection has not been established yet.");
7027
7130
  } else {
7028
7131
  if (untypedMessage.channel_message_send) {
7029
- untypedMessage.channel_message_send.content = JSON.stringify(untypedMessage.channel_message_send.content);
7132
+ untypedMessage.channel_message_send.content = JSON.stringify(
7133
+ untypedMessage.channel_message_send.content
7134
+ );
7030
7135
  } else if (untypedMessage.channel_message_update) {
7031
- untypedMessage.channel_message_update.content = JSON.stringify(untypedMessage.channel_message_update.content);
7136
+ untypedMessage.channel_message_update.content = JSON.stringify(
7137
+ untypedMessage.channel_message_update.content
7138
+ );
7032
7139
  }
7033
7140
  const cid = this.generatecid();
7034
7141
  this.cIds[cid] = { resolve, reject };
@@ -7040,6 +7147,54 @@ var _DefaultSocket = class _DefaultSocket {
7040
7147
  }
7041
7148
  });
7042
7149
  }
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
+ }
7043
7198
  followUsers(userIds) {
7044
7199
  return __async(this, null, function* () {
7045
7200
  const response = yield this.send({ status_follow: { user_ids: userIds } });
@@ -7058,49 +7213,50 @@ var _DefaultSocket = class _DefaultSocket {
7058
7213
  }
7059
7214
  joinChat(clan_id, channel_id, channel_type, is_public) {
7060
7215
  return __async(this, null, function* () {
7061
- const response = yield this.send(
7062
- {
7063
- channel_join: {
7064
- clan_id,
7065
- channel_id,
7066
- channel_type,
7067
- is_public
7068
- }
7216
+ const response = yield this.send({
7217
+ channel_join: {
7218
+ clan_id,
7219
+ channel_id,
7220
+ channel_type,
7221
+ is_public
7069
7222
  }
7070
- );
7223
+ });
7071
7224
  return response.channel;
7072
7225
  });
7073
7226
  }
7074
7227
  leaveChat(clan_id, channel_id, channel_type, is_public) {
7075
- return this.send({ channel_leave: { clan_id, channel_id, channel_type, is_public } });
7228
+ return this.send({
7229
+ channel_leave: {
7230
+ clan_id,
7231
+ channel_id,
7232
+ channel_type,
7233
+ is_public
7234
+ }
7235
+ });
7076
7236
  }
7077
7237
  removeChatMessage(clan_id, channel_id, mode, is_public, message_id) {
7078
7238
  return __async(this, null, function* () {
7079
- const response = yield this.send(
7080
- {
7081
- channel_message_remove: {
7082
- clan_id,
7083
- channel_id,
7084
- mode,
7085
- message_id,
7086
- is_public
7087
- }
7239
+ const response = yield this.send({
7240
+ channel_message_remove: {
7241
+ clan_id,
7242
+ channel_id,
7243
+ mode,
7244
+ message_id,
7245
+ is_public
7088
7246
  }
7089
- );
7247
+ });
7090
7248
  return response.channel_message_ack;
7091
7249
  });
7092
7250
  }
7093
7251
  rpc(id, payload, http_key) {
7094
7252
  return __async(this, null, function* () {
7095
- const response = yield this.send(
7096
- {
7097
- rpc: {
7098
- id,
7099
- payload,
7100
- http_key
7101
- }
7253
+ const response = yield this.send({
7254
+ rpc: {
7255
+ id,
7256
+ payload,
7257
+ http_key
7102
7258
  }
7103
- );
7259
+ });
7104
7260
  return response.rpc;
7105
7261
  });
7106
7262
  }
@@ -7109,7 +7265,19 @@ var _DefaultSocket = class _DefaultSocket {
7109
7265
  }
7110
7266
  updateChatMessage(clan_id, channel_id, mode, is_public, message_id, content, mentions, attachments, hideEditted) {
7111
7267
  return __async(this, null, function* () {
7112
- const response = yield this.send({ channel_message_update: { clan_id, channel_id, message_id, content, mentions, attachments, mode, is_public, hide_editted: hideEditted } });
7268
+ const response = yield this.send({
7269
+ channel_message_update: {
7270
+ clan_id,
7271
+ channel_id,
7272
+ message_id,
7273
+ content,
7274
+ mentions,
7275
+ attachments,
7276
+ mode,
7277
+ is_public,
7278
+ hide_editted: hideEditted
7279
+ }
7280
+ });
7113
7281
  return response.channel_message_ack;
7114
7282
  });
7115
7283
  }
@@ -7118,55 +7286,133 @@ var _DefaultSocket = class _DefaultSocket {
7118
7286
  }
7119
7287
  writeChatMessage(clan_id, channel_id, mode, is_public, content, mentions, attachments, references, anonymous_message, mention_everyone, avatar) {
7120
7288
  return __async(this, null, function* () {
7121
- const response = yield this.send({ channel_message_send: { clan_id, channel_id, mode, is_public, content, mentions, attachments, references, anonymous_message, mention_everyone, avatar } });
7289
+ const response = yield this.send({
7290
+ channel_message_send: {
7291
+ clan_id,
7292
+ channel_id,
7293
+ mode,
7294
+ is_public,
7295
+ content,
7296
+ mentions,
7297
+ attachments,
7298
+ references,
7299
+ anonymous_message,
7300
+ mention_everyone,
7301
+ avatar
7302
+ }
7303
+ });
7122
7304
  return response.channel_message_ack;
7123
7305
  });
7124
7306
  }
7125
7307
  writeMessageReaction(id, clan_id, channel_id, mode, is_public, message_id, emoji_id, emoji, count, message_sender_id, action_delete) {
7126
7308
  return __async(this, null, function* () {
7127
- const response = yield this.send({ message_reaction_event: { id, clan_id, channel_id, mode, is_public, message_id, emoji_id, emoji, count, message_sender_id, action: action_delete } });
7309
+ const response = yield this.send({
7310
+ message_reaction_event: {
7311
+ id,
7312
+ clan_id,
7313
+ channel_id,
7314
+ mode,
7315
+ is_public,
7316
+ message_id,
7317
+ emoji_id,
7318
+ emoji,
7319
+ count,
7320
+ message_sender_id,
7321
+ action: action_delete
7322
+ }
7323
+ });
7128
7324
  return response.message_reaction_event;
7129
7325
  });
7130
7326
  }
7131
7327
  writeMessageTyping(clan_id, channel_id, mode, is_public) {
7132
7328
  return __async(this, null, function* () {
7133
- const response = yield this.send({ message_typing_event: { clan_id, channel_id, mode, is_public } });
7329
+ const response = yield this.send({
7330
+ message_typing_event: {
7331
+ clan_id,
7332
+ channel_id,
7333
+ mode,
7334
+ is_public
7335
+ }
7336
+ });
7134
7337
  return response.message_typing_event;
7135
7338
  });
7136
7339
  }
7137
7340
  writeLastSeenMessage(clan_id, channel_id, mode, message_id, timestamp_seconds) {
7138
7341
  return __async(this, null, function* () {
7139
- const response = yield this.send({ last_seen_message_event: { clan_id, channel_id, mode, message_id, timestamp_seconds } });
7342
+ const response = yield this.send({
7343
+ last_seen_message_event: {
7344
+ clan_id,
7345
+ channel_id,
7346
+ mode,
7347
+ message_id,
7348
+ timestamp_seconds
7349
+ }
7350
+ });
7140
7351
  return response.last_seen_message_event;
7141
7352
  });
7142
7353
  }
7143
7354
  writeLastPinMessage(clan_id, channel_id, mode, is_public, message_id, timestamp_seconds, operation) {
7144
7355
  return __async(this, null, function* () {
7145
- const response = yield this.send({ last_pin_message_event: { clan_id, channel_id, mode, is_public, message_id, timestamp_seconds, operation } });
7356
+ const response = yield this.send({
7357
+ last_pin_message_event: {
7358
+ clan_id,
7359
+ channel_id,
7360
+ mode,
7361
+ is_public,
7362
+ message_id,
7363
+ timestamp_seconds,
7364
+ operation
7365
+ }
7366
+ });
7146
7367
  return response.last_pin_message_event;
7147
7368
  });
7148
7369
  }
7149
7370
  writeVoiceJoined(id, clanId, clanName, voiceChannelId, voiceChannelLabel, participant, lastScreenshot) {
7150
7371
  return __async(this, null, function* () {
7151
- const response = yield this.send({ voice_joined_event: { clan_id: clanId, clan_name: clanName, id, participant, voice_channel_id: voiceChannelId, voice_channel_label: voiceChannelLabel, last_screenshot: lastScreenshot } });
7372
+ const response = yield this.send({
7373
+ voice_joined_event: {
7374
+ clan_id: clanId,
7375
+ clan_name: clanName,
7376
+ id,
7377
+ participant,
7378
+ voice_channel_id: voiceChannelId,
7379
+ voice_channel_label: voiceChannelLabel,
7380
+ last_screenshot: lastScreenshot
7381
+ }
7382
+ });
7152
7383
  return response.voice_joined_event;
7153
7384
  });
7154
7385
  }
7155
7386
  writeVoiceLeaved(id, clanId, voiceChannelId, voiceUserId) {
7156
7387
  return __async(this, null, function* () {
7157
- const response = yield this.send({ voice_leaved_event: { id, clan_id: clanId, voice_channel_id: voiceChannelId, voice_user_id: voiceUserId } });
7388
+ const response = yield this.send({
7389
+ voice_leaved_event: {
7390
+ id,
7391
+ clan_id: clanId,
7392
+ voice_channel_id: voiceChannelId,
7393
+ voice_user_id: voiceUserId
7394
+ }
7395
+ });
7158
7396
  return response.voice_leaved_event;
7159
7397
  });
7160
7398
  }
7161
7399
  writeCustomStatus(clan_id, status) {
7162
7400
  return __async(this, null, function* () {
7163
- const response = yield this.send({ custom_status_event: { clan_id, status } });
7401
+ const response = yield this.send({
7402
+ custom_status_event: { clan_id, status }
7403
+ });
7164
7404
  return response.custom_status_event;
7165
7405
  });
7166
7406
  }
7167
7407
  checkDuplicateName(name, condition_id, type) {
7168
7408
  return __async(this, null, function* () {
7169
- const response = yield this.send({ check_name_existed_event: { name, condition_id, type } });
7409
+ const response = yield this.send({
7410
+ check_name_existed_event: {
7411
+ name,
7412
+ condition_id,
7413
+ type
7414
+ }
7415
+ });
7170
7416
  return response.check_name_existed_event;
7171
7417
  });
7172
7418
  }
package/dist/socket.d.ts CHANGED
@@ -584,12 +584,27 @@ 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;
600
+ }
587
601
  /** A socket connection to Mezon server. */
588
602
  export interface Socket {
589
603
  /** Connection is Open */
590
604
  isOpen(): boolean;
591
605
  /** Connect to the server. */
592
606
  connect(session: Session, createStatus: boolean, platform: string, connectTimeoutMs?: number, signal?: AbortSignal): Promise<Session>;
607
+ getRTCPeerConnection(): RTCPeerConnection;
593
608
  /** Disconnect from the server. */
594
609
  disconnect(fireDisconnectEvent: boolean): void;
595
610
  /** Subscribe to one or more users for their status updates. */
@@ -685,6 +700,9 @@ export interface Socket {
685
700
  getHeartbeatTimeoutMs(): number;
686
701
  checkDuplicateName(name: string, condition_id: string, type: number): Promise<CheckNameExistedEvent>;
687
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;
688
706
  oneventcreated: (clan_event_created: ApiCreateEventRequest) => void;
689
707
  oncoffeegiven: (give_coffee_event: ApiGiveCoffeeEvent) => void;
690
708
  oneventemoji: (event_emoji: EventEmoji) => void;
@@ -697,6 +715,24 @@ export interface Socket {
697
715
  onpermissionchanged: (permission_changed_event: PermissionChangedEvent) => void;
698
716
  onunmuteevent: (unmute_event: UnmuteEvent) => void;
699
717
  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>;
700
736
  }
701
737
  /** Reports an error received from a socket message. */
702
738
  export interface SocketError {
@@ -772,7 +808,29 @@ export declare class DefaultSocket implements Socket {
772
808
  onunmuteevent(unmute_event: UnmuteEvent): void;
773
809
  ontokensent(tokenSentEvent: ApiTokenSentEvent): void;
774
810
  handleMessageButtonClick(messageButtonClicked: MessageButtonClicked): void;
775
- send(message: ChannelJoin | ChannelLeave | ChannelMessageSend | ChannelMessageUpdate | CustomStatusEvent | ChannelMessageRemove | MessageTypingEvent | LastSeenMessageEvent | Rpc | StatusFollow | StatusUnfollow | StatusUpdate | Ping, sendTimeout?: number): Promise<any>;
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>;
776
834
  followUsers(userIds: string[]): Promise<Status>;
777
835
  joinClanChat(clan_id: string): Promise<ClanJoin>;
778
836
  joinChat(clan_id: string, channel_id: string, channel_type: number, is_public: boolean): Promise<Channel>;
@@ -37,6 +37,7 @@ 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;
40
41
  }
41
42
  /**
42
43
  * SocketCloseHandler defines a lambda that handles WebSocket close events.
@@ -63,11 +64,18 @@ export interface SocketMessageHandler {
63
64
  export interface SocketOpenHandler {
64
65
  (this: WebSocket, evt: Event): void;
65
66
  }
67
+ export interface RTCPeerOntrackHandler {
68
+ (this: RTCPeerConnection, ev: RTCTrackEvent): any | null;
69
+ }
70
+ export interface RTCPeerOnicecandidateHandler {
71
+ (this: RTCPeerConnection, ev: RTCPeerConnectionIceEvent): any;
72
+ }
66
73
  /**
67
74
  * A text-based socket adapter that accepts and transmits payloads over UTF-8.
68
75
  */
69
76
  export declare class WebSocketAdapterText implements WebSocketAdapter {
70
77
  private _socket?;
78
+ private _pcRef?;
71
79
  get onClose(): SocketCloseHandler | null;
72
80
  set onClose(value: SocketCloseHandler | null);
73
81
  get onError(): SocketErrorHandler | null;
@@ -80,4 +88,5 @@ export declare class WebSocketAdapterText implements WebSocketAdapter {
80
88
  connect(scheme: string, host: string, port: string, createStatus: boolean, token: string, platform: string, signal?: AbortSignal): void;
81
89
  close(): void;
82
90
  send(msg: any): void;
91
+ getRTCPeerConnection(): RTCPeerConnection;
83
92
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mezon-js",
3
3
 
4
- "version": "2.9.69",
4
+ "version": "2.9.70",
5
5
 
6
6
  "scripts": {
7
7
  "build": "npx tsc && npx rollup -c --bundleConfigAsCjs && node build.mjs"