mezon-js 2.9.69 → 2.9.71
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/dist/mezon-js.cjs.js +234 -64
- package/dist/mezon-js.esm.mjs +234 -64
- package/dist/socket.d.ts +14 -3
- package/dist/web_socket_adapter.d.ts +8 -0
- package/package.json +1 -1
- package/socket.ts +627 -227
- package/web_socket_adapter.ts +141 -102
package/dist/mezon-js.cjs.js
CHANGED
@@ -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(
|
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(
|
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.
|
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(
|
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(
|
6686
|
+
this.onstatuspresence(
|
6687
|
+
message.status_presence_event
|
6688
|
+
);
|
6665
6689
|
} else if (message.stream_presence_event) {
|
6666
|
-
this.onstreampresence(
|
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(
|
6752
|
+
this.onmessagetyping(
|
6753
|
+
message.message_typing_event
|
6754
|
+
);
|
6727
6755
|
} else if (message.message_reaction_event) {
|
6728
|
-
this.onmessagereaction(
|
6756
|
+
this.onmessagereaction(
|
6757
|
+
message.message_reaction_event
|
6758
|
+
);
|
6729
6759
|
} else if (message.channel_presence_event) {
|
6730
|
-
this.onchannelpresence(
|
6760
|
+
this.onchannelpresence(
|
6761
|
+
message.channel_presence_event
|
6762
|
+
);
|
6731
6763
|
} else if (message.last_pin_message_event) {
|
6732
|
-
this.onpinmessage(
|
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(
|
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(
|
6776
|
+
this.onuserprofileupdate(
|
6777
|
+
message.user_profile_updated_event
|
6778
|
+
);
|
6741
6779
|
} else if (message.user_channel_removed_event) {
|
6742
|
-
this.onuserchannelremoved(
|
6780
|
+
this.onuserchannelremoved(
|
6781
|
+
message.user_channel_removed_event
|
6782
|
+
);
|
6743
6783
|
} else if (message.user_clan_removed_event) {
|
6744
|
-
this.onuserclanremoved(
|
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,35 @@ 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(
|
6794
|
+
this.onstreamingchannelstarted(
|
6795
|
+
message.streaming_started_event
|
6796
|
+
);
|
6753
6797
|
} else if (message.streaming_ended_event) {
|
6754
|
-
this.onstreamingchannelended(
|
6798
|
+
this.onstreamingchannelended(
|
6799
|
+
message.streaming_ended_event
|
6800
|
+
);
|
6755
6801
|
} else if (message.streaming_joined_event) {
|
6756
|
-
this.onstreamingchanneljoined(
|
6802
|
+
this.onstreamingchanneljoined(
|
6803
|
+
message.streaming_joined_event
|
6804
|
+
);
|
6757
6805
|
} else if (message.streaming_leaved_event) {
|
6758
|
-
this.onstreamingchannelleaved(
|
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(
|
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.
|
6820
|
+
this.onmessagebuttonclicked(message.message_button_clicked);
|
6821
|
+
} else if (message.webrtc_signaling_fwd) {
|
6822
|
+
this.onwebrtcsignalingfwd(message.webrtc_signaling_fwd);
|
6769
6823
|
} else {
|
6770
6824
|
if (this.verbose && window && window.console) {
|
6771
6825
|
console.log("Unrecognized message received: %o", message);
|
@@ -6786,7 +6840,7 @@ var _DefaultSocket = class _DefaultSocket {
|
|
6786
6840
|
executor.resolve(message);
|
6787
6841
|
}
|
6788
6842
|
}
|
6789
|
-
};
|
6843
|
+
});
|
6790
6844
|
return new Promise((resolve, reject) => {
|
6791
6845
|
this.adapter.onOpen = (evt) => {
|
6792
6846
|
if (this.verbose && window && window.console) {
|
@@ -7043,11 +7097,16 @@ var _DefaultSocket = class _DefaultSocket {
|
|
7043
7097
|
console.log(tokenSentEvent);
|
7044
7098
|
}
|
7045
7099
|
}
|
7046
|
-
|
7100
|
+
onmessagebuttonclicked(messageButtonClicked) {
|
7047
7101
|
if (this.verbose && window && window.console) {
|
7048
7102
|
console.log(messageButtonClicked);
|
7049
7103
|
}
|
7050
7104
|
}
|
7105
|
+
onwebrtcsignalingfwd(event) {
|
7106
|
+
if (this.verbose && window && window.console) {
|
7107
|
+
console.log(event);
|
7108
|
+
}
|
7109
|
+
}
|
7051
7110
|
send(message, sendTimeout = _DefaultSocket.DefaultSendTimeoutMs) {
|
7052
7111
|
const untypedMessage = message;
|
7053
7112
|
return new Promise((resolve, reject) => {
|
@@ -7055,9 +7114,13 @@ var _DefaultSocket = class _DefaultSocket {
|
|
7055
7114
|
reject("Socket connection has not been established yet.");
|
7056
7115
|
} else {
|
7057
7116
|
if (untypedMessage.channel_message_send) {
|
7058
|
-
untypedMessage.channel_message_send.content = JSON.stringify(
|
7117
|
+
untypedMessage.channel_message_send.content = JSON.stringify(
|
7118
|
+
untypedMessage.channel_message_send.content
|
7119
|
+
);
|
7059
7120
|
} else if (untypedMessage.channel_message_update) {
|
7060
|
-
untypedMessage.channel_message_update.content = JSON.stringify(
|
7121
|
+
untypedMessage.channel_message_update.content = JSON.stringify(
|
7122
|
+
untypedMessage.channel_message_update.content
|
7123
|
+
);
|
7061
7124
|
}
|
7062
7125
|
const cid = this.generatecid();
|
7063
7126
|
this.cIds[cid] = { resolve, reject };
|
@@ -7087,49 +7150,50 @@ var _DefaultSocket = class _DefaultSocket {
|
|
7087
7150
|
}
|
7088
7151
|
joinChat(clan_id, channel_id, channel_type, is_public) {
|
7089
7152
|
return __async(this, null, function* () {
|
7090
|
-
const response = yield this.send(
|
7091
|
-
{
|
7092
|
-
|
7093
|
-
|
7094
|
-
|
7095
|
-
|
7096
|
-
is_public
|
7097
|
-
}
|
7153
|
+
const response = yield this.send({
|
7154
|
+
channel_join: {
|
7155
|
+
clan_id,
|
7156
|
+
channel_id,
|
7157
|
+
channel_type,
|
7158
|
+
is_public
|
7098
7159
|
}
|
7099
|
-
);
|
7160
|
+
});
|
7100
7161
|
return response.channel;
|
7101
7162
|
});
|
7102
7163
|
}
|
7103
7164
|
leaveChat(clan_id, channel_id, channel_type, is_public) {
|
7104
|
-
return this.send({
|
7165
|
+
return this.send({
|
7166
|
+
channel_leave: {
|
7167
|
+
clan_id,
|
7168
|
+
channel_id,
|
7169
|
+
channel_type,
|
7170
|
+
is_public
|
7171
|
+
}
|
7172
|
+
});
|
7105
7173
|
}
|
7106
7174
|
removeChatMessage(clan_id, channel_id, mode, is_public, message_id) {
|
7107
7175
|
return __async(this, null, function* () {
|
7108
|
-
const response = yield this.send(
|
7109
|
-
{
|
7110
|
-
|
7111
|
-
|
7112
|
-
|
7113
|
-
|
7114
|
-
|
7115
|
-
is_public
|
7116
|
-
}
|
7176
|
+
const response = yield this.send({
|
7177
|
+
channel_message_remove: {
|
7178
|
+
clan_id,
|
7179
|
+
channel_id,
|
7180
|
+
mode,
|
7181
|
+
message_id,
|
7182
|
+
is_public
|
7117
7183
|
}
|
7118
|
-
);
|
7184
|
+
});
|
7119
7185
|
return response.channel_message_ack;
|
7120
7186
|
});
|
7121
7187
|
}
|
7122
7188
|
rpc(id, payload, http_key) {
|
7123
7189
|
return __async(this, null, function* () {
|
7124
|
-
const response = yield this.send(
|
7125
|
-
{
|
7126
|
-
|
7127
|
-
|
7128
|
-
|
7129
|
-
http_key
|
7130
|
-
}
|
7190
|
+
const response = yield this.send({
|
7191
|
+
rpc: {
|
7192
|
+
id,
|
7193
|
+
payload,
|
7194
|
+
http_key
|
7131
7195
|
}
|
7132
|
-
);
|
7196
|
+
});
|
7133
7197
|
return response.rpc;
|
7134
7198
|
});
|
7135
7199
|
}
|
@@ -7138,7 +7202,19 @@ var _DefaultSocket = class _DefaultSocket {
|
|
7138
7202
|
}
|
7139
7203
|
updateChatMessage(clan_id, channel_id, mode, is_public, message_id, content, mentions, attachments, hideEditted) {
|
7140
7204
|
return __async(this, null, function* () {
|
7141
|
-
const response = yield this.send({
|
7205
|
+
const response = yield this.send({
|
7206
|
+
channel_message_update: {
|
7207
|
+
clan_id,
|
7208
|
+
channel_id,
|
7209
|
+
message_id,
|
7210
|
+
content,
|
7211
|
+
mentions,
|
7212
|
+
attachments,
|
7213
|
+
mode,
|
7214
|
+
is_public,
|
7215
|
+
hide_editted: hideEditted
|
7216
|
+
}
|
7217
|
+
});
|
7142
7218
|
return response.channel_message_ack;
|
7143
7219
|
});
|
7144
7220
|
}
|
@@ -7147,58 +7223,152 @@ var _DefaultSocket = class _DefaultSocket {
|
|
7147
7223
|
}
|
7148
7224
|
writeChatMessage(clan_id, channel_id, mode, is_public, content, mentions, attachments, references, anonymous_message, mention_everyone, avatar) {
|
7149
7225
|
return __async(this, null, function* () {
|
7150
|
-
const response = yield this.send({
|
7226
|
+
const response = yield this.send({
|
7227
|
+
channel_message_send: {
|
7228
|
+
clan_id,
|
7229
|
+
channel_id,
|
7230
|
+
mode,
|
7231
|
+
is_public,
|
7232
|
+
content,
|
7233
|
+
mentions,
|
7234
|
+
attachments,
|
7235
|
+
references,
|
7236
|
+
anonymous_message,
|
7237
|
+
mention_everyone,
|
7238
|
+
avatar
|
7239
|
+
}
|
7240
|
+
});
|
7151
7241
|
return response.channel_message_ack;
|
7152
7242
|
});
|
7153
7243
|
}
|
7154
7244
|
writeMessageReaction(id, clan_id, channel_id, mode, is_public, message_id, emoji_id, emoji, count, message_sender_id, action_delete) {
|
7155
7245
|
return __async(this, null, function* () {
|
7156
|
-
const response = yield this.send({
|
7246
|
+
const response = yield this.send({
|
7247
|
+
message_reaction_event: {
|
7248
|
+
id,
|
7249
|
+
clan_id,
|
7250
|
+
channel_id,
|
7251
|
+
mode,
|
7252
|
+
is_public,
|
7253
|
+
message_id,
|
7254
|
+
emoji_id,
|
7255
|
+
emoji,
|
7256
|
+
count,
|
7257
|
+
message_sender_id,
|
7258
|
+
action: action_delete
|
7259
|
+
}
|
7260
|
+
});
|
7157
7261
|
return response.message_reaction_event;
|
7158
7262
|
});
|
7159
7263
|
}
|
7160
7264
|
writeMessageTyping(clan_id, channel_id, mode, is_public) {
|
7161
7265
|
return __async(this, null, function* () {
|
7162
|
-
const response = yield this.send({
|
7266
|
+
const response = yield this.send({
|
7267
|
+
message_typing_event: {
|
7268
|
+
clan_id,
|
7269
|
+
channel_id,
|
7270
|
+
mode,
|
7271
|
+
is_public
|
7272
|
+
}
|
7273
|
+
});
|
7163
7274
|
return response.message_typing_event;
|
7164
7275
|
});
|
7165
7276
|
}
|
7166
7277
|
writeLastSeenMessage(clan_id, channel_id, mode, message_id, timestamp_seconds) {
|
7167
7278
|
return __async(this, null, function* () {
|
7168
|
-
const response = yield this.send({
|
7279
|
+
const response = yield this.send({
|
7280
|
+
last_seen_message_event: {
|
7281
|
+
clan_id,
|
7282
|
+
channel_id,
|
7283
|
+
mode,
|
7284
|
+
message_id,
|
7285
|
+
timestamp_seconds
|
7286
|
+
}
|
7287
|
+
});
|
7169
7288
|
return response.last_seen_message_event;
|
7170
7289
|
});
|
7171
7290
|
}
|
7172
7291
|
writeLastPinMessage(clan_id, channel_id, mode, is_public, message_id, timestamp_seconds, operation) {
|
7173
7292
|
return __async(this, null, function* () {
|
7174
|
-
const response = yield this.send({
|
7293
|
+
const response = yield this.send({
|
7294
|
+
last_pin_message_event: {
|
7295
|
+
clan_id,
|
7296
|
+
channel_id,
|
7297
|
+
mode,
|
7298
|
+
is_public,
|
7299
|
+
message_id,
|
7300
|
+
timestamp_seconds,
|
7301
|
+
operation
|
7302
|
+
}
|
7303
|
+
});
|
7175
7304
|
return response.last_pin_message_event;
|
7176
7305
|
});
|
7177
7306
|
}
|
7178
7307
|
writeVoiceJoined(id, clanId, clanName, voiceChannelId, voiceChannelLabel, participant, lastScreenshot) {
|
7179
7308
|
return __async(this, null, function* () {
|
7180
|
-
const response = yield this.send({
|
7309
|
+
const response = yield this.send({
|
7310
|
+
voice_joined_event: {
|
7311
|
+
clan_id: clanId,
|
7312
|
+
clan_name: clanName,
|
7313
|
+
id,
|
7314
|
+
participant,
|
7315
|
+
voice_channel_id: voiceChannelId,
|
7316
|
+
voice_channel_label: voiceChannelLabel,
|
7317
|
+
last_screenshot: lastScreenshot
|
7318
|
+
}
|
7319
|
+
});
|
7181
7320
|
return response.voice_joined_event;
|
7182
7321
|
});
|
7183
7322
|
}
|
7184
7323
|
writeVoiceLeaved(id, clanId, voiceChannelId, voiceUserId) {
|
7185
7324
|
return __async(this, null, function* () {
|
7186
|
-
const response = yield this.send({
|
7325
|
+
const response = yield this.send({
|
7326
|
+
voice_leaved_event: {
|
7327
|
+
id,
|
7328
|
+
clan_id: clanId,
|
7329
|
+
voice_channel_id: voiceChannelId,
|
7330
|
+
voice_user_id: voiceUserId
|
7331
|
+
}
|
7332
|
+
});
|
7187
7333
|
return response.voice_leaved_event;
|
7188
7334
|
});
|
7189
7335
|
}
|
7190
7336
|
writeCustomStatus(clan_id, status) {
|
7191
7337
|
return __async(this, null, function* () {
|
7192
|
-
const response = yield this.send({
|
7338
|
+
const response = yield this.send({
|
7339
|
+
custom_status_event: { clan_id, status }
|
7340
|
+
});
|
7193
7341
|
return response.custom_status_event;
|
7194
7342
|
});
|
7195
7343
|
}
|
7196
7344
|
checkDuplicateName(name, condition_id, type) {
|
7197
7345
|
return __async(this, null, function* () {
|
7198
|
-
const response = yield this.send({
|
7346
|
+
const response = yield this.send({
|
7347
|
+
check_name_existed_event: {
|
7348
|
+
name,
|
7349
|
+
condition_id,
|
7350
|
+
type
|
7351
|
+
}
|
7352
|
+
});
|
7199
7353
|
return response.check_name_existed_event;
|
7200
7354
|
});
|
7201
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
|
+
}
|
7202
7372
|
pingPong() {
|
7203
7373
|
return __async(this, null, function* () {
|
7204
7374
|
if (!this.adapter.isOpen()) {
|