mezon-sdk 2.7.1 → 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/README.md +143 -143
- package/api.ts +392 -0
- package/build.mjs +44 -44
- package/client.ts +409 -327
- package/dist/api.d.ts +68 -0
- package/dist/client.d.ts +173 -74
- package/dist/index.d.ts +18 -18
- package/dist/mezon-sdk.cjs.js +10346 -0
- package/dist/mezon-sdk.esm.mjs +10326 -0
- package/dist/mezon-sdk.iife.js +10348 -0
- package/dist/mezon-sdk.umd.js +11033 -0
- package/dist/session.d.ts +52 -52
- package/dist/socket.d.ts +594 -0
- package/dist/utils.d.ts +3 -3
- package/dist/web_socket_adapter.d.ts +83 -0
- package/index.ts +19 -19
- package/package.json +46 -49
- package/rollup.config.js +40 -40
- package/session.ts +107 -107
- package/socket.ts +1345 -0
- package/tsconfig.json +10 -10
- package/utils.ts +47 -47
- package/web_socket_adapter.ts +159 -0
- package/api.gen.ts +0 -783
- package/dist/api.gen.d.ts +0 -157
- package/dist/satori-js.cjs.js +0 -1456
- package/dist/satori-js.esm.mjs +0 -1436
- package/dist/satori-js.iife.js +0 -1458
- package/dist/satori-js.umd.js +0 -1956
- package/tsconfig.base.json +0 -33
package/client.ts
CHANGED
|
@@ -1,327 +1,409 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2020 The Nakama Authors
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
await
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2020 The Nakama Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { MezonApi, ApiAuthenticateLogoutRequest, ApiAuthenticateRefreshRequest, ApiUpdateMessageRequest, ApiSession } from "./api";
|
|
18
|
+
import { Session } from "./session";
|
|
19
|
+
import { ChannelCreatedEvent, ChannelDeletedEvent, ChannelUpdatedEvent, DefaultSocket, Socket, UserChannelAddedEvent, UserChannelRemovedEvent, UserClanRemovedEvent, VoiceJoinedEvent } from "./socket";
|
|
20
|
+
import { WebSocketAdapter } from "./web_socket_adapter";
|
|
21
|
+
import { WebSocketAdapterPb } from 'mezon-js-protobuf';
|
|
22
|
+
|
|
23
|
+
const DEFAULT_HOST = "dev-mezon.nccsoft.vn";
|
|
24
|
+
const DEFAULT_PORT = "7305";
|
|
25
|
+
const DEFAULT_API_KEY = "defaultkey";
|
|
26
|
+
const DEFAULT_TIMEOUT_MS = 7000;
|
|
27
|
+
const DEFAULT_EXPIRED_TIMESPAN_MS = 5 * 60 * 1000;
|
|
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
|
+
|
|
220
|
+
/** A client for Mezon server. */
|
|
221
|
+
export class MezonClient implements Client {
|
|
222
|
+
|
|
223
|
+
/** The expired timespan used to check session lifetime. */
|
|
224
|
+
public expiredTimespanMs = DEFAULT_EXPIRED_TIMESPAN_MS;
|
|
225
|
+
|
|
226
|
+
/** The low level API client for Nakama server. */
|
|
227
|
+
private readonly apiClient: MezonApi;
|
|
228
|
+
|
|
229
|
+
constructor(
|
|
230
|
+
readonly apiKey = DEFAULT_API_KEY,
|
|
231
|
+
readonly host = DEFAULT_HOST,
|
|
232
|
+
readonly port = DEFAULT_PORT,
|
|
233
|
+
readonly useSSL = true,
|
|
234
|
+
readonly timeout = DEFAULT_TIMEOUT_MS,
|
|
235
|
+
readonly autoRefreshSession = true) {
|
|
236
|
+
const scheme = (useSSL) ? "https://" : "http://";
|
|
237
|
+
const basePath = `${scheme}${host}:${port}`;
|
|
238
|
+
|
|
239
|
+
this.apiClient = new MezonApi(apiKey, basePath, timeout);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Authenticate a user with an ID against the server. */
|
|
243
|
+
async authenticate() {
|
|
244
|
+
return this.apiClient.mezonAuthenticate(this.apiKey, "", {
|
|
245
|
+
account: {
|
|
246
|
+
token: this.apiKey,
|
|
247
|
+
}
|
|
248
|
+
}).then(async (apiSession : ApiSession) => {
|
|
249
|
+
const sockSession = new Session(apiSession.token || "", apiSession.refresh_token || "");
|
|
250
|
+
const socket = this.createSocket(this.useSSL, true, new WebSocketAdapterPb());
|
|
251
|
+
const session = await socket.connect(sockSession, false);
|
|
252
|
+
|
|
253
|
+
if (!session) {
|
|
254
|
+
return Promise.resolve("error authenticate");
|
|
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
|
+
})
|
|
261
|
+
|
|
262
|
+
// join direct message
|
|
263
|
+
await socket.joinClanChat("0");
|
|
264
|
+
|
|
265
|
+
socket.onchannelmessage = this.onMessage;
|
|
266
|
+
socket.ondisconnect = this.ondisconnect;
|
|
267
|
+
socket.onerror = this.onerror;
|
|
268
|
+
socket.onmessagereaction = this.onmessagereaction;
|
|
269
|
+
socket.onuserchannelremoved = this.onuserchannelremoved;
|
|
270
|
+
socket.onuserclanremoved = this.onuserclanremoved;
|
|
271
|
+
socket.onuserchanneladded = this.onuserchanneladded;
|
|
272
|
+
socket.onchannelcreated = this.onchannelcreated;
|
|
273
|
+
socket.onchanneldeleted = this.onchanneldeleted;
|
|
274
|
+
socket.onchannelupdated = this.onchannelupdated;
|
|
275
|
+
socket.onheartbeattimeout = this.onheartbeattimeout;
|
|
276
|
+
|
|
277
|
+
return Promise.resolve("connect successful");
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** Refresh a user's session using a refresh token retrieved from a previous authentication request. */
|
|
282
|
+
async sessionRefresh(session: Session) {
|
|
283
|
+
|
|
284
|
+
const request : ApiAuthenticateRefreshRequest = {
|
|
285
|
+
"refresh_token": session.refresh_token,
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
return this.apiClient.mezonAuthenticateRefresh(this.apiKey, "", request).then((apiSession : ApiSession) => {
|
|
289
|
+
return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || ""));
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** Log out a session, invalidate a refresh token, or log out all sessions/refresh tokens for a user. */
|
|
294
|
+
async logout(session: Session) {
|
|
295
|
+
|
|
296
|
+
const request : ApiAuthenticateLogoutRequest = {
|
|
297
|
+
"token": session.token,
|
|
298
|
+
"refresh_token": session.refresh_token
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
return this.apiClient.mezonAuthenticateLogout(session.token, request).then((response) => {
|
|
302
|
+
return Promise.resolve(response !== undefined);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async deleteMessage(session : Session, id : string) {
|
|
307
|
+
if (this.autoRefreshSession && session.refresh_token &&
|
|
308
|
+
session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
|
|
309
|
+
await this.sessionRefresh(session);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return this.apiClient.mezonDeleteMessage(session.token, id).then((response) => {
|
|
313
|
+
return Promise.resolve(response !== undefined);
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async updateMessage(session : Session, id : string, consume_time? : string, read_time? : string) {
|
|
318
|
+
if (this.autoRefreshSession && session.refresh_token &&
|
|
319
|
+
session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
|
|
320
|
+
await this.sessionRefresh(session);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const request : ApiUpdateMessageRequest = {
|
|
324
|
+
id: id,
|
|
325
|
+
consume_time: consume_time,
|
|
326
|
+
read_time: read_time
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
return this.apiClient.mezonUpdateMessage(session.token, id, request).then((response) => {
|
|
330
|
+
return Promise.resolve(response !== undefined);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** A socket created with the client's configuration. */
|
|
335
|
+
createSocket(useSSL = false, verbose: boolean = false, adapter : WebSocketAdapter = new WebSocketAdapterPb(), sendTimeoutMs : number = DefaultSocket.DefaultSendTimeoutMs): Socket {
|
|
336
|
+
return new DefaultSocket(this.host, this.port, useSSL, verbose, adapter, sendTimeoutMs);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
onerror(evt: Event) {
|
|
340
|
+
console.log(evt);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
onmessagereaction(messagereaction: ApiMessageReaction) {
|
|
344
|
+
console.log(messagereaction);
|
|
345
|
+
if (messagereaction.action) {
|
|
346
|
+
this.onMessageReactionRemove(messagereaction);
|
|
347
|
+
} else {
|
|
348
|
+
this.onMessageReactionAdd(messagereaction);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
ondisconnect(e: Event) {
|
|
353
|
+
console.log(e);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
onuserchanneladded(user: UserChannelAddedEvent) {
|
|
357
|
+
console.log(user);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
onuserchannelremoved(user: UserChannelRemovedEvent) {
|
|
361
|
+
console.log(user);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
onuserclanremoved(user: UserClanRemovedEvent) {
|
|
365
|
+
this.onClanMemberUpdate(user.user_ids, true);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
onchannelcreated(channelCreated: ChannelCreatedEvent) {
|
|
369
|
+
console.log(channelCreated);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
onchanneldeleted(channelDeleted: ChannelDeletedEvent) {
|
|
373
|
+
console.log(channelDeleted);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
onchannelupdated(channelUpdated: ChannelUpdatedEvent) {
|
|
377
|
+
console.log(channelUpdated);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
onheartbeattimeout() {
|
|
381
|
+
console.log("Heartbeat timeout.");
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** Receive clan evnet. */
|
|
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
|
+
}
|
|
408
|
+
|
|
409
|
+
};
|