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/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 { SatoriApi, ApiSession, ApiAuthenticateRequest, ApiEventRequest, ApiAuthenticateLogoutRequest, ApiAuthenticateRefreshRequest, ApiIdentifyRequest, ApiUpdatePropertiesRequest, ApiEvent, ApiUpdateMessageRequest } from "./api.gen";
18
-
19
- import { Session } from "./session";
20
-
21
- const DEFAULT_HOST = "127.0.0.1";
22
- const DEFAULT_PORT = "7450";
23
- const DEFAULT_API_KEY = "defaultkey";
24
- const DEFAULT_TIMEOUT_MS = 7000;
25
- const DEFAULT_EXPIRED_TIMESPAN_MS = 5 * 60 * 1000;
26
-
27
- /** A client for Satori server. */
28
- export class Client {
29
-
30
- /** The expired timespan used to check session lifetime. */
31
- public expiredTimespanMs = DEFAULT_EXPIRED_TIMESPAN_MS;
32
-
33
- /** The low level API client for Nakama server. */
34
- private readonly apiClient: SatoriApi;
35
-
36
- constructor(
37
- readonly apiKey = DEFAULT_API_KEY,
38
- readonly host = DEFAULT_HOST,
39
- readonly port = DEFAULT_PORT,
40
- readonly useSSL = false,
41
- readonly timeout = DEFAULT_TIMEOUT_MS,
42
- readonly autoRefreshSession = true) {
43
- const scheme = (useSSL) ? "https://" : "http://";
44
- const basePath = `${scheme}${host}:${port}`;
45
-
46
- this.apiClient = new SatoriApi(apiKey, basePath, timeout);
47
- }
48
-
49
- /** Authenticate a user with an ID against the server. */
50
- async authenticate(id: string, customProperties?: Record<string, string>, defaultProperties?: Record<string, string>) {
51
-
52
- const request : ApiAuthenticateRequest = {
53
- "id": id,
54
- custom: customProperties,
55
- default: defaultProperties
56
- };
57
-
58
- return this.apiClient.satoriAuthenticate(this.apiKey, "", request).then((apiSession : ApiSession) => {
59
- return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || ""));
60
- });
61
- }
62
-
63
- /** Refresh a user's session using a refresh token retrieved from a previous authentication request. */
64
- async sessionRefresh(session: Session) {
65
-
66
- const request : ApiAuthenticateRefreshRequest = {
67
- "refresh_token": session.refresh_token,
68
- };
69
-
70
- return this.apiClient.satoriAuthenticateRefresh(this.apiKey, "", request).then((apiSession : ApiSession) => {
71
- return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || ""));
72
- });
73
- }
74
-
75
- /** Log out a session, invalidate a refresh token, or log out all sessions/refresh tokens for a user. */
76
- async logout(session: Session) {
77
-
78
- const request : ApiAuthenticateLogoutRequest = {
79
- "token": session.token,
80
- "refresh_token": session.refresh_token
81
- };
82
-
83
- return this.apiClient.satoriAuthenticateLogout(session.token, request).then((response) => {
84
- return Promise.resolve(response !== undefined);
85
- });
86
- }
87
-
88
- /** Publish an event for this session. */
89
- async event(session: Session, event: ApiEvent) {
90
- if (this.autoRefreshSession && session.refresh_token &&
91
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
92
- await this.sessionRefresh(session);
93
- }
94
-
95
- const request : ApiEventRequest = {
96
- events: [event]
97
- };
98
-
99
- return this.apiClient.satoriEvent(session.token, request).then((response) => {
100
- return Promise.resolve(response !== undefined);
101
- });
102
- }
103
-
104
- /** Publish multiple events for this session */
105
- async events(session: Session, events: Array<ApiEvent>) {
106
- if (this.autoRefreshSession && session.refresh_token &&
107
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
108
- await this.sessionRefresh(session);
109
- }
110
-
111
- const request : ApiEventRequest = {
112
- events
113
- };
114
-
115
- return this.apiClient.satoriEvent(session.token, request).then((response) => {
116
- return Promise.resolve(response !== undefined);
117
- });
118
- }
119
-
120
- /** Get or list all available experiments for this identity. */
121
- async getExperiments(session: Session, names?: Array<string>) {
122
- if (this.autoRefreshSession && session.refresh_token &&
123
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
124
- await this.sessionRefresh(session);
125
- }
126
-
127
- return this.apiClient.satoriGetExperiments(session.token, names);
128
- }
129
-
130
- /** Get a single flag for this identity. Throws an error when the flag does not exist. */
131
- async getFlag(session: Session, name: string) {
132
- if (this.autoRefreshSession && session.refresh_token &&
133
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
134
- await this.sessionRefresh(session);
135
- }
136
-
137
- return this.apiClient.satoriGetFlags(session.token, "", "", [name]).then((flagList) => {
138
- let flag = null;
139
-
140
- flagList.flags?.forEach((f) => {
141
- if (f.name === name) {
142
- flag = f;
143
- }
144
- });
145
-
146
- if (flag === null) {
147
- return Promise.reject("Flag does not exist.");
148
- }
149
-
150
- return Promise.resolve(flag);
151
- });
152
- }
153
-
154
-
155
- /** Get a single flag for this identity. */
156
- async getFlagWithFallback(session: Session, name: string, fallbackValue?: string) {
157
- return this.getFlag(session, name)
158
- .then((flag) => {
159
- return flag;
160
- })
161
- .catch(() => {
162
- const flag = {
163
- name,
164
- value: fallbackValue
165
- };
166
-
167
- return Promise.resolve(flag)
168
- });
169
- }
170
-
171
- /** Get a single flag with its configured default value. Throws an error when the flag does not exist. */
172
- async getFlagDefault(name: string) {
173
- return this.apiClient.satoriGetFlags("", this.apiKey, "", [name]).then((flagList) => {
174
- let flag = null;
175
-
176
- flagList.flags?.forEach((f) => {
177
- if (f.name === name) {
178
- flag = f;
179
- }
180
- });
181
-
182
- if (flag === null) {
183
- return Promise.reject("Flag does not exist.");
184
- }
185
-
186
- return Promise.resolve(flag);
187
- });
188
- }
189
-
190
- /** Get a single flag with its configured default value. */
191
- async getFlagDefaultWithFallback(name: string, fallbackValue?: string) {
192
- return this.getFlagDefault(name)
193
- .then((flag) => {
194
- return flag;
195
- })
196
- .catch(() => {
197
- const flag = {
198
- name,
199
- value: fallbackValue
200
- };
201
-
202
- return Promise.resolve(flag)
203
- });
204
- }
205
-
206
- /** List all available flags for this identity. */
207
- async getFlags(session: Session, names?: Array<string>) {
208
- if (this.autoRefreshSession && session.refresh_token &&
209
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
210
- await this.sessionRefresh(session);
211
- }
212
-
213
- return this.apiClient.satoriGetFlags(session.token, "", "", names);
214
- }
215
-
216
- /** List all available default flags. */
217
- async getFlagsDefault(names?: Array<string>) {
218
- return this.apiClient.satoriGetFlags("", this.apiKey, "", names);
219
- }
220
-
221
- /** Enrich/replace the current session with new identifier. */
222
- async identify(session: Session, id: string, defaultProperties?: Record<string, string>, customProperties?: Record<string, string>) {
223
- if (this.autoRefreshSession && session.refresh_token &&
224
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
225
- await this.sessionRefresh(session);
226
- }
227
-
228
- const request : ApiIdentifyRequest = {
229
- id: id,
230
- default: defaultProperties,
231
- custom: customProperties
232
- };
233
-
234
- return this.apiClient.satoriIdentify(session.token, request).then((apiSession: ApiSession) => {
235
- return Promise.resolve(new Session(apiSession.token || "", apiSession.refresh_token || ""));
236
- });
237
- }
238
-
239
- /** List available live events. */
240
- async getLiveEvents(session: Session, names?: Array<string>) {
241
- if (this.autoRefreshSession && session.refresh_token &&
242
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
243
- await this.sessionRefresh(session);
244
- }
245
-
246
- return this.apiClient.satoriGetLiveEvents(session.token, names);
247
- }
248
-
249
- /** List properties associated with this identity. */
250
- async listProperties(session: Session) {
251
- if (this.autoRefreshSession && session.refresh_token &&
252
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
253
- await this.sessionRefresh(session);
254
- }
255
-
256
- return this.apiClient.satoriListProperties(session.token);
257
- }
258
-
259
- /** Update identity properties. */
260
- async updateProperties(session: Session, defaultProperties?: Record<string, string>, customProperties?: Record<string, string>, recompute?: boolean) {
261
- if (this.autoRefreshSession && session.refresh_token &&
262
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
263
- await this.sessionRefresh(session);
264
- }
265
-
266
- const request : ApiUpdatePropertiesRequest = {
267
- default: defaultProperties,
268
- custom: customProperties,
269
- recompute: recompute,
270
- };
271
-
272
- return this.apiClient.satoriUpdateProperties(session.token, request).then((response) => {
273
- return Promise.resolve(response !== undefined);
274
- });
275
- }
276
-
277
- /** Delete the caller's identity and associated data. */
278
- async deleteIdentity(session: Session) {
279
- if (this.autoRefreshSession && session.refresh_token &&
280
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
281
- await this.sessionRefresh(session);
282
- }
283
-
284
- return this.apiClient.satoriDeleteIdentity(session.token).then((response) => {
285
- return Promise.resolve(response !== undefined);
286
- });
287
- }
288
-
289
- async getMessageList(session : Session) {
290
- if (this.autoRefreshSession && session.refresh_token &&
291
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
292
- await this.sessionRefresh(session);
293
- }
294
-
295
- return this.apiClient.satoriGetMessageList(session.token).then((response) => {
296
- return Promise.resolve(response !== undefined);
297
- });
298
- }
299
-
300
- async deleteMessage(session : Session, id : string) {
301
- if (this.autoRefreshSession && session.refresh_token &&
302
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
303
- await this.sessionRefresh(session);
304
- }
305
-
306
- return this.apiClient.satoriDeleteMessage(session.token, id).then((response) => {
307
- return Promise.resolve(response !== undefined);
308
- });
309
- }
310
-
311
- async updateMessage(session : Session, id : string, consume_time? : string, read_time? : string) {
312
- if (this.autoRefreshSession && session.refresh_token &&
313
- session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) {
314
- await this.sessionRefresh(session);
315
- }
316
-
317
- const request : ApiUpdateMessageRequest = {
318
- id: id,
319
- consume_time: consume_time,
320
- read_time: read_time
321
- };
322
-
323
- return this.apiClient.satoriUpdateMessage(session.token, id, request).then((response) => {
324
- return Promise.resolve(response !== undefined);
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
+ };