mezon-sdk 2.7.2 → 2.7.4
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/api.ts +59 -0
- package/client.ts +309 -19
- package/dist/mezon-sdk.cjs.js +62 -19
- package/package.json +1 -1
- package/socket.ts +6 -187
- package/dist/api.d.ts +0 -53
- package/dist/client.d.ts +0 -60
- package/dist/index.d.ts +0 -18
- package/dist/mezon-sdk.esm.mjs +0 -10283
- package/dist/mezon-sdk.iife.js +0 -10305
- package/dist/mezon-sdk.umd.js +0 -10979
- package/dist/session.d.ts +0 -52
- package/dist/socket.d.ts +0 -696
- package/dist/utils.d.ts +0 -3
- package/dist/web_socket_adapter.d.ts +0 -83
package/api.ts
CHANGED
|
@@ -5,6 +5,28 @@ import { buildFetchOptions } from './utils';
|
|
|
5
5
|
import { encode } from 'js-base64';
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
/** */
|
|
9
|
+
export interface ApiClanDescList {
|
|
10
|
+
//A list of channel.
|
|
11
|
+
clandesc?: Array<ApiClanDesc>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** */
|
|
15
|
+
export interface ApiClanDesc {
|
|
16
|
+
//
|
|
17
|
+
banner?: string;
|
|
18
|
+
//
|
|
19
|
+
clan_id?: string;
|
|
20
|
+
//
|
|
21
|
+
clan_name?: string;
|
|
22
|
+
//
|
|
23
|
+
creator_id?: string;
|
|
24
|
+
//
|
|
25
|
+
logo?: string;
|
|
26
|
+
//
|
|
27
|
+
status?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
8
30
|
/** A user's session used to authenticate messages. */
|
|
9
31
|
export interface ApiSession {
|
|
10
32
|
//True if the corresponding account was just created, false otherwise.
|
|
@@ -313,6 +335,43 @@ export class MezonApi {
|
|
|
313
335
|
]);
|
|
314
336
|
}
|
|
315
337
|
|
|
338
|
+
/** List clans */
|
|
339
|
+
listClanDescs(bearerToken: string,
|
|
340
|
+
limit?:number,
|
|
341
|
+
state?:number,
|
|
342
|
+
cursor?:string,
|
|
343
|
+
options: any = {}): Promise<ApiClanDescList> {
|
|
344
|
+
|
|
345
|
+
const urlPath = "/v2/clandesc";
|
|
346
|
+
const queryParams = new Map<string, any>();
|
|
347
|
+
queryParams.set("limit", limit);
|
|
348
|
+
queryParams.set("state", state);
|
|
349
|
+
queryParams.set("cursor", cursor);
|
|
350
|
+
|
|
351
|
+
let bodyJson : string = "";
|
|
352
|
+
|
|
353
|
+
const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
354
|
+
const fetchOptions = buildFetchOptions("GET", options, bodyJson);
|
|
355
|
+
if (bearerToken) {
|
|
356
|
+
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return Promise.race([
|
|
360
|
+
fetch(fullUrl, fetchOptions).then((response) => {
|
|
361
|
+
if (response.status == 204) {
|
|
362
|
+
return response;
|
|
363
|
+
} else if (response.status >= 200 && response.status < 300) {
|
|
364
|
+
return response.json();
|
|
365
|
+
} else {
|
|
366
|
+
throw response;
|
|
367
|
+
}
|
|
368
|
+
}),
|
|
369
|
+
new Promise((_, reject) =>
|
|
370
|
+
setTimeout(reject, this.timeoutMs, "Request timed out.")
|
|
371
|
+
),
|
|
372
|
+
]);
|
|
373
|
+
}
|
|
374
|
+
|
|
316
375
|
buildFullUrl(basePath: string, fragment: string, queryParams: Map<string, any>) {
|
|
317
376
|
let fullPath = basePath + fragment + "?";
|
|
318
377
|
|
package/client.ts
CHANGED
|
@@ -16,18 +16,288 @@
|
|
|
16
16
|
|
|
17
17
|
import { MezonApi, ApiAuthenticateLogoutRequest, ApiAuthenticateRefreshRequest, ApiUpdateMessageRequest, ApiSession } from "./api";
|
|
18
18
|
import { Session } from "./session";
|
|
19
|
-
import {
|
|
19
|
+
import { ChannelCreatedEvent, ChannelDeletedEvent, ChannelUpdatedEvent, DefaultSocket, Socket, UserChannelAddedEvent, UserChannelRemovedEvent, UserClanRemovedEvent, VoiceJoinedEvent } from "./socket";
|
|
20
20
|
import { WebSocketAdapter } from "./web_socket_adapter";
|
|
21
21
|
import { WebSocketAdapterPb } from 'mezon-js-protobuf';
|
|
22
22
|
|
|
23
|
-
const DEFAULT_HOST = "
|
|
24
|
-
const DEFAULT_PORT = "
|
|
23
|
+
const DEFAULT_HOST = "dev-mezon.nccsoft.vn";
|
|
24
|
+
const DEFAULT_PORT = "7305";
|
|
25
25
|
const DEFAULT_API_KEY = "defaultkey";
|
|
26
26
|
const DEFAULT_TIMEOUT_MS = 7000;
|
|
27
27
|
const DEFAULT_EXPIRED_TIMESPAN_MS = 5 * 60 * 1000;
|
|
28
28
|
|
|
29
|
+
|
|
30
|
+
/** */
|
|
31
|
+
export interface ClanDesc {
|
|
32
|
+
//
|
|
33
|
+
banner?: string;
|
|
34
|
+
//
|
|
35
|
+
clan_id?: string;
|
|
36
|
+
//
|
|
37
|
+
clan_name?: string;
|
|
38
|
+
//
|
|
39
|
+
creator_id?: string;
|
|
40
|
+
//
|
|
41
|
+
logo?: string;
|
|
42
|
+
//
|
|
43
|
+
status?: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** */
|
|
47
|
+
export interface ChannelDescription {
|
|
48
|
+
// The clan of this channel
|
|
49
|
+
clan_id?: string;
|
|
50
|
+
// The channel this message belongs to.
|
|
51
|
+
channel_id?: string;
|
|
52
|
+
// The channel type.
|
|
53
|
+
type?: number;
|
|
54
|
+
// The channel lable
|
|
55
|
+
channel_label?: string;
|
|
56
|
+
// The channel private
|
|
57
|
+
channel_private?: number;
|
|
58
|
+
// meeting code
|
|
59
|
+
meeting_code?: string;
|
|
60
|
+
//
|
|
61
|
+
clan_name?: string;
|
|
62
|
+
//
|
|
63
|
+
parrent_id?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** */
|
|
67
|
+
export interface ApiMessageAttachment {
|
|
68
|
+
//
|
|
69
|
+
filename?: string;
|
|
70
|
+
//
|
|
71
|
+
filetype?: string;
|
|
72
|
+
//
|
|
73
|
+
height?: number;
|
|
74
|
+
//
|
|
75
|
+
size?: number;
|
|
76
|
+
//
|
|
77
|
+
url?: string;
|
|
78
|
+
//
|
|
79
|
+
width?: number;
|
|
80
|
+
/** The channel this message belongs to. */
|
|
81
|
+
channel_id?:string;
|
|
82
|
+
// The mode
|
|
83
|
+
mode?: number;
|
|
84
|
+
// The channel label
|
|
85
|
+
channel_label?: string;
|
|
86
|
+
/** The message that user react */
|
|
87
|
+
message_id?: string;
|
|
88
|
+
/** Message sender, usually a user ID. */
|
|
89
|
+
sender_id?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** */
|
|
93
|
+
export interface ApiMessageDeleted {
|
|
94
|
+
//
|
|
95
|
+
deletor?: string;
|
|
96
|
+
//
|
|
97
|
+
message_id?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** */
|
|
101
|
+
export interface ApiMessageMention {
|
|
102
|
+
//The UNIX time (for gRPC clients) or ISO string (for REST clients) when the message was created.
|
|
103
|
+
create_time?: string;
|
|
104
|
+
//
|
|
105
|
+
id?: string;
|
|
106
|
+
//
|
|
107
|
+
user_id?: string;
|
|
108
|
+
//
|
|
109
|
+
username?: string;
|
|
110
|
+
// role id
|
|
111
|
+
role_id?: string;
|
|
112
|
+
// role name
|
|
113
|
+
rolename?: string;
|
|
114
|
+
// start position
|
|
115
|
+
s?: number;
|
|
116
|
+
// end position
|
|
117
|
+
e?: number;
|
|
118
|
+
/** The channel this message belongs to. */
|
|
119
|
+
channel_id?:string;
|
|
120
|
+
// The mode
|
|
121
|
+
mode?: number;
|
|
122
|
+
// The channel label
|
|
123
|
+
channel_label?: string;
|
|
124
|
+
/** The message that user react */
|
|
125
|
+
message_id?: string;
|
|
126
|
+
/** Message sender, usually a user ID. */
|
|
127
|
+
sender_id?: string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** */
|
|
131
|
+
export interface ApiMessageReaction {
|
|
132
|
+
//
|
|
133
|
+
action?: boolean;
|
|
134
|
+
//
|
|
135
|
+
emoji_id: string;
|
|
136
|
+
//
|
|
137
|
+
emoji: string;
|
|
138
|
+
//
|
|
139
|
+
id?: string;
|
|
140
|
+
//
|
|
141
|
+
sender_id?: string;
|
|
142
|
+
//
|
|
143
|
+
sender_name?: string;
|
|
144
|
+
//
|
|
145
|
+
sender_avatar?: string;
|
|
146
|
+
// count of emoji
|
|
147
|
+
count: number;
|
|
148
|
+
/** The channel this message belongs to. */
|
|
149
|
+
channel_id:string;
|
|
150
|
+
// The mode
|
|
151
|
+
mode: number;
|
|
152
|
+
// The channel label
|
|
153
|
+
channel_label: string;
|
|
154
|
+
/** The message that user react */
|
|
155
|
+
message_id: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** */
|
|
159
|
+
export interface ApiMessageRef {
|
|
160
|
+
//
|
|
161
|
+
message_id?: string;
|
|
162
|
+
//
|
|
163
|
+
message_ref_id?: string;
|
|
164
|
+
//
|
|
165
|
+
ref_type?: number;
|
|
166
|
+
//
|
|
167
|
+
message_sender_id?: string;
|
|
168
|
+
// original message sendre username
|
|
169
|
+
message_sender_username?: string;
|
|
170
|
+
// original message sender avatar
|
|
171
|
+
mesages_sender_avatar?: string;
|
|
172
|
+
// original sender clan nick name
|
|
173
|
+
message_sender_clan_nick?: string;
|
|
174
|
+
// original sender display name
|
|
175
|
+
message_sender_display_name?:string;
|
|
176
|
+
//
|
|
177
|
+
content?:string;
|
|
178
|
+
//
|
|
179
|
+
has_attachment: boolean;
|
|
180
|
+
/** The channel this message belongs to. */
|
|
181
|
+
channel_id:string;
|
|
182
|
+
// The mode
|
|
183
|
+
mode: number;
|
|
184
|
+
// The channel label
|
|
185
|
+
channel_label: string;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** A message sent on a channel. */
|
|
189
|
+
export interface ChannelMessage {
|
|
190
|
+
//The unique ID of this message.
|
|
191
|
+
id: string;
|
|
192
|
+
//
|
|
193
|
+
avatar?: string;
|
|
194
|
+
//The channel this message belongs to.
|
|
195
|
+
channel_id: string;
|
|
196
|
+
//The name of the chat room, or an empty string if this message was not sent through a chat room.
|
|
197
|
+
channel_label: string;
|
|
198
|
+
//The clan this message belong to.
|
|
199
|
+
clan_id?: string;
|
|
200
|
+
//The code representing a message type or category.
|
|
201
|
+
code: number;
|
|
202
|
+
//The content payload.
|
|
203
|
+
content: string;
|
|
204
|
+
//The UNIX time (for gRPC clients) or ISO string (for REST clients) when the message was created.
|
|
205
|
+
create_time: string;
|
|
206
|
+
//
|
|
207
|
+
reactions?: Array<ApiMessageReaction>;
|
|
208
|
+
//
|
|
209
|
+
mentions?: Array<ApiMessageMention>;
|
|
210
|
+
//
|
|
211
|
+
attachments?: Array<ApiMessageAttachment>;
|
|
212
|
+
//
|
|
213
|
+
references?: Array<ApiMessageRef>;
|
|
214
|
+
//
|
|
215
|
+
referenced_message?: ChannelMessage;
|
|
216
|
+
//True if the message was persisted to the channel's history, false otherwise.
|
|
217
|
+
persistent?: boolean;
|
|
218
|
+
//Message sender, usually a user ID.
|
|
219
|
+
sender_id: string;
|
|
220
|
+
//The UNIX time (for gRPC clients) or ISO string (for REST clients) when the message was last updated.
|
|
221
|
+
update_time?: string;
|
|
222
|
+
//The ID of the first DM user, or an empty string if this message was not sent through a DM chat.
|
|
223
|
+
clan_logo?: string;
|
|
224
|
+
//The ID of the second DM user, or an empty string if this message was not sent through a DM chat.
|
|
225
|
+
category_name?: string;
|
|
226
|
+
//The username of the message sender, if any.
|
|
227
|
+
username?: string;
|
|
228
|
+
// The clan nick name
|
|
229
|
+
clan_nick?: string;
|
|
230
|
+
// The clan avatar
|
|
231
|
+
clan_avatar?: string;
|
|
232
|
+
//
|
|
233
|
+
display_name?: string;
|
|
234
|
+
//
|
|
235
|
+
create_time_ms?: number;
|
|
236
|
+
//
|
|
237
|
+
update_time_ms?: number;
|
|
238
|
+
//
|
|
239
|
+
mode?: number;
|
|
240
|
+
//
|
|
241
|
+
message_id?: string;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
/** A user in the server. */
|
|
246
|
+
export interface ApiUser {
|
|
247
|
+
//
|
|
248
|
+
about_me?: string;
|
|
249
|
+
//The Apple Sign In ID in the user's account.
|
|
250
|
+
apple_id?: string;
|
|
251
|
+
//A URL for an avatar image.
|
|
252
|
+
avatar_url?: string;
|
|
253
|
+
//The UNIX time (for gRPC clients) or ISO string (for REST clients) when the user was created.
|
|
254
|
+
create_time?: string;
|
|
255
|
+
//The display name of the user.
|
|
256
|
+
display_name?: string;
|
|
257
|
+
//Number of related edges to this user.
|
|
258
|
+
edge_count?: number;
|
|
259
|
+
//The Facebook id in the user's account.
|
|
260
|
+
facebook_id?: string;
|
|
261
|
+
//The Apple Game Center in of the user's account.
|
|
262
|
+
gamecenter_id?: string;
|
|
263
|
+
//The Google id in the user's account.
|
|
264
|
+
google_id?: string;
|
|
265
|
+
//The id of the user's account.
|
|
266
|
+
id?: string;
|
|
267
|
+
//
|
|
268
|
+
join_time?: string;
|
|
269
|
+
//The language expected to be a tag which follows the BCP-47 spec.
|
|
270
|
+
lang_tag?: string;
|
|
271
|
+
//The location set by the user.
|
|
272
|
+
location?: string;
|
|
273
|
+
//Additional information stored as a JSON object.
|
|
274
|
+
metadata?: string;
|
|
275
|
+
//Indicates whether the user is currently online.
|
|
276
|
+
online?: boolean;
|
|
277
|
+
//The Steam id in the user's account.
|
|
278
|
+
steam_id?: string;
|
|
279
|
+
//The timezone set by the user.
|
|
280
|
+
timezone?: string;
|
|
281
|
+
//The UNIX time (for gRPC clients) or ISO string (for REST clients) when the user was last updated.
|
|
282
|
+
update_time?: string;
|
|
283
|
+
//The username of the user's account.
|
|
284
|
+
username?: string;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export interface Client {
|
|
288
|
+
authenticate: () => Promise<string>;
|
|
289
|
+
|
|
290
|
+
/** Receive clan evnet. */
|
|
291
|
+
onMessage: (channelMessage: ChannelMessage) => void;
|
|
292
|
+
onClanMemberUpdate: (member_id: Array<string>, leave: boolean) => void;
|
|
293
|
+
onMessageDelete: (channelMessage: ChannelMessage) => void;
|
|
294
|
+
onMessageReactionAdd: (messageReactionEvent: ApiMessageReaction) => void;
|
|
295
|
+
onVoiceStateUpdate: (voiceState: VoiceJoinedEvent) => void;
|
|
296
|
+
onMessageReactionRemove: (messageReactionEvent: ApiMessageReaction) => void;
|
|
297
|
+
}
|
|
298
|
+
|
|
29
299
|
/** A client for Mezon server. */
|
|
30
|
-
export class Client {
|
|
300
|
+
export class MezonClient implements Client {
|
|
31
301
|
|
|
32
302
|
/** The expired timespan used to check session lifetime. */
|
|
33
303
|
public expiredTimespanMs = DEFAULT_EXPIRED_TIMESPAN_MS;
|
|
@@ -39,7 +309,7 @@ export class Client {
|
|
|
39
309
|
readonly apiKey = DEFAULT_API_KEY,
|
|
40
310
|
readonly host = DEFAULT_HOST,
|
|
41
311
|
readonly port = DEFAULT_PORT,
|
|
42
|
-
readonly useSSL =
|
|
312
|
+
readonly useSSL = true,
|
|
43
313
|
readonly timeout = DEFAULT_TIMEOUT_MS,
|
|
44
314
|
readonly autoRefreshSession = true) {
|
|
45
315
|
const scheme = (useSSL) ? "https://" : "http://";
|
|
@@ -56,15 +326,22 @@ export class Client {
|
|
|
56
326
|
}
|
|
57
327
|
}).then(async (apiSession : ApiSession) => {
|
|
58
328
|
const sockSession = new Session(apiSession.token || "", apiSession.refresh_token || "");
|
|
59
|
-
const socket = this.createSocket(
|
|
329
|
+
const socket = this.createSocket(this.useSSL, true, new WebSocketAdapterPb());
|
|
60
330
|
const session = await socket.connect(sockSession, false);
|
|
61
331
|
|
|
62
332
|
if (!session) {
|
|
63
|
-
|
|
64
|
-
return;
|
|
333
|
+
return Promise.resolve("error authenticate");
|
|
65
334
|
}
|
|
335
|
+
|
|
336
|
+
const clans = await this.apiClient.listClanDescs(session.token);
|
|
337
|
+
clans.clandesc?.forEach(async clan => {
|
|
338
|
+
await socket.joinClanChat(clan.clan_id || '');
|
|
339
|
+
})
|
|
66
340
|
|
|
67
|
-
|
|
341
|
+
// join direct message
|
|
342
|
+
await socket.joinClanChat("0");
|
|
343
|
+
|
|
344
|
+
socket.onchannelmessage = this.onMessage;
|
|
68
345
|
socket.ondisconnect = this.ondisconnect;
|
|
69
346
|
socket.onerror = this.onerror;
|
|
70
347
|
socket.onmessagereaction = this.onmessagereaction;
|
|
@@ -151,10 +428,6 @@ export class Client {
|
|
|
151
428
|
}
|
|
152
429
|
}
|
|
153
430
|
|
|
154
|
-
onchannelmessage(channelMessage: ChannelMessage) {
|
|
155
|
-
this.onMessage(channelMessage);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
431
|
ondisconnect(e: Event) {
|
|
159
432
|
console.log(e);
|
|
160
433
|
}
|
|
@@ -188,11 +461,28 @@ export class Client {
|
|
|
188
461
|
}
|
|
189
462
|
|
|
190
463
|
/** Receive clan evnet. */
|
|
191
|
-
onMessage
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
464
|
+
onMessage(channelMessage: ChannelMessage) {
|
|
465
|
+
console.log(channelMessage);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
onClanMemberUpdate(member_id: Array<string>, leave: boolean) {
|
|
469
|
+
console.log(member_id, leave);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
onMessageDelete(channelMessage: ChannelMessage) {
|
|
473
|
+
console.log(channelMessage);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
onMessageReactionAdd(messageReactionEvent: ApiMessageReaction) {
|
|
477
|
+
console.log(messageReactionEvent);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
onVoiceStateUpdate(voiceState: VoiceJoinedEvent) {
|
|
481
|
+
console.log(voiceState);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
onMessageReactionRemove(messageReactionEvent: ApiMessageReaction) {
|
|
485
|
+
console.log(messageReactionEvent);
|
|
486
|
+
}
|
|
197
487
|
|
|
198
488
|
};
|
package/dist/mezon-sdk.cjs.js
CHANGED
|
@@ -54,7 +54,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
54
54
|
// index.ts
|
|
55
55
|
var mezon_sdk_exports = {};
|
|
56
56
|
__export(mezon_sdk_exports, {
|
|
57
|
-
|
|
57
|
+
MezonClient: () => MezonClient,
|
|
58
58
|
Session: () => Session
|
|
59
59
|
});
|
|
60
60
|
module.exports = __toCommonJS(mezon_sdk_exports);
|
|
@@ -844,6 +844,34 @@ var MezonApi = class {
|
|
|
844
844
|
)
|
|
845
845
|
]);
|
|
846
846
|
}
|
|
847
|
+
/** List clans */
|
|
848
|
+
listClanDescs(bearerToken, limit, state, cursor, options = {}) {
|
|
849
|
+
const urlPath = "/v2/clandesc";
|
|
850
|
+
const queryParams = /* @__PURE__ */ new Map();
|
|
851
|
+
queryParams.set("limit", limit);
|
|
852
|
+
queryParams.set("state", state);
|
|
853
|
+
queryParams.set("cursor", cursor);
|
|
854
|
+
let bodyJson = "";
|
|
855
|
+
const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams);
|
|
856
|
+
const fetchOptions = buildFetchOptions("GET", options, bodyJson);
|
|
857
|
+
if (bearerToken) {
|
|
858
|
+
fetchOptions.headers["Authorization"] = "Bearer " + bearerToken;
|
|
859
|
+
}
|
|
860
|
+
return Promise.race([
|
|
861
|
+
fetch(fullUrl, fetchOptions).then((response) => {
|
|
862
|
+
if (response.status == 204) {
|
|
863
|
+
return response;
|
|
864
|
+
} else if (response.status >= 200 && response.status < 300) {
|
|
865
|
+
return response.json();
|
|
866
|
+
} else {
|
|
867
|
+
throw response;
|
|
868
|
+
}
|
|
869
|
+
}),
|
|
870
|
+
new Promise(
|
|
871
|
+
(_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.")
|
|
872
|
+
)
|
|
873
|
+
]);
|
|
874
|
+
}
|
|
847
875
|
buildFullUrl(basePath, fragment, queryParams) {
|
|
848
876
|
let fullPath = basePath + fragment + "?";
|
|
849
877
|
for (let [k, v] of queryParams) {
|
|
@@ -1337,12 +1365,6 @@ var _DefaultSocket = class _DefaultSocket {
|
|
|
1337
1365
|
}
|
|
1338
1366
|
});
|
|
1339
1367
|
}
|
|
1340
|
-
followUsers(userIds) {
|
|
1341
|
-
return __async(this, null, function* () {
|
|
1342
|
-
const response = yield this.send({ status_follow: { user_ids: userIds } });
|
|
1343
|
-
return response.status;
|
|
1344
|
-
});
|
|
1345
|
-
}
|
|
1346
1368
|
joinClanChat(clan_id) {
|
|
1347
1369
|
return __async(this, null, function* () {
|
|
1348
1370
|
const response = yield this.send({
|
|
@@ -1550,7 +1572,7 @@ _DefaultSocket.DefaultSendTimeoutMs = 1e4;
|
|
|
1550
1572
|
_DefaultSocket.DefaultConnectTimeoutMs = 3e4;
|
|
1551
1573
|
var DefaultSocket = _DefaultSocket;
|
|
1552
1574
|
|
|
1553
|
-
//
|
|
1575
|
+
// node_modules/mezon-js-protobuf/dist/mezon-js-protobuf.esm.mjs
|
|
1554
1576
|
var __create = Object.create;
|
|
1555
1577
|
var __defProp2 = Object.defineProperty;
|
|
1556
1578
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
@@ -10161,13 +10183,13 @@ var WebSocketAdapterPb = class {
|
|
|
10161
10183
|
};
|
|
10162
10184
|
|
|
10163
10185
|
// client.ts
|
|
10164
|
-
var DEFAULT_HOST = "
|
|
10165
|
-
var DEFAULT_PORT = "
|
|
10186
|
+
var DEFAULT_HOST = "dev-mezon.nccsoft.vn";
|
|
10187
|
+
var DEFAULT_PORT = "7305";
|
|
10166
10188
|
var DEFAULT_API_KEY = "defaultkey";
|
|
10167
10189
|
var DEFAULT_TIMEOUT_MS = 7e3;
|
|
10168
10190
|
var DEFAULT_EXPIRED_TIMESPAN_MS = 5 * 60 * 1e3;
|
|
10169
|
-
var
|
|
10170
|
-
constructor(apiKey = DEFAULT_API_KEY, host = DEFAULT_HOST, port = DEFAULT_PORT, useSSL =
|
|
10191
|
+
var MezonClient = class {
|
|
10192
|
+
constructor(apiKey = DEFAULT_API_KEY, host = DEFAULT_HOST, port = DEFAULT_PORT, useSSL = true, timeout = DEFAULT_TIMEOUT_MS, autoRefreshSession = true) {
|
|
10171
10193
|
this.apiKey = apiKey;
|
|
10172
10194
|
this.host = host;
|
|
10173
10195
|
this.port = port;
|
|
@@ -10188,14 +10210,19 @@ var Client = class {
|
|
|
10188
10210
|
token: this.apiKey
|
|
10189
10211
|
}
|
|
10190
10212
|
}).then((apiSession) => __async(this, null, function* () {
|
|
10213
|
+
var _a;
|
|
10191
10214
|
const sockSession = new Session(apiSession.token || "", apiSession.refresh_token || "");
|
|
10192
|
-
const socket = this.createSocket(
|
|
10215
|
+
const socket = this.createSocket(this.useSSL, true, new WebSocketAdapterPb());
|
|
10193
10216
|
const session = yield socket.connect(sockSession, false);
|
|
10194
10217
|
if (!session) {
|
|
10195
|
-
|
|
10196
|
-
return;
|
|
10218
|
+
return Promise.resolve("error authenticate");
|
|
10197
10219
|
}
|
|
10198
|
-
|
|
10220
|
+
const clans = yield this.apiClient.listClanDescs(session.token);
|
|
10221
|
+
(_a = clans.clandesc) == null ? void 0 : _a.forEach((clan) => __async(this, null, function* () {
|
|
10222
|
+
yield socket.joinClanChat(clan.clan_id || "");
|
|
10223
|
+
}));
|
|
10224
|
+
yield socket.joinClanChat("0");
|
|
10225
|
+
socket.onchannelmessage = this.onMessage;
|
|
10199
10226
|
socket.ondisconnect = this.ondisconnect;
|
|
10200
10227
|
socket.onerror = this.onerror;
|
|
10201
10228
|
socket.onmessagereaction = this.onmessagereaction;
|
|
@@ -10273,9 +10300,6 @@ var Client = class {
|
|
|
10273
10300
|
this.onMessageReactionAdd(messagereaction);
|
|
10274
10301
|
}
|
|
10275
10302
|
}
|
|
10276
|
-
onchannelmessage(channelMessage) {
|
|
10277
|
-
this.onMessage(channelMessage);
|
|
10278
|
-
}
|
|
10279
10303
|
ondisconnect(e) {
|
|
10280
10304
|
console.log(e);
|
|
10281
10305
|
}
|
|
@@ -10300,4 +10324,23 @@ var Client = class {
|
|
|
10300
10324
|
onheartbeattimeout() {
|
|
10301
10325
|
console.log("Heartbeat timeout.");
|
|
10302
10326
|
}
|
|
10327
|
+
/** Receive clan evnet. */
|
|
10328
|
+
onMessage(channelMessage) {
|
|
10329
|
+
console.log(channelMessage);
|
|
10330
|
+
}
|
|
10331
|
+
onClanMemberUpdate(member_id, leave) {
|
|
10332
|
+
console.log(member_id, leave);
|
|
10333
|
+
}
|
|
10334
|
+
onMessageDelete(channelMessage) {
|
|
10335
|
+
console.log(channelMessage);
|
|
10336
|
+
}
|
|
10337
|
+
onMessageReactionAdd(messageReactionEvent) {
|
|
10338
|
+
console.log(messageReactionEvent);
|
|
10339
|
+
}
|
|
10340
|
+
onVoiceStateUpdate(voiceState) {
|
|
10341
|
+
console.log(voiceState);
|
|
10342
|
+
}
|
|
10343
|
+
onMessageReactionRemove(messageReactionEvent) {
|
|
10344
|
+
console.log(messageReactionEvent);
|
|
10345
|
+
}
|
|
10303
10346
|
};
|