mezon-sdk 2.7.2 → 2.7.3
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 +230 -19
- package/dist/api.d.ts +15 -0
- package/dist/client.d.ts +123 -10
- package/dist/mezon-sdk.cjs.js +62 -19
- package/dist/mezon-sdk.esm.mjs +62 -19
- package/dist/mezon-sdk.iife.js +62 -19
- package/dist/mezon-sdk.umd.js +101 -47
- package/dist/socket.d.ts +3 -105
- package/package.json +1 -1
- package/socket.ts +5 -186
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,209 @@
|
|
|
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 ApiMessageAttachment {
|
|
32
|
+
//
|
|
33
|
+
filename?: string;
|
|
34
|
+
//
|
|
35
|
+
filetype?: string;
|
|
36
|
+
//
|
|
37
|
+
height?: number;
|
|
38
|
+
//
|
|
39
|
+
size?: number;
|
|
40
|
+
//
|
|
41
|
+
url?: string;
|
|
42
|
+
//
|
|
43
|
+
width?: number;
|
|
44
|
+
/** The channel this message belongs to. */
|
|
45
|
+
channel_id?:string;
|
|
46
|
+
// The mode
|
|
47
|
+
mode?: number;
|
|
48
|
+
// The channel label
|
|
49
|
+
channel_label?: string;
|
|
50
|
+
/** The message that user react */
|
|
51
|
+
message_id?: string;
|
|
52
|
+
/** Message sender, usually a user ID. */
|
|
53
|
+
sender_id?: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** */
|
|
57
|
+
export interface ApiMessageDeleted {
|
|
58
|
+
//
|
|
59
|
+
deletor?: string;
|
|
60
|
+
//
|
|
61
|
+
message_id?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** */
|
|
65
|
+
export interface ApiMessageMention {
|
|
66
|
+
//The UNIX time (for gRPC clients) or ISO string (for REST clients) when the message was created.
|
|
67
|
+
create_time?: string;
|
|
68
|
+
//
|
|
69
|
+
id?: string;
|
|
70
|
+
//
|
|
71
|
+
user_id?: string;
|
|
72
|
+
//
|
|
73
|
+
username?: string;
|
|
74
|
+
// role id
|
|
75
|
+
role_id?: string;
|
|
76
|
+
// role name
|
|
77
|
+
rolename?: string;
|
|
78
|
+
// start position
|
|
79
|
+
s?: number;
|
|
80
|
+
// end position
|
|
81
|
+
e?: number;
|
|
82
|
+
/** The channel this message belongs to. */
|
|
83
|
+
channel_id?:string;
|
|
84
|
+
// The mode
|
|
85
|
+
mode?: number;
|
|
86
|
+
// The channel label
|
|
87
|
+
channel_label?: string;
|
|
88
|
+
/** The message that user react */
|
|
89
|
+
message_id?: string;
|
|
90
|
+
/** Message sender, usually a user ID. */
|
|
91
|
+
sender_id?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** */
|
|
95
|
+
export interface ApiMessageReaction {
|
|
96
|
+
//
|
|
97
|
+
action?: boolean;
|
|
98
|
+
//
|
|
99
|
+
emoji_id: string;
|
|
100
|
+
//
|
|
101
|
+
emoji: string;
|
|
102
|
+
//
|
|
103
|
+
id?: string;
|
|
104
|
+
//
|
|
105
|
+
sender_id?: string;
|
|
106
|
+
//
|
|
107
|
+
sender_name?: string;
|
|
108
|
+
//
|
|
109
|
+
sender_avatar?: string;
|
|
110
|
+
// count of emoji
|
|
111
|
+
count: number;
|
|
112
|
+
/** The channel this message belongs to. */
|
|
113
|
+
channel_id:string;
|
|
114
|
+
// The mode
|
|
115
|
+
mode: number;
|
|
116
|
+
// The channel label
|
|
117
|
+
channel_label: string;
|
|
118
|
+
/** The message that user react */
|
|
119
|
+
message_id: string;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** */
|
|
123
|
+
export interface ApiMessageRef {
|
|
124
|
+
//
|
|
125
|
+
message_id?: string;
|
|
126
|
+
//
|
|
127
|
+
message_ref_id?: string;
|
|
128
|
+
//
|
|
129
|
+
ref_type?: number;
|
|
130
|
+
//
|
|
131
|
+
message_sender_id?: string;
|
|
132
|
+
// original message sendre username
|
|
133
|
+
message_sender_username?: string;
|
|
134
|
+
// original message sender avatar
|
|
135
|
+
mesages_sender_avatar?: string;
|
|
136
|
+
// original sender clan nick name
|
|
137
|
+
message_sender_clan_nick?: string;
|
|
138
|
+
// original sender display name
|
|
139
|
+
message_sender_display_name?:string;
|
|
140
|
+
//
|
|
141
|
+
content?:string;
|
|
142
|
+
//
|
|
143
|
+
has_attachment: boolean;
|
|
144
|
+
/** The channel this message belongs to. */
|
|
145
|
+
channel_id:string;
|
|
146
|
+
// The mode
|
|
147
|
+
mode: number;
|
|
148
|
+
// The channel label
|
|
149
|
+
channel_label: string;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** A message sent on a channel. */
|
|
153
|
+
export interface ChannelMessage {
|
|
154
|
+
//The unique ID of this message.
|
|
155
|
+
id: string;
|
|
156
|
+
//
|
|
157
|
+
avatar?: string;
|
|
158
|
+
//The channel this message belongs to.
|
|
159
|
+
channel_id: string;
|
|
160
|
+
//The name of the chat room, or an empty string if this message was not sent through a chat room.
|
|
161
|
+
channel_label: string;
|
|
162
|
+
//The clan this message belong to.
|
|
163
|
+
clan_id?: string;
|
|
164
|
+
//The code representing a message type or category.
|
|
165
|
+
code: number;
|
|
166
|
+
//The content payload.
|
|
167
|
+
content: string;
|
|
168
|
+
//The UNIX time (for gRPC clients) or ISO string (for REST clients) when the message was created.
|
|
169
|
+
create_time: string;
|
|
170
|
+
//
|
|
171
|
+
reactions?: Array<ApiMessageReaction>;
|
|
172
|
+
//
|
|
173
|
+
mentions?: Array<ApiMessageMention>;
|
|
174
|
+
//
|
|
175
|
+
attachments?: Array<ApiMessageAttachment>;
|
|
176
|
+
//
|
|
177
|
+
references?: Array<ApiMessageRef>;
|
|
178
|
+
//
|
|
179
|
+
referenced_message?: ChannelMessage;
|
|
180
|
+
//True if the message was persisted to the channel's history, false otherwise.
|
|
181
|
+
persistent?: boolean;
|
|
182
|
+
//Message sender, usually a user ID.
|
|
183
|
+
sender_id: string;
|
|
184
|
+
//The UNIX time (for gRPC clients) or ISO string (for REST clients) when the message was last updated.
|
|
185
|
+
update_time?: string;
|
|
186
|
+
//The ID of the first DM user, or an empty string if this message was not sent through a DM chat.
|
|
187
|
+
clan_logo?: string;
|
|
188
|
+
//The ID of the second DM user, or an empty string if this message was not sent through a DM chat.
|
|
189
|
+
category_name?: string;
|
|
190
|
+
//The username of the message sender, if any.
|
|
191
|
+
username?: string;
|
|
192
|
+
// The clan nick name
|
|
193
|
+
clan_nick?: string;
|
|
194
|
+
// The clan avatar
|
|
195
|
+
clan_avatar?: string;
|
|
196
|
+
//
|
|
197
|
+
display_name?: string;
|
|
198
|
+
//
|
|
199
|
+
create_time_ms?: number;
|
|
200
|
+
//
|
|
201
|
+
update_time_ms?: number;
|
|
202
|
+
//
|
|
203
|
+
mode?: number;
|
|
204
|
+
//
|
|
205
|
+
message_id?: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface Client {
|
|
209
|
+
authenticate: () => Promise<string>;
|
|
210
|
+
|
|
211
|
+
/** Receive clan evnet. */
|
|
212
|
+
onMessage: (channelMessage: ChannelMessage) => void;
|
|
213
|
+
onClanMemberUpdate: (member_id: Array<string>, leave: boolean) => void;
|
|
214
|
+
onMessageDelete: (channelMessage: ChannelMessage) => void;
|
|
215
|
+
onMessageReactionAdd: (messageReactionEvent: ApiMessageReaction) => void;
|
|
216
|
+
onVoiceStateUpdate: (voiceState: VoiceJoinedEvent) => void;
|
|
217
|
+
onMessageReactionRemove: (messageReactionEvent: ApiMessageReaction) => void;
|
|
218
|
+
}
|
|
219
|
+
|
|
29
220
|
/** A client for Mezon server. */
|
|
30
|
-
export class Client {
|
|
221
|
+
export class MezonClient implements Client {
|
|
31
222
|
|
|
32
223
|
/** The expired timespan used to check session lifetime. */
|
|
33
224
|
public expiredTimespanMs = DEFAULT_EXPIRED_TIMESPAN_MS;
|
|
@@ -39,7 +230,7 @@ export class Client {
|
|
|
39
230
|
readonly apiKey = DEFAULT_API_KEY,
|
|
40
231
|
readonly host = DEFAULT_HOST,
|
|
41
232
|
readonly port = DEFAULT_PORT,
|
|
42
|
-
readonly useSSL =
|
|
233
|
+
readonly useSSL = true,
|
|
43
234
|
readonly timeout = DEFAULT_TIMEOUT_MS,
|
|
44
235
|
readonly autoRefreshSession = true) {
|
|
45
236
|
const scheme = (useSSL) ? "https://" : "http://";
|
|
@@ -56,15 +247,22 @@ export class Client {
|
|
|
56
247
|
}
|
|
57
248
|
}).then(async (apiSession : ApiSession) => {
|
|
58
249
|
const sockSession = new Session(apiSession.token || "", apiSession.refresh_token || "");
|
|
59
|
-
const socket = this.createSocket(
|
|
250
|
+
const socket = this.createSocket(this.useSSL, true, new WebSocketAdapterPb());
|
|
60
251
|
const session = await socket.connect(sockSession, false);
|
|
61
252
|
|
|
62
253
|
if (!session) {
|
|
63
|
-
|
|
64
|
-
return;
|
|
254
|
+
return Promise.resolve("error authenticate");
|
|
65
255
|
}
|
|
256
|
+
|
|
257
|
+
const clans = await this.apiClient.listClanDescs(session.token);
|
|
258
|
+
clans.clandesc?.forEach(async clan => {
|
|
259
|
+
await socket.joinClanChat(clan.clan_id || '');
|
|
260
|
+
})
|
|
66
261
|
|
|
67
|
-
|
|
262
|
+
// join direct message
|
|
263
|
+
await socket.joinClanChat("0");
|
|
264
|
+
|
|
265
|
+
socket.onchannelmessage = this.onMessage;
|
|
68
266
|
socket.ondisconnect = this.ondisconnect;
|
|
69
267
|
socket.onerror = this.onerror;
|
|
70
268
|
socket.onmessagereaction = this.onmessagereaction;
|
|
@@ -151,10 +349,6 @@ export class Client {
|
|
|
151
349
|
}
|
|
152
350
|
}
|
|
153
351
|
|
|
154
|
-
onchannelmessage(channelMessage: ChannelMessage) {
|
|
155
|
-
this.onMessage(channelMessage);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
352
|
ondisconnect(e: Event) {
|
|
159
353
|
console.log(e);
|
|
160
354
|
}
|
|
@@ -188,11 +382,28 @@ export class Client {
|
|
|
188
382
|
}
|
|
189
383
|
|
|
190
384
|
/** Receive clan evnet. */
|
|
191
|
-
onMessage
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
385
|
+
onMessage(channelMessage: ChannelMessage) {
|
|
386
|
+
console.log(channelMessage);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
onClanMemberUpdate(member_id: Array<string>, leave: boolean) {
|
|
390
|
+
console.log(member_id, leave);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
onMessageDelete(channelMessage: ChannelMessage) {
|
|
394
|
+
console.log(channelMessage);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
onMessageReactionAdd(messageReactionEvent: ApiMessageReaction) {
|
|
398
|
+
console.log(messageReactionEvent);
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
onVoiceStateUpdate(voiceState: VoiceJoinedEvent) {
|
|
402
|
+
console.log(voiceState);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
onMessageReactionRemove(messageReactionEvent: ApiMessageReaction) {
|
|
406
|
+
console.log(messageReactionEvent);
|
|
407
|
+
}
|
|
197
408
|
|
|
198
409
|
};
|
package/dist/api.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/** */
|
|
2
|
+
export interface ApiClanDescList {
|
|
3
|
+
clandesc?: Array<ApiClanDesc>;
|
|
4
|
+
}
|
|
5
|
+
/** */
|
|
6
|
+
export interface ApiClanDesc {
|
|
7
|
+
banner?: string;
|
|
8
|
+
clan_id?: string;
|
|
9
|
+
clan_name?: string;
|
|
10
|
+
creator_id?: string;
|
|
11
|
+
logo?: string;
|
|
12
|
+
status?: number;
|
|
13
|
+
}
|
|
1
14
|
/** A user's session used to authenticate messages. */
|
|
2
15
|
export interface ApiSession {
|
|
3
16
|
created?: boolean;
|
|
@@ -49,5 +62,7 @@ export declare class MezonApi {
|
|
|
49
62
|
mezonDeleteMessage(bearerToken: string, id: string, options?: any): Promise<any>;
|
|
50
63
|
/** Updates a message for an identity. */
|
|
51
64
|
mezonUpdateMessage(bearerToken: string, id: string, body: ApiUpdateMessageRequest, options?: any): Promise<any>;
|
|
65
|
+
/** List clans */
|
|
66
|
+
listClanDescs(bearerToken: string, limit?: number, state?: number, cursor?: string, options?: any): Promise<ApiClanDescList>;
|
|
52
67
|
buildFullUrl(basePath: string, fragment: string, queryParams: Map<string, any>): string;
|
|
53
68
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -14,10 +14,124 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import { Session } from "./session";
|
|
17
|
-
import {
|
|
17
|
+
import { ChannelCreatedEvent, ChannelDeletedEvent, ChannelUpdatedEvent, Socket, UserChannelAddedEvent, UserChannelRemovedEvent, UserClanRemovedEvent, VoiceJoinedEvent } from "./socket";
|
|
18
18
|
import { WebSocketAdapter } from "./web_socket_adapter";
|
|
19
|
+
/** */
|
|
20
|
+
export interface ApiMessageAttachment {
|
|
21
|
+
filename?: string;
|
|
22
|
+
filetype?: string;
|
|
23
|
+
height?: number;
|
|
24
|
+
size?: number;
|
|
25
|
+
url?: string;
|
|
26
|
+
width?: number;
|
|
27
|
+
/** The channel this message belongs to. */
|
|
28
|
+
channel_id?: string;
|
|
29
|
+
mode?: number;
|
|
30
|
+
channel_label?: string;
|
|
31
|
+
/** The message that user react */
|
|
32
|
+
message_id?: string;
|
|
33
|
+
/** Message sender, usually a user ID. */
|
|
34
|
+
sender_id?: string;
|
|
35
|
+
}
|
|
36
|
+
/** */
|
|
37
|
+
export interface ApiMessageDeleted {
|
|
38
|
+
deletor?: string;
|
|
39
|
+
message_id?: string;
|
|
40
|
+
}
|
|
41
|
+
/** */
|
|
42
|
+
export interface ApiMessageMention {
|
|
43
|
+
create_time?: string;
|
|
44
|
+
id?: string;
|
|
45
|
+
user_id?: string;
|
|
46
|
+
username?: string;
|
|
47
|
+
role_id?: string;
|
|
48
|
+
rolename?: string;
|
|
49
|
+
s?: number;
|
|
50
|
+
e?: number;
|
|
51
|
+
/** The channel this message belongs to. */
|
|
52
|
+
channel_id?: string;
|
|
53
|
+
mode?: number;
|
|
54
|
+
channel_label?: string;
|
|
55
|
+
/** The message that user react */
|
|
56
|
+
message_id?: string;
|
|
57
|
+
/** Message sender, usually a user ID. */
|
|
58
|
+
sender_id?: string;
|
|
59
|
+
}
|
|
60
|
+
/** */
|
|
61
|
+
export interface ApiMessageReaction {
|
|
62
|
+
action?: boolean;
|
|
63
|
+
emoji_id: string;
|
|
64
|
+
emoji: string;
|
|
65
|
+
id?: string;
|
|
66
|
+
sender_id?: string;
|
|
67
|
+
sender_name?: string;
|
|
68
|
+
sender_avatar?: string;
|
|
69
|
+
count: number;
|
|
70
|
+
/** The channel this message belongs to. */
|
|
71
|
+
channel_id: string;
|
|
72
|
+
mode: number;
|
|
73
|
+
channel_label: string;
|
|
74
|
+
/** The message that user react */
|
|
75
|
+
message_id: string;
|
|
76
|
+
}
|
|
77
|
+
/** */
|
|
78
|
+
export interface ApiMessageRef {
|
|
79
|
+
message_id?: string;
|
|
80
|
+
message_ref_id?: string;
|
|
81
|
+
ref_type?: number;
|
|
82
|
+
message_sender_id?: string;
|
|
83
|
+
message_sender_username?: string;
|
|
84
|
+
mesages_sender_avatar?: string;
|
|
85
|
+
message_sender_clan_nick?: string;
|
|
86
|
+
message_sender_display_name?: string;
|
|
87
|
+
content?: string;
|
|
88
|
+
has_attachment: boolean;
|
|
89
|
+
/** The channel this message belongs to. */
|
|
90
|
+
channel_id: string;
|
|
91
|
+
mode: number;
|
|
92
|
+
channel_label: string;
|
|
93
|
+
}
|
|
94
|
+
/** A message sent on a channel. */
|
|
95
|
+
export interface ChannelMessage {
|
|
96
|
+
id: string;
|
|
97
|
+
avatar?: string;
|
|
98
|
+
channel_id: string;
|
|
99
|
+
channel_label: string;
|
|
100
|
+
clan_id?: string;
|
|
101
|
+
code: number;
|
|
102
|
+
content: string;
|
|
103
|
+
create_time: string;
|
|
104
|
+
reactions?: Array<ApiMessageReaction>;
|
|
105
|
+
mentions?: Array<ApiMessageMention>;
|
|
106
|
+
attachments?: Array<ApiMessageAttachment>;
|
|
107
|
+
references?: Array<ApiMessageRef>;
|
|
108
|
+
referenced_message?: ChannelMessage;
|
|
109
|
+
persistent?: boolean;
|
|
110
|
+
sender_id: string;
|
|
111
|
+
update_time?: string;
|
|
112
|
+
clan_logo?: string;
|
|
113
|
+
category_name?: string;
|
|
114
|
+
username?: string;
|
|
115
|
+
clan_nick?: string;
|
|
116
|
+
clan_avatar?: string;
|
|
117
|
+
display_name?: string;
|
|
118
|
+
create_time_ms?: number;
|
|
119
|
+
update_time_ms?: number;
|
|
120
|
+
mode?: number;
|
|
121
|
+
message_id?: string;
|
|
122
|
+
}
|
|
123
|
+
export interface Client {
|
|
124
|
+
authenticate: () => Promise<string>;
|
|
125
|
+
/** Receive clan evnet. */
|
|
126
|
+
onMessage: (channelMessage: ChannelMessage) => void;
|
|
127
|
+
onClanMemberUpdate: (member_id: Array<string>, leave: boolean) => void;
|
|
128
|
+
onMessageDelete: (channelMessage: ChannelMessage) => void;
|
|
129
|
+
onMessageReactionAdd: (messageReactionEvent: ApiMessageReaction) => void;
|
|
130
|
+
onVoiceStateUpdate: (voiceState: VoiceJoinedEvent) => void;
|
|
131
|
+
onMessageReactionRemove: (messageReactionEvent: ApiMessageReaction) => void;
|
|
132
|
+
}
|
|
19
133
|
/** A client for Mezon server. */
|
|
20
|
-
export declare class Client {
|
|
134
|
+
export declare class MezonClient implements Client {
|
|
21
135
|
readonly apiKey: string;
|
|
22
136
|
readonly host: string;
|
|
23
137
|
readonly port: string;
|
|
@@ -30,7 +144,7 @@ export declare class Client {
|
|
|
30
144
|
private readonly apiClient;
|
|
31
145
|
constructor(apiKey?: string, host?: string, port?: string, useSSL?: boolean, timeout?: number, autoRefreshSession?: boolean);
|
|
32
146
|
/** Authenticate a user with an ID against the server. */
|
|
33
|
-
authenticate(): Promise<string
|
|
147
|
+
authenticate(): Promise<string>;
|
|
34
148
|
/** Refresh a user's session using a refresh token retrieved from a previous authentication request. */
|
|
35
149
|
sessionRefresh(session: Session): Promise<Session>;
|
|
36
150
|
/** Log out a session, invalidate a refresh token, or log out all sessions/refresh tokens for a user. */
|
|
@@ -41,7 +155,6 @@ export declare class Client {
|
|
|
41
155
|
createSocket(useSSL?: boolean, verbose?: boolean, adapter?: WebSocketAdapter, sendTimeoutMs?: number): Socket;
|
|
42
156
|
onerror(evt: Event): void;
|
|
43
157
|
onmessagereaction(messagereaction: ApiMessageReaction): void;
|
|
44
|
-
onchannelmessage(channelMessage: ChannelMessage): void;
|
|
45
158
|
ondisconnect(e: Event): void;
|
|
46
159
|
onuserchanneladded(user: UserChannelAddedEvent): void;
|
|
47
160
|
onuserchannelremoved(user: UserChannelRemovedEvent): void;
|
|
@@ -51,10 +164,10 @@ export declare class Client {
|
|
|
51
164
|
onchannelupdated(channelUpdated: ChannelUpdatedEvent): void;
|
|
52
165
|
onheartbeattimeout(): void;
|
|
53
166
|
/** Receive clan evnet. */
|
|
54
|
-
onMessage
|
|
55
|
-
onClanMemberUpdate
|
|
56
|
-
onMessageDelete
|
|
57
|
-
onMessageReactionAdd
|
|
58
|
-
onVoiceStateUpdate
|
|
59
|
-
onMessageReactionRemove
|
|
167
|
+
onMessage(channelMessage: ChannelMessage): void;
|
|
168
|
+
onClanMemberUpdate(member_id: Array<string>, leave: boolean): void;
|
|
169
|
+
onMessageDelete(channelMessage: ChannelMessage): void;
|
|
170
|
+
onMessageReactionAdd(messageReactionEvent: ApiMessageReaction): void;
|
|
171
|
+
onVoiceStateUpdate(voiceState: VoiceJoinedEvent): void;
|
|
172
|
+
onMessageReactionRemove(messageReactionEvent: ApiMessageReaction): void;
|
|
60
173
|
}
|
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
|
};
|