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.
@@ -6539,7 +6539,9 @@ var WebSocketAdapterText = class {
6539
6539
  this._socket.onmessage = (evt) => {
6540
6540
  const message = JSON.parse(evt.data);
6541
6541
  if (message.party_data && message.party_data.data) {
6542
- message.party_data.data = new Uint8Array(decode2(message.party_data.data));
6542
+ message.party_data.data = new Uint8Array(
6543
+ decode2(message.party_data.data)
6544
+ );
6543
6545
  }
6544
6546
  value(message);
6545
6547
  };
@@ -6563,12 +6565,21 @@ var WebSocketAdapterText = class {
6563
6565
  this.close();
6564
6566
  });
6565
6567
  }
6566
- const url = `${scheme}${host}:${port}/ws?lang=en&status=${encodeURIComponent(createStatus.toString())}&token=${encodeURIComponent(token)}&paltform=${encodeURIComponent(platform)}`;
6568
+ const url = `${scheme}${host}:${port}/ws?lang=en&status=${encodeURIComponent(
6569
+ createStatus.toString()
6570
+ )}&token=${encodeURIComponent(token)}&paltform=${encodeURIComponent(
6571
+ platform
6572
+ )}`;
6567
6573
  this._socket = new WebSocket(url);
6574
+ this._pcRef = new RTCPeerConnection({
6575
+ iceServers: [{ urls: "stun:stun.l.google.com:19302" }]
6576
+ });
6568
6577
  }
6569
6578
  close() {
6570
- var _a;
6571
- (_a = this._socket) == null ? void 0 : _a.close();
6579
+ var _a, _b;
6580
+ (_a = this._pcRef) == null ? void 0 : _a.close();
6581
+ this._pcRef = void 0;
6582
+ (_b = this._socket) == null ? void 0 : _b.close();
6572
6583
  this._socket = void 0;
6573
6584
  }
6574
6585
  send(msg) {
@@ -6583,6 +6594,9 @@ var WebSocketAdapterText = class {
6583
6594
  }
6584
6595
  this._socket.send(JSON.stringify(msg));
6585
6596
  }
6597
+ getRTCPeerConnection() {
6598
+ return this._pcRef;
6599
+ }
6586
6600
  };
6587
6601
 
6588
6602
  // socket.ts
@@ -6611,14 +6625,22 @@ var _DefaultSocket = class _DefaultSocket {
6611
6625
  return Promise.resolve(session);
6612
6626
  }
6613
6627
  const scheme = this.useSSL ? "wss://" : "ws://";
6614
- this.adapter.connect(scheme, this.host, this.port, createStatus, session.token, platform, signal);
6628
+ this.adapter.connect(
6629
+ scheme,
6630
+ this.host,
6631
+ this.port,
6632
+ createStatus,
6633
+ session.token,
6634
+ platform,
6635
+ signal
6636
+ );
6615
6637
  this.adapter.onClose = (evt) => {
6616
6638
  this.ondisconnect(evt);
6617
6639
  };
6618
6640
  this.adapter.onError = (evt) => {
6619
6641
  this.onerror(evt);
6620
6642
  };
6621
- this.adapter.onMessage = (message) => {
6643
+ this.adapter.onMessage = (message) => __async(this, null, function* () {
6622
6644
  if (this.verbose && window && window.console) {
6623
6645
  console.log("Response: %o", JSON.stringify(message));
6624
6646
  }
@@ -6661,9 +6683,13 @@ var _DefaultSocket = class _DefaultSocket {
6661
6683
  } else if (message.last_seen_message_event) {
6662
6684
  this.onlastseenupdated(message.last_seen_message_event);
6663
6685
  } else if (message.status_presence_event) {
6664
- this.onstatuspresence(message.status_presence_event);
6686
+ this.onstatuspresence(
6687
+ message.status_presence_event
6688
+ );
6665
6689
  } else if (message.stream_presence_event) {
6666
- this.onstreampresence(message.stream_presence_event);
6690
+ this.onstreampresence(
6691
+ message.stream_presence_event
6692
+ );
6667
6693
  } else if (message.stream_data) {
6668
6694
  this.onstreamdata(message.stream_data);
6669
6695
  } else if (message.channel_message) {
@@ -6723,25 +6749,41 @@ var _DefaultSocket = class _DefaultSocket {
6723
6749
  };
6724
6750
  this.onchannelmessage(e);
6725
6751
  } else if (message.message_typing_event) {
6726
- this.onmessagetyping(message.message_typing_event);
6752
+ this.onmessagetyping(
6753
+ message.message_typing_event
6754
+ );
6727
6755
  } else if (message.message_reaction_event) {
6728
- this.onmessagereaction(message.message_reaction_event);
6756
+ this.onmessagereaction(
6757
+ message.message_reaction_event
6758
+ );
6729
6759
  } else if (message.channel_presence_event) {
6730
- this.onchannelpresence(message.channel_presence_event);
6760
+ this.onchannelpresence(
6761
+ message.channel_presence_event
6762
+ );
6731
6763
  } else if (message.last_pin_message_event) {
6732
- this.onpinmessage(message.last_pin_message_event);
6764
+ this.onpinmessage(
6765
+ message.last_pin_message_event
6766
+ );
6733
6767
  } else if (message.custom_status_event) {
6734
6768
  this.oncustomstatus(message.custom_status_event);
6735
6769
  } else if (message.user_channel_added_event) {
6736
- this.onuserchanneladded(message.user_channel_added_event);
6770
+ this.onuserchanneladded(
6771
+ message.user_channel_added_event
6772
+ );
6737
6773
  } else if (message.add_clan_user_event) {
6738
6774
  this.onuserclanadded(message.add_clan_user_event);
6739
6775
  } else if (message.user_profile_updated_event) {
6740
- this.onuserprofileupdate(message.user_profile_updated_event);
6776
+ this.onuserprofileupdate(
6777
+ message.user_profile_updated_event
6778
+ );
6741
6779
  } else if (message.user_channel_removed_event) {
6742
- this.onuserchannelremoved(message.user_channel_removed_event);
6780
+ this.onuserchannelremoved(
6781
+ message.user_channel_removed_event
6782
+ );
6743
6783
  } else if (message.user_clan_removed_event) {
6744
- this.onuserclanremoved(message.user_clan_removed_event);
6784
+ this.onuserclanremoved(
6785
+ message.user_clan_removed_event
6786
+ );
6745
6787
  } else if (message.clan_event_created) {
6746
6788
  this.oneventcreated(message.clan_event_created);
6747
6789
  } else if (message.give_coffee_event) {
@@ -6749,23 +6791,69 @@ var _DefaultSocket = class _DefaultSocket {
6749
6791
  } else if (message.role_assign_event) {
6750
6792
  this.onroleassign(message.role_assign_event);
6751
6793
  } else if (message.streaming_started_event) {
6752
- this.onstreamingchannelstarted(message.streaming_started_event);
6794
+ this.onstreamingchannelstarted(
6795
+ message.streaming_started_event
6796
+ );
6753
6797
  } else if (message.streaming_ended_event) {
6754
- this.onstreamingchannelended(message.streaming_ended_event);
6798
+ this.onstreamingchannelended(
6799
+ message.streaming_ended_event
6800
+ );
6755
6801
  } else if (message.streaming_joined_event) {
6756
- this.onstreamingchanneljoined(message.streaming_joined_event);
6802
+ this.onstreamingchanneljoined(
6803
+ message.streaming_joined_event
6804
+ );
6757
6805
  } else if (message.streaming_leaved_event) {
6758
- this.onstreamingchannelleaved(message.streaming_leaved_event);
6806
+ this.onstreamingchannelleaved(
6807
+ message.streaming_leaved_event
6808
+ );
6759
6809
  } else if (message.permission_set_event) {
6760
6810
  this.onpermissionset(message.permission_set_event);
6761
6811
  } else if (message.permission_changed_event) {
6762
- this.onpermissionchanged(message.permission_changed_event);
6812
+ this.onpermissionchanged(
6813
+ message.permission_changed_event
6814
+ );
6763
6815
  } else if (message.unmute_event) {
6764
6816
  this.onunmuteevent(message.unmute_event);
6765
6817
  } else if (message.token_sent_event) {
6766
6818
  this.ontokensent(message.token_sent_event);
6767
6819
  } else if (message.message_button_clicked) {
6768
- this.handleMessageButtonClick(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);
6769
6857
  } else {
6770
6858
  if (this.verbose && window && window.console) {
6771
6859
  console.log("Unrecognized message received: %o", message);
@@ -6786,7 +6874,7 @@ var _DefaultSocket = class _DefaultSocket {
6786
6874
  executor.resolve(message);
6787
6875
  }
6788
6876
  }
6789
- };
6877
+ });
6790
6878
  return new Promise((resolve, reject) => {
6791
6879
  this.adapter.onOpen = (evt) => {
6792
6880
  if (this.verbose && window && window.console) {
@@ -7048,6 +7136,21 @@ var _DefaultSocket = class _DefaultSocket {
7048
7136
  console.log(messageButtonClicked);
7049
7137
  }
7050
7138
  }
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) {
7150
+ if (this.verbose && window && window.console) {
7151
+ console.log(iceCandidateInit);
7152
+ }
7153
+ }
7051
7154
  send(message, sendTimeout = _DefaultSocket.DefaultSendTimeoutMs) {
7052
7155
  const untypedMessage = message;
7053
7156
  return new Promise((resolve, reject) => {
@@ -7055,9 +7158,13 @@ var _DefaultSocket = class _DefaultSocket {
7055
7158
  reject("Socket connection has not been established yet.");
7056
7159
  } else {
7057
7160
  if (untypedMessage.channel_message_send) {
7058
- untypedMessage.channel_message_send.content = JSON.stringify(untypedMessage.channel_message_send.content);
7161
+ untypedMessage.channel_message_send.content = JSON.stringify(
7162
+ untypedMessage.channel_message_send.content
7163
+ );
7059
7164
  } else if (untypedMessage.channel_message_update) {
7060
- untypedMessage.channel_message_update.content = JSON.stringify(untypedMessage.channel_message_update.content);
7165
+ untypedMessage.channel_message_update.content = JSON.stringify(
7166
+ untypedMessage.channel_message_update.content
7167
+ );
7061
7168
  }
7062
7169
  const cid = this.generatecid();
7063
7170
  this.cIds[cid] = { resolve, reject };
@@ -7069,6 +7176,54 @@ var _DefaultSocket = class _DefaultSocket {
7069
7176
  }
7070
7177
  });
7071
7178
  }
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
+ }
7072
7227
  followUsers(userIds) {
7073
7228
  return __async(this, null, function* () {
7074
7229
  const response = yield this.send({ status_follow: { user_ids: userIds } });
@@ -7087,49 +7242,50 @@ var _DefaultSocket = class _DefaultSocket {
7087
7242
  }
7088
7243
  joinChat(clan_id, channel_id, channel_type, is_public) {
7089
7244
  return __async(this, null, function* () {
7090
- const response = yield this.send(
7091
- {
7092
- channel_join: {
7093
- clan_id,
7094
- channel_id,
7095
- channel_type,
7096
- is_public
7097
- }
7245
+ const response = yield this.send({
7246
+ channel_join: {
7247
+ clan_id,
7248
+ channel_id,
7249
+ channel_type,
7250
+ is_public
7098
7251
  }
7099
- );
7252
+ });
7100
7253
  return response.channel;
7101
7254
  });
7102
7255
  }
7103
7256
  leaveChat(clan_id, channel_id, channel_type, is_public) {
7104
- return this.send({ channel_leave: { clan_id, channel_id, channel_type, is_public } });
7257
+ return this.send({
7258
+ channel_leave: {
7259
+ clan_id,
7260
+ channel_id,
7261
+ channel_type,
7262
+ is_public
7263
+ }
7264
+ });
7105
7265
  }
7106
7266
  removeChatMessage(clan_id, channel_id, mode, is_public, message_id) {
7107
7267
  return __async(this, null, function* () {
7108
- const response = yield this.send(
7109
- {
7110
- channel_message_remove: {
7111
- clan_id,
7112
- channel_id,
7113
- mode,
7114
- message_id,
7115
- is_public
7116
- }
7268
+ const response = yield this.send({
7269
+ channel_message_remove: {
7270
+ clan_id,
7271
+ channel_id,
7272
+ mode,
7273
+ message_id,
7274
+ is_public
7117
7275
  }
7118
- );
7276
+ });
7119
7277
  return response.channel_message_ack;
7120
7278
  });
7121
7279
  }
7122
7280
  rpc(id, payload, http_key) {
7123
7281
  return __async(this, null, function* () {
7124
- const response = yield this.send(
7125
- {
7126
- rpc: {
7127
- id,
7128
- payload,
7129
- http_key
7130
- }
7282
+ const response = yield this.send({
7283
+ rpc: {
7284
+ id,
7285
+ payload,
7286
+ http_key
7131
7287
  }
7132
- );
7288
+ });
7133
7289
  return response.rpc;
7134
7290
  });
7135
7291
  }
@@ -7138,7 +7294,19 @@ var _DefaultSocket = class _DefaultSocket {
7138
7294
  }
7139
7295
  updateChatMessage(clan_id, channel_id, mode, is_public, message_id, content, mentions, attachments, hideEditted) {
7140
7296
  return __async(this, null, function* () {
7141
- const response = yield this.send({ channel_message_update: { clan_id, channel_id, message_id, content, mentions, attachments, mode, is_public, hide_editted: hideEditted } });
7297
+ const response = yield this.send({
7298
+ channel_message_update: {
7299
+ clan_id,
7300
+ channel_id,
7301
+ message_id,
7302
+ content,
7303
+ mentions,
7304
+ attachments,
7305
+ mode,
7306
+ is_public,
7307
+ hide_editted: hideEditted
7308
+ }
7309
+ });
7142
7310
  return response.channel_message_ack;
7143
7311
  });
7144
7312
  }
@@ -7147,55 +7315,133 @@ var _DefaultSocket = class _DefaultSocket {
7147
7315
  }
7148
7316
  writeChatMessage(clan_id, channel_id, mode, is_public, content, mentions, attachments, references, anonymous_message, mention_everyone, avatar) {
7149
7317
  return __async(this, null, function* () {
7150
- const response = yield this.send({ channel_message_send: { clan_id, channel_id, mode, is_public, content, mentions, attachments, references, anonymous_message, mention_everyone, avatar } });
7318
+ const response = yield this.send({
7319
+ channel_message_send: {
7320
+ clan_id,
7321
+ channel_id,
7322
+ mode,
7323
+ is_public,
7324
+ content,
7325
+ mentions,
7326
+ attachments,
7327
+ references,
7328
+ anonymous_message,
7329
+ mention_everyone,
7330
+ avatar
7331
+ }
7332
+ });
7151
7333
  return response.channel_message_ack;
7152
7334
  });
7153
7335
  }
7154
7336
  writeMessageReaction(id, clan_id, channel_id, mode, is_public, message_id, emoji_id, emoji, count, message_sender_id, action_delete) {
7155
7337
  return __async(this, null, function* () {
7156
- 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 } });
7338
+ const response = yield this.send({
7339
+ message_reaction_event: {
7340
+ id,
7341
+ clan_id,
7342
+ channel_id,
7343
+ mode,
7344
+ is_public,
7345
+ message_id,
7346
+ emoji_id,
7347
+ emoji,
7348
+ count,
7349
+ message_sender_id,
7350
+ action: action_delete
7351
+ }
7352
+ });
7157
7353
  return response.message_reaction_event;
7158
7354
  });
7159
7355
  }
7160
7356
  writeMessageTyping(clan_id, channel_id, mode, is_public) {
7161
7357
  return __async(this, null, function* () {
7162
- const response = yield this.send({ message_typing_event: { clan_id, channel_id, mode, is_public } });
7358
+ const response = yield this.send({
7359
+ message_typing_event: {
7360
+ clan_id,
7361
+ channel_id,
7362
+ mode,
7363
+ is_public
7364
+ }
7365
+ });
7163
7366
  return response.message_typing_event;
7164
7367
  });
7165
7368
  }
7166
7369
  writeLastSeenMessage(clan_id, channel_id, mode, message_id, timestamp_seconds) {
7167
7370
  return __async(this, null, function* () {
7168
- const response = yield this.send({ last_seen_message_event: { clan_id, channel_id, mode, message_id, timestamp_seconds } });
7371
+ const response = yield this.send({
7372
+ last_seen_message_event: {
7373
+ clan_id,
7374
+ channel_id,
7375
+ mode,
7376
+ message_id,
7377
+ timestamp_seconds
7378
+ }
7379
+ });
7169
7380
  return response.last_seen_message_event;
7170
7381
  });
7171
7382
  }
7172
7383
  writeLastPinMessage(clan_id, channel_id, mode, is_public, message_id, timestamp_seconds, operation) {
7173
7384
  return __async(this, null, function* () {
7174
- const response = yield this.send({ last_pin_message_event: { clan_id, channel_id, mode, is_public, message_id, timestamp_seconds, operation } });
7385
+ const response = yield this.send({
7386
+ last_pin_message_event: {
7387
+ clan_id,
7388
+ channel_id,
7389
+ mode,
7390
+ is_public,
7391
+ message_id,
7392
+ timestamp_seconds,
7393
+ operation
7394
+ }
7395
+ });
7175
7396
  return response.last_pin_message_event;
7176
7397
  });
7177
7398
  }
7178
7399
  writeVoiceJoined(id, clanId, clanName, voiceChannelId, voiceChannelLabel, participant, lastScreenshot) {
7179
7400
  return __async(this, null, function* () {
7180
- 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 } });
7401
+ const response = yield this.send({
7402
+ voice_joined_event: {
7403
+ clan_id: clanId,
7404
+ clan_name: clanName,
7405
+ id,
7406
+ participant,
7407
+ voice_channel_id: voiceChannelId,
7408
+ voice_channel_label: voiceChannelLabel,
7409
+ last_screenshot: lastScreenshot
7410
+ }
7411
+ });
7181
7412
  return response.voice_joined_event;
7182
7413
  });
7183
7414
  }
7184
7415
  writeVoiceLeaved(id, clanId, voiceChannelId, voiceUserId) {
7185
7416
  return __async(this, null, function* () {
7186
- const response = yield this.send({ voice_leaved_event: { id, clan_id: clanId, voice_channel_id: voiceChannelId, voice_user_id: voiceUserId } });
7417
+ const response = yield this.send({
7418
+ voice_leaved_event: {
7419
+ id,
7420
+ clan_id: clanId,
7421
+ voice_channel_id: voiceChannelId,
7422
+ voice_user_id: voiceUserId
7423
+ }
7424
+ });
7187
7425
  return response.voice_leaved_event;
7188
7426
  });
7189
7427
  }
7190
7428
  writeCustomStatus(clan_id, status) {
7191
7429
  return __async(this, null, function* () {
7192
- const response = yield this.send({ custom_status_event: { clan_id, status } });
7430
+ const response = yield this.send({
7431
+ custom_status_event: { clan_id, status }
7432
+ });
7193
7433
  return response.custom_status_event;
7194
7434
  });
7195
7435
  }
7196
7436
  checkDuplicateName(name, condition_id, type) {
7197
7437
  return __async(this, null, function* () {
7198
- const response = yield this.send({ check_name_existed_event: { name, condition_id, type } });
7438
+ const response = yield this.send({
7439
+ check_name_existed_event: {
7440
+ name,
7441
+ condition_id,
7442
+ type
7443
+ }
7444
+ });
7199
7445
  return response.check_name_existed_event;
7200
7446
  });
7201
7447
  }