mezon-sdk 2.7.1 → 2.7.2

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/socket.ts ADDED
@@ -0,0 +1,1526 @@
1
+ /**
2
+ * Copyright 2020 The Mezon 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 {Session} from "./session";
18
+ import { WebSocketAdapter, WebSocketAdapterText } from "./web_socket_adapter";
19
+
20
+ /** Stores function references for resolve/reject with a DOM Promise. */
21
+ interface PromiseExecutor {
22
+ resolve: (value?: any) => void;
23
+ reject: (reason?: any) => void;
24
+ }
25
+ /** An object which represents a connected user in the server. */
26
+ export interface Presence {
27
+ /** The id of the user. */
28
+ user_id: string;
29
+ /** The session id of the user. */
30
+ session_id: string;
31
+ /** The username of the user. */
32
+ username: string;
33
+ /** The node the user is connected to. */
34
+ node: string;
35
+ /** The status of the user */
36
+ status: string;
37
+ }
38
+
39
+ /** A response from a channel join operation. */
40
+ export interface Channel {
41
+ /** The server-assigned channel id. */
42
+ id: string;
43
+ // label
44
+ chanel_label: string;
45
+ /** The presences visible on the chat channel. */
46
+ presences: Presence[];
47
+ /** The presence of the current user, i.e. yourself. */
48
+ self: Presence;
49
+ // The ID of the first DM user, or an empty string if this message was not sent through a DM chat.
50
+ clan_logo: string;
51
+ // The ID of the second DM user, or an empty string if this message was not sent through a DM chat.
52
+ category_name: string;
53
+ }
54
+
55
+ export interface ClanJoin {
56
+ clan_join: {
57
+ clan_id: string;
58
+ }
59
+ }
60
+
61
+ /** Join a realtime chat channel. */
62
+ interface ChannelJoin {
63
+ channel_join: {
64
+ /** The id of the channel to join. */
65
+ channel_id: string;
66
+ /** The name of the channel to join. */
67
+ channel_label: string;
68
+ /** The channel type: 1 = Channel, 2 = Direct Message, 3 = Group. */
69
+ type: number;
70
+ /** Whether channel messages are persisted in the database. */
71
+ persistence: boolean;
72
+ /** Whether the user's channel presence is hidden when joining. */
73
+ hidden: boolean;
74
+ };
75
+ }
76
+
77
+ /** Leave a realtime chat channel. */
78
+ interface ChannelLeave {
79
+ channel_leave: {
80
+ /** The id of the channel to leave. */
81
+ channel_id:string;
82
+ // The mode
83
+ mode: number;
84
+ // The channel label
85
+ channel_label: string;
86
+ };
87
+ }
88
+
89
+
90
+ /** A message sent on a channel. */
91
+ export interface ChannelMessage {
92
+ //The unique ID of this message.
93
+ id: string;
94
+ //
95
+ avatar?: string;
96
+ //The channel this message belongs to.
97
+ channel_id: string;
98
+ //The name of the chat room, or an empty string if this message was not sent through a chat room.
99
+ channel_label: string;
100
+ //The clan this message belong to.
101
+ clan_id?: string;
102
+ //The code representing a message type or category.
103
+ code: number;
104
+ //The content payload.
105
+ content: string;
106
+ //The UNIX time (for gRPC clients) or ISO string (for REST clients) when the message was created.
107
+ create_time: string;
108
+ //
109
+ reactions?: Array<ApiMessageReaction>;
110
+ //
111
+ mentions?: Array<ApiMessageMention>;
112
+ //
113
+ attachments?: Array<ApiMessageAttachment>;
114
+ //
115
+ references?: Array<ApiMessageRef>;
116
+ //
117
+ referenced_message?: ChannelMessage;
118
+ //True if the message was persisted to the channel's history, false otherwise.
119
+ persistent?: boolean;
120
+ //Message sender, usually a user ID.
121
+ sender_id: string;
122
+ //The UNIX time (for gRPC clients) or ISO string (for REST clients) when the message was last updated.
123
+ update_time?: string;
124
+ //The ID of the first DM user, or an empty string if this message was not sent through a DM chat.
125
+ clan_logo?: string;
126
+ //The ID of the second DM user, or an empty string if this message was not sent through a DM chat.
127
+ category_name?: string;
128
+ //The username of the message sender, if any.
129
+ username?: string;
130
+ // The clan nick name
131
+ clan_nick?: string;
132
+ // The clan avatar
133
+ clan_avatar?: string;
134
+ //
135
+ display_name?: string;
136
+ //
137
+ create_time_ms?: number;
138
+ //
139
+ update_time_ms?: number;
140
+ //
141
+ mode?: number;
142
+ //
143
+ message_id?: string;
144
+ }
145
+
146
+
147
+ /** */
148
+ export interface ApiMessageAttachment {
149
+ //
150
+ filename?: string;
151
+ //
152
+ filetype?: string;
153
+ //
154
+ height?: number;
155
+ //
156
+ size?: number;
157
+ //
158
+ url?: string;
159
+ //
160
+ width?: number;
161
+ /** The channel this message belongs to. */
162
+ channel_id?:string;
163
+ // The mode
164
+ mode?: number;
165
+ // The channel label
166
+ channel_label?: string;
167
+ /** The message that user react */
168
+ message_id?: string;
169
+ /** Message sender, usually a user ID. */
170
+ sender_id?: string;
171
+ }
172
+
173
+ /** */
174
+ export interface ApiMessageDeleted {
175
+ //
176
+ deletor?: string;
177
+ //
178
+ message_id?: string;
179
+ }
180
+
181
+ /** */
182
+ export interface ApiMessageMention {
183
+ //The UNIX time (for gRPC clients) or ISO string (for REST clients) when the message was created.
184
+ create_time?: string;
185
+ //
186
+ id?: string;
187
+ //
188
+ user_id?: string;
189
+ //
190
+ username?: string;
191
+ // role id
192
+ role_id?: string;
193
+ // role name
194
+ rolename?: string;
195
+ // start position
196
+ s?: number;
197
+ // end position
198
+ e?: number;
199
+ /** The channel this message belongs to. */
200
+ channel_id?:string;
201
+ // The mode
202
+ mode?: number;
203
+ // The channel label
204
+ channel_label?: string;
205
+ /** The message that user react */
206
+ message_id?: string;
207
+ /** Message sender, usually a user ID. */
208
+ sender_id?: string;
209
+ }
210
+
211
+ /** */
212
+ export interface ApiMessageReaction {
213
+ //
214
+ action?: boolean;
215
+ //
216
+ emoji_id: string;
217
+ //
218
+ emoji: string;
219
+ //
220
+ id?: string;
221
+ //
222
+ sender_id?: string;
223
+ //
224
+ sender_name?: string;
225
+ //
226
+ sender_avatar?: string;
227
+ // count of emoji
228
+ count: number;
229
+ /** The channel this message belongs to. */
230
+ channel_id:string;
231
+ // The mode
232
+ mode: number;
233
+ // The channel label
234
+ channel_label: string;
235
+ /** The message that user react */
236
+ message_id: string;
237
+ }
238
+
239
+ /** */
240
+ export interface ApiMessageRef {
241
+ //
242
+ message_id?: string;
243
+ //
244
+ message_ref_id?: string;
245
+ //
246
+ ref_type?: number;
247
+ //
248
+ message_sender_id?: string;
249
+ // original message sendre username
250
+ message_sender_username?: string;
251
+ // original message sender avatar
252
+ mesages_sender_avatar?: string;
253
+ // original sender clan nick name
254
+ message_sender_clan_nick?: string;
255
+ // original sender display name
256
+ message_sender_display_name?:string;
257
+ //
258
+ content?:string;
259
+ //
260
+ has_attachment: boolean;
261
+ /** The channel this message belongs to. */
262
+ channel_id:string;
263
+ // The mode
264
+ mode: number;
265
+ // The channel label
266
+ channel_label: string;
267
+ }
268
+
269
+ /** UserChannelAddedEvent */
270
+ export interface UserChannelAddedEvent {
271
+ // the channel id
272
+ channel_id: string;
273
+ // the user
274
+ users: AddUsers[];
275
+ // the custom status
276
+ status: string;
277
+ // the clan id
278
+ clan_id: string;
279
+ // the channel type
280
+ channel_type: number;
281
+ }
282
+
283
+ export interface AddUsers {
284
+ // User IDs to follow.
285
+ user_id: string;
286
+ // Avatar to follow.
287
+ avatar: string;
288
+ // Username to follow.
289
+ username: string;
290
+ }
291
+
292
+ export interface UserChannelRemovedEvent {
293
+ // the channel id
294
+ channel_id: string;
295
+ // the user_id
296
+ user_ids: string[];
297
+ }
298
+
299
+ export interface UserClanRemovedEvent {
300
+ // the clan id
301
+ clan_id: string;
302
+ // the user_id
303
+ user_ids: string[];
304
+ }
305
+
306
+ /** Last seen message by user */
307
+ export interface LastPinMessageEvent {
308
+ /** The channel this message belongs to. */
309
+ channel_id:string;
310
+ // The mode
311
+ mode: number;
312
+ // The channel label
313
+ channel_label: string;
314
+ /** The unique ID of this message. */
315
+ message_id: string;
316
+ /** user id */
317
+ user_id: string;
318
+ /** operation */
319
+ operation: number;
320
+ }
321
+
322
+ /** Last seen message by user */
323
+ export interface LastSeenMessageEvent {
324
+ /** The channel this message belongs to. */
325
+ channel_id:string;
326
+ // The mode
327
+ mode: number;
328
+ // The channel label
329
+ channel_label: string;
330
+ /** The unique ID of this message. */
331
+ message_id: string;
332
+ }
333
+
334
+ /** User is typing */
335
+ export interface MessageTypingEvent {
336
+ /** The channel this message belongs to. */
337
+ channel_id:string;
338
+ // The mode
339
+ mode: number;
340
+ // The channel label
341
+ channel_label: string;
342
+ /** Message sender, usually a user ID. */
343
+ sender_id: string;
344
+ }
345
+
346
+ // user profile updated event
347
+ export interface UserProfileUpdatedEvent{
348
+ // the user id
349
+ user_id: string;
350
+ // the display_name
351
+ display_name: string;
352
+ // the avatar
353
+ avatar: string;
354
+ // the about_me
355
+ about_me: string;
356
+ // the channel_id
357
+ channel_id: string;
358
+ // the clan_id
359
+ clan_id: string;
360
+ }
361
+
362
+ /** An acknowledgement received in response to sending a message on a chat channel. */
363
+ export interface ChannelMessageAck {
364
+ /** The server-assigned channel ID. */
365
+ channel_id:string;
366
+ // The mode
367
+ mode: number;
368
+ /** A unique ID for the chat message. */
369
+ message_id: string;
370
+ /** A user-defined code for the chat message. */
371
+ code: number;
372
+ /** The username of the sender of the message. */
373
+ username: string;
374
+ /** The UNIX time when the message was created. */
375
+ create_time: string;
376
+ /** The UNIX time when the message was updated. */
377
+ update_time: string;
378
+ /** True if the chat message has been stored in history. */
379
+ persistence: boolean;
380
+ }
381
+
382
+ /** Send a message to a realtime chat channel. */
383
+ interface ChannelMessageSend {
384
+ channel_message_send: {
385
+ /** Clan Id */
386
+ clan_id: string;
387
+ /** The server-assigned channel ID. */
388
+ channel_id:string;
389
+ // The mode
390
+ mode: number;
391
+ // channel label
392
+ channel_label: string;
393
+ /** The content payload. */
394
+ content: any;
395
+ //
396
+ mentions?: Array<ApiMessageMention>;
397
+ //
398
+ attachments?: Array<ApiMessageAttachment>;
399
+ //
400
+ anonymous_message?: boolean;
401
+ //
402
+ mention_everyone?: boolean;
403
+ //
404
+ avatar: string;
405
+ };
406
+ }
407
+
408
+ /** Update a message previously sent to a realtime chat channel. */
409
+ interface ChannelMessageUpdate {
410
+ channel_message_update: {
411
+ /** The server-assigned channel ID. */
412
+ channel_id: string,
413
+ /** The server-assigned channel label. */
414
+
415
+ /** A unique ID for the chat message to be updated. */
416
+ message_id: string,
417
+ /** The content payload. */
418
+ content: any,
419
+ /** mentions */
420
+ mentions?: Array<ApiMessageMention>;
421
+ /** attachments */
422
+ attachments?: Array<ApiMessageAttachment>;
423
+ /** The mode payload. */
424
+ mode: number;
425
+ };
426
+ }
427
+
428
+ /** Remove a message previously sent to a realtime chat channel. */
429
+ interface ChannelMessageRemove {
430
+ channel_message_remove: {
431
+ /** The server-assigned channel ID. */
432
+ channel_id:string;
433
+ // The mode
434
+ mode: number;
435
+ // The channel label
436
+ channel_label: string;
437
+ /** A unique ID for the chat message to be removed. */
438
+ message_id: string;
439
+ };
440
+ }
441
+
442
+ /** Presence update for a particular realtime chat channel. */
443
+ export interface ChannelPresenceEvent {
444
+ /** The unique identifier of the chat channel. */
445
+ channel_id: string;
446
+ // The channel name
447
+ channel_label: string;
448
+ // The mode
449
+ mode: number;
450
+ /** Presences of the users who joined the channel. */
451
+ joins: Presence[];
452
+ /** Presences of users who left the channel. */
453
+ leaves: Presence[];
454
+ }
455
+
456
+ export interface VoiceEndedEvent {
457
+ // id voice
458
+ id: string;
459
+ // The unique identifier of the chat clan.
460
+ clan_id: string;
461
+ // voice channel name
462
+ voice_channel_id: string;
463
+ }
464
+
465
+ export interface VoiceStartedEvent {
466
+ // id voice
467
+ id: string;
468
+ // The unique identifier of the chat clan.
469
+ clan_id: string;
470
+ // voice channel name
471
+ voice_channel_id: string;
472
+ }
473
+
474
+ export interface VoiceLeavedEvent {
475
+ // event id
476
+ id: string;
477
+ // clan id
478
+ clan_id: string;
479
+ // voice channel name
480
+ voice_channel_id: string;
481
+ // voice user id
482
+ voice_user_id: string;
483
+ }
484
+
485
+ export interface VoiceJoinedEvent {
486
+ /** The unique identifier of the chat channel. */
487
+ clan_id: string;
488
+ // The channel name
489
+ clan_name: string;
490
+ // id voice
491
+ id: string;
492
+ // voice participant
493
+ participant: string;
494
+ // user id
495
+ user_id: string;
496
+ // voice channel label
497
+ voice_channel_label: string;
498
+ // voice channel id
499
+ voice_channel_id: string;
500
+ // last screenshot
501
+ last_screenshot: string;
502
+ }
503
+
504
+ export interface CustomStatusEvent {
505
+ // the clan id
506
+ clan_id: string;
507
+ // the user id
508
+ user_id: string;
509
+ // username
510
+ username: string;
511
+ // the status
512
+ status: string;
513
+ }
514
+
515
+ export interface ChannelUpdatedEvent {
516
+ // clan id
517
+ clan_id: string;
518
+ // category
519
+ category_id: string;
520
+ // creator
521
+ creator_id: string;
522
+ // parrent_id
523
+ parrent_id: string;
524
+ // channel id
525
+ channel_id: string;
526
+ // channel label
527
+ channel_label: string;
528
+ // channel type
529
+ channel_type: number;
530
+ // status
531
+ status: number;
532
+ }
533
+
534
+ export interface ChannelCreatedEvent {
535
+ // clan id
536
+ clan_id: string;
537
+ // category
538
+ category_id: string;
539
+ // creator
540
+ creator_id: string;
541
+ // parrent_id
542
+ parrent_id: string;
543
+ // channel id
544
+ channel_id: string;
545
+ // channel label
546
+ channel_label: string;
547
+ // channel private
548
+ channel_private: number;
549
+ // channel type
550
+ channel_type: number;
551
+ // status
552
+ status: number;
553
+ }
554
+
555
+ export interface ChannelDeletedEvent {
556
+ // clan id
557
+ clan_id: string;
558
+ // category
559
+ category_id: string;
560
+ // channel id
561
+ channel_id: string;
562
+ // deletor
563
+ deletor: string;
564
+ }
565
+
566
+ // clan updated event
567
+ export interface ClanUpdatedEvent {
568
+ // the clan id
569
+ clan_id: string;
570
+ // the clan name
571
+ clan_name: string;
572
+ // the clan logo
573
+ clan_logo: string;
574
+ }
575
+
576
+ export interface ClanProfileUpdatedEvent {
577
+ // the user id
578
+ user_id: string;
579
+ // the clan_nick
580
+ clan_nick: string;
581
+ // the avatar
582
+ clan_avatar: string;
583
+ // the clan_id
584
+ clan_id: string;
585
+ }
586
+
587
+ /** Stream identifier */
588
+ export interface StreamId {
589
+ /** The type of stream (e.g. chat). */
590
+ mode: number;
591
+ /** The primary stream subject, usually a user id. */
592
+ subject: string;
593
+ /** A secondary stream subject, for example for a direct chat. */
594
+ descriptor: string;
595
+ /** Meta-information (e.g. chat room name). */
596
+ label: string;
597
+ }
598
+
599
+ /** Stream data. */
600
+ export interface StreamData {
601
+ /** The stream identifier. */
602
+ stream: StreamId;
603
+ /** A reference to the user presence that sent this data, if any. */
604
+ sender?: Presence;
605
+ /** Arbitrary contents of the data message. */
606
+ data: string;
607
+ /** True if this data was delivered reliably. */
608
+ reliable?: boolean;
609
+ }
610
+
611
+ /** Presence updates. */
612
+ export interface StreamPresenceEvent {
613
+ /** The stream identifier. */
614
+ stream: StreamId;
615
+ /** Presences of users who joined the stream. */
616
+ joins: Presence[];
617
+ /** Presences of users who left the stream. */
618
+ leaves: Presence[];
619
+ }
620
+
621
+ /** Execute an Lua function on the server. */
622
+ interface Rpc {
623
+ rpc: ApiRpc;
624
+ }
625
+
626
+ /** Execute an Lua function on the server. */
627
+ export interface ApiRpc {
628
+ //The authentication key used when executed as a non-client HTTP request.
629
+ http_key?: string;
630
+ //The identifier of the function.
631
+ id?: string;
632
+ //The payload of the function which must be a JSON object.
633
+ payload?: string;
634
+ }
635
+
636
+ /** Application-level heartbeat ping. */
637
+ interface Ping {
638
+
639
+ }
640
+
641
+ /** A snapshot of statuses for some set of users. */
642
+ export interface Status {
643
+ /** The user presences to view statuses of. */
644
+ presences: Presence[];
645
+ }
646
+
647
+ /** Start receiving status updates for some set of users. */
648
+ interface StatusFollow {
649
+ /** The IDs of the users to follow. */
650
+ status_follow: {user_ids: string[];}
651
+ }
652
+
653
+ /** A batch of status updates for a given user. */
654
+ export interface StatusPresenceEvent {
655
+ /** This join information is in response to a subscription made to be notified when a user comes online. */
656
+ joins: Presence[];
657
+ /** This join information is in response to a subscription made to be notified when a user goes offline. */
658
+ leaves: Presence[];
659
+ }
660
+
661
+ /** Stop receiving status updates for some set of users. */
662
+ interface StatusUnfollow {
663
+ /** The IDs of user to unfollow. */
664
+ status_unfollow: {user_ids: string[];};
665
+ }
666
+
667
+ /** Set the user's own status. */
668
+ interface StatusUpdate {
669
+ /** Status string to set, if not present the user will appear offline. */
670
+ status_update: {status?: string;};
671
+ }
672
+ export interface ClanNameExistedEvent {
673
+ clan_name: string;
674
+ exist: boolean;
675
+ }
676
+
677
+
678
+ /** */
679
+ export interface StrickerListedEvent {
680
+ // clan id
681
+ clan_id: string;
682
+ // sticker data
683
+ stickers?: Array<ClanSticker>;
684
+ }
685
+
686
+ /** */
687
+ export interface ClanSticker {
688
+ //
689
+ category?: string;
690
+ //
691
+ clan_id?: string;
692
+ //
693
+ create_time?: string;
694
+ //
695
+ creator_id?: string;
696
+ //
697
+ id?: string;
698
+ //
699
+ shortname?: string;
700
+ //
701
+ source?: string;
702
+ }
703
+
704
+ /** */
705
+ export interface EmojiListedEvent {
706
+ // clan id
707
+ clan_id: string;
708
+ // emoji data
709
+ emoji_list?: Array<ClanEmoji>;
710
+ }
711
+
712
+ /** */
713
+ export interface ClanEmoji {
714
+ //
715
+ category?: string;
716
+ //
717
+ creator_id?: string;
718
+ //
719
+ id?: string;
720
+ //
721
+ shortname?: string;
722
+ //
723
+ src?: string;
724
+ }
725
+
726
+ /** */
727
+ export interface ChannelDescListEvent {
728
+ //
729
+ channeldesc?: Array<ChannelDescription>;
730
+ }
731
+
732
+ /** */
733
+ export interface ChannelDescription {
734
+ // The clan of this channel
735
+ clan_id?: string;
736
+ // The channel this message belongs to.
737
+ channel_id?: string;
738
+ // The channel type.
739
+ type?: number;
740
+ // The channel lable
741
+ channel_label?: string;
742
+ // The channel private
743
+ channel_private?: number;
744
+ // meeting code
745
+ meeting_code?: string;
746
+ //
747
+ clan_name?: string;
748
+ //
749
+ parrent_id?: string;
750
+ }
751
+
752
+ // A list of Channel
753
+ export interface HashtagDmListEvent {
754
+ // user Id
755
+ user_id?: Array<string>;
756
+ // Max number of records to return. Between 1 and 100.
757
+ limit?: number;
758
+ // A list of channel.
759
+ hashtag_dm?: Array<HashtagDm>;
760
+ }
761
+
762
+ // hashtagDM
763
+ export interface HashtagDm {
764
+ // The channel id.
765
+ channel_id?: string;
766
+ // The channel lable
767
+ channel_label?: string;
768
+ // The clan of this channel
769
+ clan_id?: string;
770
+ // The clan name
771
+ clan_name?: string;
772
+ //
773
+ meeting_code?: string;
774
+ //
775
+ type?: number;
776
+ //
777
+ channel_private?: number;
778
+ //
779
+ parrent_id?: string;
780
+ }
781
+
782
+ export interface NotificationChannelSettingEvent {
783
+ // The channel id.
784
+ channel_id?: string;
785
+ //
786
+ notification_user_channel?: NotificationUserChannel;
787
+ }
788
+
789
+ export interface NotificationUserChannel {
790
+ //
791
+ active?: number;
792
+ //
793
+ id?: string;
794
+ //
795
+ notification_setting_type?: number;
796
+ //
797
+ time_mute?: string;
798
+ }
799
+
800
+ export interface NotificationCategorySettingEvent {
801
+ //
802
+ category_id?: string;
803
+ //
804
+ notification_user_channel?: NotificationUserChannel;
805
+ }
806
+
807
+ export interface NotificationClanSettingEvent {
808
+ // The clan of this channel
809
+ clan_id?: string;
810
+ //
811
+ notification_setting?: NotificationSetting;
812
+ }
813
+
814
+ export interface NotificationSetting {
815
+ //
816
+ id?: string;
817
+ //
818
+ notification_setting_type?: number;
819
+ }
820
+
821
+ export interface NotifiReactMessageEvent {
822
+ //
823
+ channel_id?: string;
824
+ //
825
+ notifi_react_message?: NotifiReactMessage;
826
+ }
827
+
828
+ export interface NotifiReactMessage {
829
+ //
830
+ id?: string;
831
+ //
832
+ user_id?: string;
833
+ //
834
+ channel_id_req?: string;
835
+ }
836
+
837
+ /** A socket connection to Mezon server. */
838
+ export interface Socket {
839
+ /** Connection is Open */
840
+ isOpen(): boolean;
841
+
842
+ /** Connect to the server. */
843
+ connect(session: Session, createStatus: boolean): Promise<Session>;
844
+
845
+ /** Disconnect from the server. */
846
+ disconnect(fireDisconnectEvent: boolean): void;
847
+
848
+ /** Join a chat channel on the server. */
849
+ joinChat(clan_id: string, channel_id: string, channel_type: number) : Promise<Channel>;
850
+
851
+ /** Leave a chat channel on the server. */
852
+ leaveChat(clan_id: string, channel_id: string, channel_type: number) : Promise<void>;
853
+
854
+ /** Remove a chat message from a chat channel on the server. */
855
+ removeChatMessage(clan_id: string, channel_id: string, mode: number, message_id: string) : Promise<ChannelMessageAck>;
856
+
857
+ /** Execute an RPC function to the server. */
858
+ rpc(id?: string, payload?: string, http_key?: string) : Promise<ApiRpc>
859
+
860
+ /** Update a chat message on a chat channel in the server. */
861
+ updateChatMessage(clan_id: string, channel_id: string, mode: number, message_id : string, content: any, mentions?: Array<ApiMessageMention>, attachments?: Array<ApiMessageAttachment>) : Promise<ChannelMessageAck>;
862
+
863
+ /** Update the status for the current user online. */
864
+ updateStatus(status? : string) : Promise<void>;
865
+
866
+ /** Send a chat message to a chat channel on the server. */
867
+ writeChatMessage(clan_id: string, channel_id: string, mode: number, content?: any, mentions?: Array<ApiMessageMention>, attachments?: Array<ApiMessageAttachment>, references?: Array<ApiMessageRef>, anonymous_message?: boolean, mention_everyone?:boolean, avatar?: string) : Promise<ChannelMessageAck>;
868
+
869
+ /** Send message reaction */
870
+ writeMessageReaction(id: string, clan_id: string, channel_id: string, mode: number, message_id: string, emoji_id: string, emoji: string, count: number, message_sender_id: string, action_delete: boolean) : Promise<ApiMessageReaction>;
871
+
872
+ /** Send custom user status */
873
+ writeCustomStatus(clan_id: string, status: string) : Promise<CustomStatusEvent>;
874
+
875
+ /** Handle disconnect events received from the socket. */
876
+ ondisconnect: (evt: Event) => void;
877
+
878
+ /** Handle error events received from the socket. */
879
+ onerror: (evt: Event) => void;
880
+
881
+
882
+ /**
883
+ * An application-level heartbeat timeout that fires after the client does not receive a pong from the server after the heartbeat interval.
884
+ * Most browsers maintain an internal heartbeat, in which case its unlikely you'll need to use this callback. However, Chrome does not implement an internal heartbeat.
885
+ * We fire this separately from `onclose` because heartbeats fail when there's no connectivity, and many browsers don't fire `onclose` until the closing handshake either succeeds or fails.
886
+ * In any case, be aware that `onclose` will still fire if there is a heartbeat timeout in a potentially delayed manner.
887
+ */
888
+ onheartbeattimeout: () => void;
889
+
890
+ oncustomstatus: (statusEvent: CustomStatusEvent) => void;
891
+
892
+ /** Receive channel message. */
893
+ onchannelmessage: (channelMessage: ChannelMessage) => void;
894
+
895
+ /** Receive reaction event */
896
+ onmessagereaction: (messageReactionEvent: ApiMessageReaction) => void;
897
+
898
+ /** Receive channel presence updates. */
899
+ onchannelpresence: (channelPresence: ChannelPresenceEvent) => void;
900
+
901
+ /** Receive added user event */
902
+ onuserchanneladded: (user: UserChannelAddedEvent) => void;
903
+
904
+ /** Receive update user event */
905
+ onuserprofileupdate: (user: UserProfileUpdatedEvent) => void;
906
+
907
+ /** Receive channel removed user event */
908
+ onuserchannelremoved: (user: UserChannelRemovedEvent) => void;
909
+
910
+ /** Receive clan removed user event */
911
+ onuserclanremoved: (user: UserClanRemovedEvent) => void;
912
+
913
+ // when channel is created
914
+ onchannelcreated: (channelCreated: ChannelCreatedEvent) => void;
915
+
916
+ // when channel is deleted
917
+ onchanneldeleted: (channelDeleted: ChannelDeletedEvent) => void;
918
+
919
+ // when channel is updated
920
+ onchannelupdated: (channelUpdated: ChannelUpdatedEvent) => void;
921
+
922
+ // when clan profile is updated
923
+ onclanprofileupdated: (clanprofile: ClanProfileUpdatedEvent) => void;
924
+
925
+ // when clan is updated
926
+ onclanupdated: (clan: ClanUpdatedEvent) => void;
927
+ }
928
+
929
+ /** Reports an error received from a socket message. */
930
+ export interface SocketError {
931
+ /** The error code. */
932
+ code: number;
933
+ /** A message in English to help developers debug the response. */
934
+ message: string;
935
+ }
936
+
937
+ /** A socket connection to Mezon server implemented with the DOM's WebSocket API. */
938
+ export class DefaultSocket implements Socket {
939
+ public static readonly DefaultHeartbeatTimeoutMs = 10000;
940
+ public static readonly DefaultSendTimeoutMs = 10000;
941
+ public static readonly DefaultConnectTimeoutMs = 30000;
942
+
943
+ private readonly cIds: { [key: string]: PromiseExecutor };
944
+ private nextCid: number;
945
+ private _heartbeatTimeoutMs: number;
946
+
947
+ constructor(
948
+ readonly host: string,
949
+ readonly port: string,
950
+ readonly useSSL: boolean = false,
951
+ public verbose: boolean = false,
952
+ readonly adapter : WebSocketAdapter = new WebSocketAdapterText(),
953
+ readonly sendTimeoutMs : number = DefaultSocket.DefaultSendTimeoutMs
954
+ ) {
955
+ this.cIds = {};
956
+ this.nextCid = 1;
957
+ this._heartbeatTimeoutMs = DefaultSocket.DefaultHeartbeatTimeoutMs;
958
+ }
959
+
960
+ generatecid(): string {
961
+ const cid = this.nextCid.toString();
962
+ ++this.nextCid;
963
+ return cid;
964
+ }
965
+
966
+ isOpen(): boolean {
967
+ return this.adapter.isOpen();
968
+ }
969
+
970
+ connect(session: Session, createStatus: boolean = false, connectTimeoutMs: number = DefaultSocket.DefaultConnectTimeoutMs): Promise<Session> {
971
+ if (this.adapter.isOpen()) {
972
+ return Promise.resolve(session);
973
+ }
974
+
975
+ const scheme = (this.useSSL) ? "wss://" : "ws://";
976
+ this.adapter.connect(scheme, this.host, this.port, createStatus, session.token);
977
+
978
+ this.adapter.onClose = (evt: Event) => {
979
+ this.ondisconnect(evt);
980
+ }
981
+
982
+ this.adapter.onError = (evt: Event) => {
983
+ this.onerror(evt);
984
+ }
985
+
986
+ this.adapter.onMessage = (message: any) => {
987
+ if (this.verbose && window && window.console) {
988
+ console.log("Response: %o", JSON.stringify(message));
989
+ }
990
+
991
+ /** Inbound message from server. */
992
+ if (!message.cid) {
993
+ if (message.voice_started_event) {
994
+ this.onvoicestarted(message.voice_started_event)
995
+ } else if (message.voice_ended_event) {
996
+ this.onvoiceended(message.voice_ended_event)
997
+ } else if (message.voice_joined_event) {
998
+ this.onvoicejoined(message.voice_joined_event)
999
+ } else if (message.voice_leaved_event) {
1000
+ this.onvoiceleaved(message.voice_leaved_event)
1001
+ } else if (message.channel_created_event) {
1002
+ this.onchannelcreated(message.channel_created_event)
1003
+ } else if (message.channel_deleted_event) {
1004
+ this.onchanneldeleted(message.channel_deleted_event)
1005
+ } else if (message.channel_updated_event) {
1006
+ this.onchannelupdated(message.channel_updated_event)
1007
+ } else if (message.clan_profile_updated_event) {
1008
+ this.onclanprofileupdated(message.clan_profile_updated_event)
1009
+ } else if (message.clan_updated_event) {
1010
+ this.onclanupdated(message.clan_updated_event)
1011
+ } else if (message.status_presence_event) {
1012
+ this.onstatuspresence(<StatusPresenceEvent>message.status_presence_event);
1013
+ } else if (message.stream_presence_event) {
1014
+ this.onstreampresence(<StreamPresenceEvent>message.stream_presence_event);
1015
+ } else if (message.stream_data) {
1016
+ this.onstreamdata(<StreamData>message.stream_data);
1017
+ } else if (message.channel_message) {
1018
+ var content, reactions, mentions, attachments, references;
1019
+ try {
1020
+ content = JSON.parse(message.channel_message.content);
1021
+ } catch(e) {
1022
+ //console.log("content is invalid", e)
1023
+ }
1024
+ try {
1025
+ reactions = JSON.parse(message.channel_message.reactions);
1026
+ } catch(e) {
1027
+ //console.log("reactions is invalid", e)
1028
+ }
1029
+ try {
1030
+ mentions = JSON.parse(message.channel_message.mentions);
1031
+ } catch(e) {
1032
+ //console.log("mentions is invalid", e)
1033
+ }
1034
+ try {
1035
+ attachments = JSON.parse(message.channel_message.attachments);
1036
+ } catch(e) {
1037
+ //console.log("attachments is invalid", e)
1038
+ }
1039
+ try {
1040
+ references = JSON.parse(message.channel_message.references);
1041
+ } catch(e) {
1042
+ //console.log("references is invalid", e);
1043
+ }
1044
+ var e: ChannelMessage = {
1045
+ id: message.id,
1046
+ avatar: message.channel_message.avatar,
1047
+ channel_id: message.channel_message.channel_id,
1048
+ mode: message.channel_message.mode,
1049
+ channel_label: message.channel_message.channel_label,
1050
+ clan_id: message.channel_message.clan_id,
1051
+ code: message.channel_message.code,
1052
+ create_time: message.channel_message.create_time,
1053
+ message_id: message.channel_message.message_id,
1054
+ sender_id: message.channel_message.sender_id,
1055
+ update_time: message.channel_message.update_time,
1056
+ clan_logo: message.channel_message.clan_logo,
1057
+ category_name: message.channel_message.category_name,
1058
+ username: message.channel_message.username,
1059
+ clan_nick: message.channel_message.clan_nick,
1060
+ clan_avatar: message.channel_message.clan_avatar,
1061
+ display_name: message.channel_message.display_name,
1062
+ content: content,
1063
+ reactions: reactions,
1064
+ mentions: mentions,
1065
+ attachments: attachments,
1066
+ references: references,
1067
+ };
1068
+ this.onchannelmessage(e);
1069
+ } else if (message.message_typing_event) {
1070
+ this.onmessagetyping(<MessageTypingEvent>message.message_typing_event);
1071
+ } else if (message.message_reaction_event) {
1072
+ this.onmessagereaction(<ApiMessageReaction>message.message_reaction_event);
1073
+ } else if (message.channel_presence_event) {
1074
+ this.onchannelpresence(<ChannelPresenceEvent>message.channel_presence_event);
1075
+ } else if (message.last_pin_message_event) {
1076
+ this.onpinmessage(<LastPinMessageEvent>message.last_pin_message_event);
1077
+ } else if (message.custom_status_event) {
1078
+ this.oncustomstatus(<CustomStatusEvent>message.custom_status_event);
1079
+ } else if (message.user_channel_added_event) {
1080
+ this.onuserchanneladded(<UserChannelAddedEvent>message.user_channel_added_event);
1081
+ } else if (message.user_channel_added_event) {
1082
+ this.onuserprofileupdate(<UserProfileUpdatedEvent>message.user_profile_updated_event);
1083
+ } else if (message.user_profile_updated_event) {
1084
+ this.onuserchannelremoved(<UserChannelRemovedEvent>message.user_channel_removed_event);
1085
+ } else if (message.user_clan_removed_event) {
1086
+ this.onuserclanremoved(<UserClanRemovedEvent>message.user_clan_removed_event);
1087
+ } else {
1088
+ if (this.verbose && window && window.console) {
1089
+ console.log("Unrecognized message received: %o", message);
1090
+ }
1091
+ }
1092
+ } else {
1093
+ const executor = this.cIds[message.cid];
1094
+ if (!executor) {
1095
+ if (this.verbose && window && window.console) {
1096
+ console.error("No promise executor for message: %o", message);
1097
+ }
1098
+ return;
1099
+ }
1100
+ delete this.cIds[message.cid];
1101
+
1102
+ if (message.error) {
1103
+ executor.reject(<SocketError>message.error);
1104
+ } else {
1105
+ executor.resolve(message);
1106
+ }
1107
+ }
1108
+ }
1109
+
1110
+ return new Promise((resolve, reject) => {
1111
+ this.adapter.onOpen = (evt: Event) => {
1112
+ if (this.verbose && window && window.console) {
1113
+ console.log(evt);
1114
+ }
1115
+
1116
+ this.pingPong();
1117
+ resolve(session);
1118
+ }
1119
+ this.adapter.onError = (evt: Event) => {
1120
+ reject(evt);
1121
+ this.adapter.close();
1122
+ }
1123
+
1124
+ setTimeout(() => {
1125
+ // if promise has resolved by now, the reject() is a no-op
1126
+ reject("The socket timed out when trying to connect.");
1127
+ }, connectTimeoutMs);
1128
+ });
1129
+ }
1130
+
1131
+ disconnect(fireDisconnectEvent: boolean = true) {
1132
+ if (this.adapter.isOpen()) {
1133
+ this.adapter.close();
1134
+ }
1135
+ if (fireDisconnectEvent) {
1136
+ this.ondisconnect(<Event>{});
1137
+ }
1138
+ }
1139
+
1140
+ setHeartbeatTimeoutMs(ms : number) {
1141
+ this._heartbeatTimeoutMs = ms;
1142
+ }
1143
+
1144
+ getHeartbeatTimeoutMs() : number {
1145
+ return this._heartbeatTimeoutMs;
1146
+ }
1147
+
1148
+ ondisconnect(evt: Event) {
1149
+ if (this.verbose && window && window.console) {
1150
+ console.log(evt);
1151
+ }
1152
+ }
1153
+
1154
+ onerror(evt: Event) {
1155
+ if (this.verbose && window && window.console) {
1156
+ console.log(evt);
1157
+ }
1158
+ }
1159
+
1160
+ onmessagetyping(messagetyping: MessageTypingEvent) {
1161
+ if (this.verbose && window && window.console) {
1162
+ console.log(messagetyping);
1163
+ }
1164
+ }
1165
+
1166
+ onmessagereaction(messagereaction: ApiMessageReaction) {
1167
+ if (this.verbose && window && window.console) {
1168
+ console.log(messagereaction);
1169
+ }
1170
+ }
1171
+
1172
+ onchannelmessage(channelMessage: ChannelMessage) {
1173
+ if (this.verbose && window && window.console) {
1174
+ console.log(channelMessage);
1175
+ }
1176
+ }
1177
+
1178
+ onchannelpresence(channelPresence: ChannelPresenceEvent) {
1179
+ if (this.verbose && window && window.console) {
1180
+ console.log(channelPresence);
1181
+ }
1182
+ }
1183
+
1184
+ onuserchanneladded(user: UserChannelAddedEvent) {
1185
+ if (this.verbose && window && window.console) {
1186
+ console.log(user);
1187
+ }
1188
+ }
1189
+
1190
+ onuserprofileupdate(user: UserProfileUpdatedEvent) {
1191
+ if (this.verbose && window && window.console) {
1192
+ console.log(user);
1193
+ }
1194
+ }
1195
+
1196
+ onuserchannelremoved(user: UserChannelRemovedEvent) {
1197
+ if (this.verbose && window && window.console) {
1198
+ console.log(user);
1199
+ }
1200
+ }
1201
+
1202
+ onuserclanremoved(user: UserClanRemovedEvent) {
1203
+ if (this.verbose && window && window.console) {
1204
+ console.log(user);
1205
+ }
1206
+ }
1207
+
1208
+ onnotification(notification: Notification) {
1209
+ if (this.verbose && window && window.console) {
1210
+ console.log(notification);
1211
+ }
1212
+ }
1213
+
1214
+ onstatuspresence(statusPresence: StatusPresenceEvent) {
1215
+ if (this.verbose && window && window.console) {
1216
+ console.log(statusPresence);
1217
+ }
1218
+ }
1219
+
1220
+ onpinmessage(pin: LastPinMessageEvent) {
1221
+ if (this.verbose && window && window.console) {
1222
+ console.log(pin);
1223
+ }
1224
+ }
1225
+
1226
+ onvoiceended(voice: VoiceEndedEvent) {
1227
+ if (this.verbose && window && window.console) {
1228
+ console.log(voice);
1229
+ }
1230
+ }
1231
+
1232
+ onvoicestarted(voice: VoiceStartedEvent) {
1233
+ if (this.verbose && window && window.console) {
1234
+ console.log(voice);
1235
+ }
1236
+ }
1237
+
1238
+ onvoicejoined(voiceParticipant: VoiceJoinedEvent) {
1239
+ if (this.verbose && window && window.console) {
1240
+ console.log(voiceParticipant);
1241
+ }
1242
+ }
1243
+
1244
+ onvoiceleaved(voiceParticipant: VoiceLeavedEvent) {
1245
+ if (this.verbose && window && window.console) {
1246
+ console.log(voiceParticipant);
1247
+ }
1248
+ }
1249
+
1250
+ onchannelcreated(channelCreated: ChannelCreatedEvent) {
1251
+ if (this.verbose && window && window.console) {
1252
+ console.log(channelCreated);
1253
+ }
1254
+ }
1255
+
1256
+ onchanneldeleted(channelDeleted: ChannelDeletedEvent) {
1257
+ if (this.verbose && window && window.console) {
1258
+ console.log(channelDeleted);
1259
+ }
1260
+ }
1261
+
1262
+ onchannelupdated(channelUpdated: ChannelUpdatedEvent) {
1263
+ if (this.verbose && window && window.console) {
1264
+ console.log(channelUpdated);
1265
+ }
1266
+ }
1267
+
1268
+ onclanprofileupdated(clanprofile: ClanProfileUpdatedEvent) {
1269
+ if (this.verbose && window && window.console) {
1270
+ console.log(clanprofile);
1271
+ }
1272
+ }
1273
+
1274
+ onclanupdated(clan: ClanUpdatedEvent) {
1275
+ if (this.verbose && window && window.console) {
1276
+ console.log(clan);
1277
+ }
1278
+ }
1279
+
1280
+ onstreampresence(streamPresence: StreamPresenceEvent) {
1281
+ if (this.verbose && window && window.console) {
1282
+ console.log(streamPresence);
1283
+ }
1284
+ }
1285
+
1286
+ onstreamdata(streamData: StreamData) {
1287
+ if (this.verbose && window && window.console) {
1288
+ console.log(streamData);
1289
+ }
1290
+ }
1291
+
1292
+ onheartbeattimeout() {
1293
+ if (this.verbose && window && window.console) {
1294
+ console.log("Heartbeat timeout.");
1295
+ }
1296
+ }
1297
+
1298
+ oncustomstatus(statusEvent: CustomStatusEvent) {
1299
+ if (this.verbose && window && window.console) {
1300
+ console.log(statusEvent);
1301
+ }
1302
+ }
1303
+
1304
+ send(message: ChannelJoin | ChannelLeave | ChannelMessageSend | ChannelMessageUpdate | CustomStatusEvent |
1305
+ ChannelMessageRemove | MessageTypingEvent | LastSeenMessageEvent | Rpc | StatusFollow | StatusUnfollow | StatusUpdate | Ping, sendTimeout = DefaultSocket.DefaultSendTimeoutMs): Promise<any> {
1306
+ const untypedMessage = message as any;
1307
+
1308
+ return new Promise<void>((resolve, reject) => {
1309
+ if (!this.adapter.isOpen()) {
1310
+ reject("Socket connection has not been established yet.");
1311
+ }
1312
+ else {
1313
+ if (untypedMessage.channel_message_send) {
1314
+ untypedMessage.channel_message_send.content = JSON.stringify(untypedMessage.channel_message_send.content);
1315
+ } else if (untypedMessage.channel_message_update) {
1316
+ untypedMessage.channel_message_update.content = JSON.stringify(untypedMessage.channel_message_update.content);
1317
+ }
1318
+
1319
+ const cid = this.generatecid();
1320
+ this.cIds[cid] = {resolve, reject};
1321
+ setTimeout(() => {
1322
+ reject("The socket timed out while waiting for a response.")
1323
+ }, sendTimeout);
1324
+
1325
+ /** Add id for promise executor. */
1326
+ untypedMessage.cid = cid;
1327
+ this.adapter.send(untypedMessage);
1328
+ }
1329
+ });
1330
+ }
1331
+
1332
+ async followUsers(userIds : string[]): Promise<Status> {
1333
+ const response = await this.send({status_follow: {user_ids: userIds}});
1334
+ return response.status;
1335
+ }
1336
+
1337
+ async joinClanChat(clan_id: string): Promise<ClanJoin> {
1338
+
1339
+ const response = await this.send({
1340
+ clan_join: {
1341
+ clan_id: clan_id,
1342
+ }
1343
+ });
1344
+
1345
+ return response.clan_join;
1346
+ }
1347
+
1348
+ async joinChat(clan_id: string, channel_id: string, channel_type: number): Promise<Channel> {
1349
+
1350
+ const response = await this.send({
1351
+ channel_join: {
1352
+ clan_id: clan_id,
1353
+ channel_id: channel_id,
1354
+ channel_type: channel_type,
1355
+ }
1356
+ }
1357
+ );
1358
+
1359
+ return response.channel;
1360
+ }
1361
+
1362
+ leaveChat(clan_id: string, channel_id: string, channel_type: number): Promise<void> {
1363
+ return this.send({channel_leave: {clan_id: clan_id, channel_id: channel_id, channel_type: channel_type}});
1364
+ }
1365
+
1366
+ async removeChatMessage(clan_id: string, channel_id: string, mode: number, message_id: string): Promise<ChannelMessageAck> {
1367
+ const response = await this.send(
1368
+ {
1369
+ channel_message_remove: {
1370
+ clan_id: clan_id,
1371
+ channel_id: channel_id,
1372
+ mode: mode,
1373
+ message_id: message_id
1374
+ }
1375
+ }
1376
+ );
1377
+
1378
+ return response.channel_message_ack;
1379
+ }
1380
+
1381
+ async removePartyMember(party_id: string, member: Presence): Promise<void> {
1382
+ return this.send({party_remove: {
1383
+ party_id: party_id,
1384
+ presence: member
1385
+ }});
1386
+ }
1387
+
1388
+ async rpc(id?: string, payload?: string, http_key?: string): Promise<ApiRpc> {
1389
+ const response = await this.send(
1390
+ {
1391
+ rpc: {
1392
+ id: id,
1393
+ payload: payload,
1394
+ http_key: http_key,
1395
+ }
1396
+ });
1397
+
1398
+ return response.rpc;
1399
+ }
1400
+
1401
+ sendPartyData(party_id: string, op_code: number, data: string | Uint8Array): Promise<void> {
1402
+ return this.send({party_data_send: {party_id: party_id, op_code: op_code, data: data}})
1403
+ }
1404
+
1405
+ unfollowUsers(user_ids : string[]): Promise<void> {
1406
+ return this.send({status_unfollow: {user_ids: user_ids}});
1407
+ }
1408
+
1409
+ async updateChatMessage(clan_id: string, channel_id: string, mode: number, message_id : string, content: any, mentions?: Array<ApiMessageMention>, attachments?: Array<ApiMessageAttachment>): Promise<ChannelMessageAck> {
1410
+ const response = await this.send({channel_message_update: {clan_id: clan_id, channel_id: channel_id, message_id: message_id, content: content, mentions: mentions, attachments: attachments, mode: mode}});
1411
+ return response.channel_message_ack;
1412
+ }
1413
+
1414
+ updateStatus(status?: string): Promise<void> {
1415
+ return this.send({status_update: {status: status}});
1416
+ }
1417
+
1418
+ async writeChatMessage(clan_id: string, channel_id: string, mode: number, content: any, mentions?: Array<ApiMessageMention>, attachments?: Array<ApiMessageAttachment>, references?: Array<ApiMessageRef>, anonymous_message?: boolean, mention_everyone?:Boolean, avatar?: string ): Promise<ChannelMessageAck> {
1419
+ const response = await this.send({channel_message_send: {clan_id: clan_id, channel_id: channel_id, mode: mode, content: content, mentions: mentions, attachments: attachments, references: references, anonymous_message: anonymous_message, mention_everyone: mention_everyone, avatar: avatar}});
1420
+ return response.channel_message_ack;
1421
+ }
1422
+
1423
+ async writeMessageReaction(id: string, clan_id: string, channel_id: string, mode: number, message_id: string, emoji_id: string, emoji: string, count: number, message_sender_id: string, action_delete: boolean): Promise<ApiMessageReaction> {
1424
+ const response = await this.send({message_reaction_event: {id: id, clan_id: clan_id, channel_id: channel_id, mode: mode, message_id: message_id, emoji_id: emoji_id, emoji: emoji, count: count, message_sender_id: message_sender_id, action: action_delete}});
1425
+ return response.message_reaction_event
1426
+ }
1427
+
1428
+ async writeMessageTyping(clan_id: string, channel_id: string, mode: number): Promise<MessageTypingEvent> {
1429
+ const response = await this.send({message_typing_event: {clan_id: clan_id, channel_id: channel_id, mode:mode}});
1430
+ return response.message_typing_event
1431
+ }
1432
+
1433
+ async writeLastSeenMessage(clan_id: string, channel_id: string, mode: number, message_id: string, timestamp: string): Promise<LastSeenMessageEvent> {
1434
+ const response = await this.send({last_seen_message_event: {clan_id: clan_id, channel_id: channel_id, mode: mode, message_id: message_id, timestamp: timestamp}});
1435
+ return response.last_seen_message_event
1436
+ }
1437
+
1438
+ async writeLastPinMessage(clan_id: string, channel_id: string, mode: number, message_id: string, timestamp: string, operation: number): Promise<LastPinMessageEvent> {
1439
+ const response = await this.send({last_pin_message_event: {clan_id: clan_id, channel_id: channel_id, mode: mode, message_id: message_id, timestamp: timestamp, operation: operation}});
1440
+ return response.last_pin_message_event
1441
+ }
1442
+
1443
+ async writeVoiceJoined(id: string, clanId: string, clanName: string, voiceChannelId: string, voiceChannelLabel: string, participant: string, lastScreenshot: string): Promise<VoiceJoinedEvent> {
1444
+ const response = await this.send({voice_joined_event: {clan_id: clanId, clan_name: clanName, id: id, participant: participant, voice_channel_id: voiceChannelId, voice_channel_label: voiceChannelLabel, last_screenshot: lastScreenshot}});
1445
+ return response.voice_joined_event
1446
+ }
1447
+
1448
+ async writeVoiceLeaved(id: string, clanId: string, voiceChannelId: string, voiceUserId: string): Promise<VoiceLeavedEvent> {
1449
+ const response = await this.send({voice_leaved_event: {id: id, clan_id: clanId, voice_channel_id: voiceChannelId, voice_user_id: voiceUserId}});
1450
+ return response.voice_leaved_event
1451
+ }
1452
+
1453
+ async writeCustomStatus(clan_id: string, status: string): Promise<CustomStatusEvent> {
1454
+ const response = await this.send({custom_status_event: {clan_id: clan_id, status: status}});
1455
+ return response.custom_status_event
1456
+ }
1457
+
1458
+ async checkDuplicateClanName(clan_name: string): Promise<ClanNameExistedEvent> {
1459
+ const response = await this.send({clan_name_existed_event: {clan_name: clan_name}});
1460
+ return response.clan_name_existed_event
1461
+ }
1462
+
1463
+ async listClanEmojiByClanId(clan_id: string): Promise<EmojiListedEvent> {
1464
+ const response = await this.send({emojis_listed_event: {clan_id: clan_id}});
1465
+ return response.emojis_listed_event
1466
+ }
1467
+
1468
+ async ListChannelByUserId(): Promise<ChannelDescListEvent> {
1469
+ const response = await this.send({channel_desc_list_event: {}});
1470
+ return response.channel_desc_list_event
1471
+ }
1472
+
1473
+ async hashtagDMList(user_id: Array<string>, limit: number): Promise<HashtagDmListEvent> {
1474
+ const response = await this.send({hashtag_dm_list_event: {user_id: user_id, limit: limit }});
1475
+ return response.hashtag_dm_list_event
1476
+ }
1477
+
1478
+ async listClanStickersByClanId(clan_id: string): Promise<StrickerListedEvent> {
1479
+ const response = await this.send({sticker_listed_event: {clan_id: clan_id}});
1480
+ return response.sticker_listed_event
1481
+ }
1482
+
1483
+ async getNotificationChannelSetting(channel_id: string): Promise<NotificationChannelSettingEvent> {
1484
+ const response = await this.send({notification_channel_setting_event: {channel_id: channel_id}})
1485
+ return response.notification_channel_setting_event
1486
+ }
1487
+
1488
+ async getNotificationCategorySetting(category_id: string): Promise<NotificationCategorySettingEvent> {
1489
+ const response = await this.send({notification_category_setting_event: {category_id: category_id}})
1490
+ return response.notification_category_setting_event
1491
+ }
1492
+
1493
+ async getNotificationClanSetting(clan_id: string): Promise<NotificationClanSettingEvent> {
1494
+ const response = await this.send({notification_clan_setting_event: {clan_id: clan_id}})
1495
+ return response.notification_clan_setting_event
1496
+ }
1497
+
1498
+ async getNotificationReactMessage(channel_id: string): Promise<NotifiReactMessageEvent> {
1499
+ const response = await this.send({notifi_react_message_event: {channel_id: channel_id}})
1500
+ return response.notifi_react_message_event
1501
+ }
1502
+
1503
+ private async pingPong(): Promise<void> {
1504
+ if (!this.adapter.isOpen()) {
1505
+ return;
1506
+ }
1507
+
1508
+ try {
1509
+ await this.send({ping: {}}, this._heartbeatTimeoutMs);
1510
+ } catch {
1511
+ if (this.adapter.isOpen()) {
1512
+ if (window && window.console) {
1513
+ console.error("Server unreachable from heartbeat.");
1514
+ }
1515
+ this.onheartbeattimeout();
1516
+ this.adapter.close();
1517
+ }
1518
+
1519
+ return;
1520
+ }
1521
+
1522
+ // reuse the timeout as the interval for now.
1523
+ // we can separate them out into separate values if needed later.
1524
+ setTimeout(() => this.pingPong(), this._heartbeatTimeoutMs);
1525
+ }
1526
+ };