mezon-js 2.9.69 → 2.9.71
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/mezon-js.cjs.js +234 -64
- package/dist/mezon-js.esm.mjs +234 -64
- package/dist/socket.d.ts +14 -3
- package/dist/web_socket_adapter.d.ts +8 -0
- package/package.json +1 -1
- package/socket.ts +627 -227
- package/web_socket_adapter.ts +141 -102
package/socket.ts
CHANGED
@@ -14,7 +14,20 @@
|
|
14
14
|
* limitations under the License.
|
15
15
|
*/
|
16
16
|
|
17
|
-
import {
|
17
|
+
import {
|
18
|
+
ApiChannelMessageHeader,
|
19
|
+
ApiCreateEventRequest,
|
20
|
+
ApiGiveCoffeeEvent,
|
21
|
+
ApiMessageAttachment,
|
22
|
+
ApiMessageMention,
|
23
|
+
ApiMessageReaction,
|
24
|
+
ApiMessageRef,
|
25
|
+
ApiNotification,
|
26
|
+
ApiPermissionUpdate,
|
27
|
+
ApiRole,
|
28
|
+
ApiRpc,
|
29
|
+
ApiTokenSentEvent,
|
30
|
+
} from "./api.gen";
|
18
31
|
import { Session } from "./session";
|
19
32
|
import { ChannelMessage, Notification } from "./client";
|
20
33
|
import { WebSocketAdapter, WebSocketAdapterText } from "./web_socket_adapter";
|
@@ -37,7 +50,7 @@ export interface Presence {
|
|
37
50
|
/** The status of the user */
|
38
51
|
status: string;
|
39
52
|
//
|
40
|
-
is_mobile: boolean
|
53
|
+
is_mobile: boolean;
|
41
54
|
}
|
42
55
|
|
43
56
|
/** A response from a channel join operation. */
|
@@ -59,7 +72,7 @@ export interface Channel {
|
|
59
72
|
export interface ClanJoin {
|
60
73
|
clan_join: {
|
61
74
|
clan_id: string;
|
62
|
-
}
|
75
|
+
};
|
63
76
|
}
|
64
77
|
|
65
78
|
/** Join a realtime chat channel. */
|
@@ -84,7 +97,7 @@ interface ChannelJoin {
|
|
84
97
|
interface ChannelLeave {
|
85
98
|
channel_leave: {
|
86
99
|
/** The id of the channel to leave. */
|
87
|
-
channel_id:string;
|
100
|
+
channel_id: string;
|
88
101
|
// The mode
|
89
102
|
mode: number;
|
90
103
|
// The channel label
|
@@ -142,7 +155,7 @@ export interface UserChannelRemovedEvent {
|
|
142
155
|
// the user_id
|
143
156
|
user_ids: string[];
|
144
157
|
// the channel type
|
145
|
-
channel_type: number
|
158
|
+
channel_type: number;
|
146
159
|
}
|
147
160
|
|
148
161
|
export interface UserClanRemovedEvent {
|
@@ -155,7 +168,7 @@ export interface UserClanRemovedEvent {
|
|
155
168
|
/** Last seen message by user */
|
156
169
|
export interface LastPinMessageEvent {
|
157
170
|
/** The channel this message belongs to. */
|
158
|
-
channel_id:string;
|
171
|
+
channel_id: string;
|
159
172
|
// The mode
|
160
173
|
mode: number;
|
161
174
|
// The channel label
|
@@ -196,7 +209,7 @@ export interface LastSeenMessageEvent {
|
|
196
209
|
/** User is typing */
|
197
210
|
export interface MessageTypingEvent {
|
198
211
|
/** The channel this message belongs to. */
|
199
|
-
channel_id:string;
|
212
|
+
channel_id: string;
|
200
213
|
// The mode
|
201
214
|
mode: number;
|
202
215
|
// The channel label
|
@@ -208,14 +221,14 @@ export interface MessageTypingEvent {
|
|
208
221
|
}
|
209
222
|
|
210
223
|
// user profile updated event
|
211
|
-
export interface UserProfileUpdatedEvent{
|
224
|
+
export interface UserProfileUpdatedEvent {
|
212
225
|
// the user id
|
213
226
|
user_id: string;
|
214
227
|
// the display_name
|
215
228
|
display_name: string;
|
216
229
|
// the avatar
|
217
230
|
avatar: string;
|
218
|
-
// the about_me
|
231
|
+
// the about_me
|
219
232
|
about_me: string;
|
220
233
|
// the channel_id
|
221
234
|
channel_id: string;
|
@@ -226,7 +239,7 @@ export interface UserProfileUpdatedEvent{
|
|
226
239
|
/** An acknowledgement received in response to sending a message on a chat channel. */
|
227
240
|
export interface ChannelMessageAck {
|
228
241
|
/** The server-assigned channel ID. */
|
229
|
-
channel_id:string;
|
242
|
+
channel_id: string;
|
230
243
|
// The mode
|
231
244
|
mode: number;
|
232
245
|
/** A unique ID for the chat message. */
|
@@ -249,7 +262,7 @@ interface ChannelMessageSend {
|
|
249
262
|
/** Clan Id */
|
250
263
|
clan_id: string;
|
251
264
|
/** The server-assigned channel ID. */
|
252
|
-
channel_id:string;
|
265
|
+
channel_id: string;
|
253
266
|
// The mode
|
254
267
|
mode: number;
|
255
268
|
// channel label
|
@@ -275,11 +288,11 @@ interface ChannelMessageSend {
|
|
275
288
|
interface ChannelMessageUpdate {
|
276
289
|
channel_message_update: {
|
277
290
|
/** The server-assigned channel ID. */
|
278
|
-
channel_id: string
|
291
|
+
channel_id: string;
|
279
292
|
/** A unique ID for the chat message to be updated. */
|
280
|
-
message_id: string
|
293
|
+
message_id: string;
|
281
294
|
/** The content payload. */
|
282
|
-
content: any
|
295
|
+
content: any;
|
283
296
|
/** mentions */
|
284
297
|
mentions?: Array<ApiMessageMention>;
|
285
298
|
/** attachments */
|
@@ -368,7 +381,7 @@ export interface VoiceJoinedEvent {
|
|
368
381
|
// voice channel id
|
369
382
|
voice_channel_id: string;
|
370
383
|
// last screenshot
|
371
|
-
last_screenshot: string;
|
384
|
+
last_screenshot: string;
|
372
385
|
}
|
373
386
|
|
374
387
|
export interface CustomStatusEvent {
|
@@ -457,7 +470,7 @@ export interface StickerCreateEvent {
|
|
457
470
|
// logo
|
458
471
|
logo: string;
|
459
472
|
// clan name
|
460
|
-
clan_name: string
|
473
|
+
clan_name: string;
|
461
474
|
}
|
462
475
|
|
463
476
|
export interface StickerUpdateEvent {
|
@@ -500,7 +513,7 @@ export interface ClanProfileUpdatedEvent {
|
|
500
513
|
clan_nick: string;
|
501
514
|
// the avatar
|
502
515
|
clan_avatar: string;
|
503
|
-
// the clan_id
|
516
|
+
// the clan_id
|
504
517
|
clan_id: string;
|
505
518
|
}
|
506
519
|
|
@@ -544,9 +557,7 @@ interface Rpc {
|
|
544
557
|
}
|
545
558
|
|
546
559
|
/** Application-level heartbeat ping. */
|
547
|
-
interface Ping {
|
548
|
-
|
549
|
-
}
|
560
|
+
interface Ping {}
|
550
561
|
|
551
562
|
/** A snapshot of statuses for some set of users. */
|
552
563
|
export interface Status {
|
@@ -557,7 +568,7 @@ export interface Status {
|
|
557
568
|
/** Start receiving status updates for some set of users. */
|
558
569
|
interface StatusFollow {
|
559
570
|
/** The IDs of the users to follow. */
|
560
|
-
status_follow: {user_ids: string[];
|
571
|
+
status_follow: { user_ids: string[] };
|
561
572
|
}
|
562
573
|
|
563
574
|
/** A batch of status updates for a given user. */
|
@@ -571,18 +582,18 @@ export interface StatusPresenceEvent {
|
|
571
582
|
/** Stop receiving status updates for some set of users. */
|
572
583
|
interface StatusUnfollow {
|
573
584
|
/** The IDs of user to unfollow. */
|
574
|
-
status_unfollow: {user_ids: string[]
|
585
|
+
status_unfollow: { user_ids: string[] };
|
575
586
|
}
|
576
587
|
|
577
588
|
/** Set the user's own status. */
|
578
589
|
interface StatusUpdate {
|
579
590
|
/** Status string to set, if not present the user will appear offline. */
|
580
|
-
status_update: {status?: string
|
591
|
+
status_update: { status?: string };
|
581
592
|
}
|
582
593
|
export interface CheckNameExistedEvent {
|
583
594
|
clan_name: string;
|
584
595
|
exist: boolean;
|
585
|
-
condition_id
|
596
|
+
condition_id: string;
|
586
597
|
type: number;
|
587
598
|
}
|
588
599
|
|
@@ -615,15 +626,15 @@ export interface RoleEvent {
|
|
615
626
|
}
|
616
627
|
|
617
628
|
export interface EventEmoji {
|
618
|
-
id
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
user_id: string
|
625
|
-
logo: string
|
626
|
-
clan_name: string
|
629
|
+
id: string;
|
630
|
+
clan_id: string;
|
631
|
+
short_name: string;
|
632
|
+
source: string;
|
633
|
+
category: string;
|
634
|
+
action: number;
|
635
|
+
user_id: string;
|
636
|
+
logo: string;
|
637
|
+
clan_name: string;
|
627
638
|
}
|
628
639
|
|
629
640
|
/** */
|
@@ -698,16 +709,16 @@ export interface NotificationSetting {
|
|
698
709
|
}
|
699
710
|
|
700
711
|
export interface NotificationChannelCategorySetting {
|
701
|
-
// Notification id
|
712
|
+
// Notification id
|
702
713
|
id: string;
|
703
714
|
//
|
704
|
-
channel_category_label
|
715
|
+
channel_category_label: string;
|
705
716
|
// Notification title
|
706
|
-
notification_setting_type
|
717
|
+
notification_setting_type: number;
|
707
718
|
//
|
708
|
-
channel_category_title
|
719
|
+
channel_category_title: string;
|
709
720
|
//
|
710
|
-
action: number
|
721
|
+
action: number;
|
711
722
|
}
|
712
723
|
|
713
724
|
export interface UserEmojiUsage {
|
@@ -803,7 +814,7 @@ export interface PermissionSet {
|
|
803
814
|
caller: string;
|
804
815
|
}
|
805
816
|
|
806
|
-
export interface PermissionChangedEvent{
|
817
|
+
export interface PermissionChangedEvent {
|
807
818
|
user_id: string;
|
808
819
|
channel_id: string;
|
809
820
|
}
|
@@ -811,9 +822,15 @@ export interface PermissionChangedEvent{
|
|
811
822
|
export interface MessageButtonClicked {
|
812
823
|
message_id: string;
|
813
824
|
channel_id: string;
|
814
|
-
button_id
|
815
|
-
sender_id
|
816
|
-
user_id
|
825
|
+
button_id: string;
|
826
|
+
sender_id: string;
|
827
|
+
user_id: string;
|
828
|
+
}
|
829
|
+
|
830
|
+
export interface WebrtcSignalingFwd {
|
831
|
+
receiverId: string;
|
832
|
+
dataType: number;
|
833
|
+
jsonData: string;
|
817
834
|
}
|
818
835
|
|
819
836
|
/** A socket connection to Mezon server. */
|
@@ -822,61 +839,152 @@ export interface Socket {
|
|
822
839
|
isOpen(): boolean;
|
823
840
|
|
824
841
|
/** Connect to the server. */
|
825
|
-
connect(
|
842
|
+
connect(
|
843
|
+
session: Session,
|
844
|
+
createStatus: boolean,
|
845
|
+
platform: string,
|
846
|
+
connectTimeoutMs?: number,
|
847
|
+
signal?: AbortSignal
|
848
|
+
): Promise<Session>;
|
826
849
|
|
827
850
|
/** Disconnect from the server. */
|
828
851
|
disconnect(fireDisconnectEvent: boolean): void;
|
829
852
|
|
830
853
|
/** Subscribe to one or more users for their status updates. */
|
831
|
-
followUsers(user_ids: string[])
|
854
|
+
followUsers(user_ids: string[]): Promise<Status>;
|
832
855
|
|
833
856
|
/** Join clan chat */
|
834
|
-
joinClanChat(clan_id: string)
|
857
|
+
joinClanChat(clan_id: string): Promise<ClanJoin>;
|
835
858
|
|
836
859
|
/** Join a chat channel on the server. */
|
837
|
-
joinChat(
|
860
|
+
joinChat(
|
861
|
+
clan_id: string,
|
862
|
+
channel_id: string,
|
863
|
+
channel_type: number,
|
864
|
+
is_public: boolean
|
865
|
+
): Promise<Channel>;
|
838
866
|
|
839
867
|
/** Leave a chat channel on the server. */
|
840
|
-
leaveChat(
|
868
|
+
leaveChat(
|
869
|
+
clan_id: string,
|
870
|
+
channel_id: string,
|
871
|
+
channel_type: number,
|
872
|
+
is_public: boolean
|
873
|
+
): Promise<void>;
|
841
874
|
|
842
875
|
/** Remove a chat message from a chat channel on the server. */
|
843
|
-
removeChatMessage(
|
876
|
+
removeChatMessage(
|
877
|
+
clan_id: string,
|
878
|
+
channel_id: string,
|
879
|
+
mode: number,
|
880
|
+
is_public: boolean,
|
881
|
+
message_id: string
|
882
|
+
): Promise<ChannelMessageAck>;
|
844
883
|
|
845
884
|
/** Execute an RPC function to the server. */
|
846
|
-
rpc(id?: string, payload?: string, http_key?: string)
|
885
|
+
rpc(id?: string, payload?: string, http_key?: string): Promise<ApiRpc>;
|
847
886
|
|
848
887
|
/** Unfollow one or more users from their status updates. */
|
849
|
-
unfollowUsers(user_ids
|
888
|
+
unfollowUsers(user_ids: string[]): Promise<void>;
|
850
889
|
|
851
890
|
/** Update a chat message on a chat channel in the server. */
|
852
|
-
updateChatMessage(
|
891
|
+
updateChatMessage(
|
892
|
+
clan_id: string,
|
893
|
+
channel_id: string,
|
894
|
+
mode: number,
|
895
|
+
is_public: boolean,
|
896
|
+
message_id: string,
|
897
|
+
content: any,
|
898
|
+
mentions?: Array<ApiMessageMention>,
|
899
|
+
attachments?: Array<ApiMessageAttachment>,
|
900
|
+
hideEditted?: boolean
|
901
|
+
): Promise<ChannelMessageAck>;
|
853
902
|
|
854
903
|
/** Update the status for the current user online. */
|
855
|
-
updateStatus(status?: string)
|
904
|
+
updateStatus(status?: string): Promise<void>;
|
856
905
|
|
857
906
|
/** Send a chat message to a chat channel on the server. */
|
858
|
-
writeChatMessage(
|
907
|
+
writeChatMessage(
|
908
|
+
clan_id: string,
|
909
|
+
channel_id: string,
|
910
|
+
mode: number,
|
911
|
+
is_public: boolean,
|
912
|
+
content?: any,
|
913
|
+
mentions?: Array<ApiMessageMention>,
|
914
|
+
attachments?: Array<ApiMessageAttachment>,
|
915
|
+
references?: Array<ApiMessageRef>,
|
916
|
+
anonymous_message?: boolean,
|
917
|
+
mention_everyone?: boolean,
|
918
|
+
avatar?: string
|
919
|
+
): Promise<ChannelMessageAck>;
|
859
920
|
|
860
921
|
/** Send message typing */
|
861
|
-
writeMessageTyping(
|
922
|
+
writeMessageTyping(
|
923
|
+
clan_id: string,
|
924
|
+
channel_id: string,
|
925
|
+
mode: number,
|
926
|
+
is_public: boolean
|
927
|
+
): Promise<MessageTypingEvent>;
|
862
928
|
|
863
929
|
/** Send message reaction */
|
864
|
-
writeMessageReaction(
|
930
|
+
writeMessageReaction(
|
931
|
+
id: string,
|
932
|
+
clan_id: string,
|
933
|
+
channel_id: string,
|
934
|
+
mode: number,
|
935
|
+
is_public: boolean,
|
936
|
+
message_id: string,
|
937
|
+
emoji_id: string,
|
938
|
+
emoji: string,
|
939
|
+
count: number,
|
940
|
+
message_sender_id: string,
|
941
|
+
action_delete: boolean
|
942
|
+
): Promise<ApiMessageReaction>;
|
865
943
|
|
866
944
|
/** Send last seen message */
|
867
|
-
writeLastSeenMessage(
|
945
|
+
writeLastSeenMessage(
|
946
|
+
clan_id: string,
|
947
|
+
channel_id: string,
|
948
|
+
mode: number,
|
949
|
+
message_id: string,
|
950
|
+
timestamp_seconds: number
|
951
|
+
): Promise<LastSeenMessageEvent>;
|
868
952
|
|
869
953
|
/** Send last pin message */
|
870
|
-
writeLastPinMessage(
|
954
|
+
writeLastPinMessage(
|
955
|
+
clan_id: string,
|
956
|
+
channel_id: string,
|
957
|
+
mode: number,
|
958
|
+
is_public: boolean,
|
959
|
+
message_id: string,
|
960
|
+
timestamp_seconds: number,
|
961
|
+
operation: number
|
962
|
+
): Promise<LastPinMessageEvent>;
|
871
963
|
|
872
964
|
/** Send custom user status */
|
873
|
-
writeCustomStatus(
|
965
|
+
writeCustomStatus(
|
966
|
+
clan_id: string,
|
967
|
+
status: string
|
968
|
+
): Promise<CustomStatusEvent>;
|
874
969
|
|
875
970
|
/** send voice joined */
|
876
|
-
writeVoiceJoined(
|
971
|
+
writeVoiceJoined(
|
972
|
+
id: string,
|
973
|
+
clanId: string,
|
974
|
+
clanName: string,
|
975
|
+
voiceChannelId: string,
|
976
|
+
voiceChannelLabel: string,
|
977
|
+
participant: string,
|
978
|
+
lastScreenshot: string
|
979
|
+
): Promise<VoiceJoinedEvent>;
|
877
980
|
|
878
981
|
/** send voice leaved */
|
879
|
-
writeVoiceLeaved(
|
982
|
+
writeVoiceLeaved(
|
983
|
+
id: string,
|
984
|
+
clanId: string,
|
985
|
+
voiceChannelId: string,
|
986
|
+
voiceUserId: string
|
987
|
+
): Promise<VoiceLeavedEvent>;
|
880
988
|
|
881
989
|
/** Handle disconnect events received from the socket. */
|
882
990
|
ondisconnect: (evt: Event) => void;
|
@@ -920,7 +1028,7 @@ export interface Socket {
|
|
920
1028
|
|
921
1029
|
/** pin message event */
|
922
1030
|
onpinmessage: (pin: LastPinMessageEvent) => void;
|
923
|
-
|
1031
|
+
|
924
1032
|
/** Receive added user event */
|
925
1033
|
onuserchanneladded: (user: UserChannelAddedEvent) => void;
|
926
1034
|
|
@@ -938,13 +1046,13 @@ export interface Socket {
|
|
938
1046
|
|
939
1047
|
// when someone start the voice room
|
940
1048
|
onvoicestarted: (voice: VoiceStartedEvent) => void;
|
941
|
-
|
1049
|
+
|
942
1050
|
// when someone end the voice room
|
943
1051
|
onvoiceended: (voice: VoiceEndedEvent) => void;
|
944
1052
|
|
945
1053
|
// when someone join to voice room
|
946
1054
|
onvoicejoined: (voiceParticipant: VoiceJoinedEvent) => void;
|
947
|
-
|
1055
|
+
|
948
1056
|
// when someone join to voice room
|
949
1057
|
onvoiceleaved: (voiceParticipant: VoiceLeavedEvent) => void;
|
950
1058
|
|
@@ -978,17 +1086,31 @@ export interface Socket {
|
|
978
1086
|
onclanupdated: (clan: ClanUpdatedEvent) => void;
|
979
1087
|
|
980
1088
|
// when user update last seen message
|
981
|
-
onlastseenupdated: (event: LastSeenMessageEvent)
|
1089
|
+
onlastseenupdated: (event: LastSeenMessageEvent) => void;
|
982
1090
|
|
983
1091
|
/* Set the heartbeat timeout used by the socket to detect if it has lost connectivity to the server. */
|
984
|
-
setHeartbeatTimeoutMs(ms
|
1092
|
+
setHeartbeatTimeoutMs(ms: number): void;
|
985
1093
|
|
986
1094
|
/* Get the heartbeat timeout used by the socket to detect if it has lost connectivity to the server. */
|
987
|
-
getHeartbeatTimeoutMs()
|
1095
|
+
getHeartbeatTimeoutMs(): number;
|
1096
|
+
|
1097
|
+
checkDuplicateName(
|
1098
|
+
name: string,
|
1099
|
+
condition_id: string,
|
1100
|
+
type: number
|
1101
|
+
): Promise<CheckNameExistedEvent>;
|
988
1102
|
|
989
|
-
|
1103
|
+
handleMessageButtonClick: (message_id: string,
|
1104
|
+
channel_id: string,
|
1105
|
+
button_id: string,
|
1106
|
+
sender_id: string,
|
1107
|
+
user_id: string) => Promise<MessageButtonClicked>;
|
1108
|
+
|
1109
|
+
onmessagebuttonclicked: (event: MessageButtonClicked) => void;
|
990
1110
|
|
991
|
-
|
1111
|
+
forwardWebrtcSignaling: (receiverId: string, dataType: number, jsonData: string) => Promise<WebrtcSignalingFwd>;
|
1112
|
+
|
1113
|
+
onwebrtcsignalingfwd: (event: WebrtcSignalingFwd) => void;
|
992
1114
|
|
993
1115
|
oneventcreated: (clan_event_created: ApiCreateEventRequest) => void;
|
994
1116
|
|
@@ -998,21 +1120,29 @@ export interface Socket {
|
|
998
1120
|
|
999
1121
|
onroleassign: (role_assign_event: RoleAssignedEvent) => void;
|
1000
1122
|
|
1001
|
-
onstreamingchannelstarted: (
|
1123
|
+
onstreamingchannelstarted: (
|
1124
|
+
streaming_started_event: StreamingStartedEvent
|
1125
|
+
) => void;
|
1002
1126
|
|
1003
1127
|
onstreamingchannelended: (streaming_ended_event: StreamingEndedEvent) => void;
|
1004
1128
|
|
1005
|
-
onstreamingchanneljoined: (
|
1129
|
+
onstreamingchanneljoined: (
|
1130
|
+
streaming_joined_event: StreamingJoinedEvent
|
1131
|
+
) => void;
|
1006
1132
|
|
1007
|
-
onstreamingchannelleaved: (
|
1133
|
+
onstreamingchannelleaved: (
|
1134
|
+
streaming_leaved_event: StreamingLeavedEvent
|
1135
|
+
) => void;
|
1008
1136
|
|
1009
1137
|
onpermissionset: (permission_set_event: PermissionSet) => void;
|
1010
1138
|
|
1011
|
-
onpermissionchanged: (
|
1139
|
+
onpermissionchanged: (
|
1140
|
+
permission_changed_event: PermissionChangedEvent
|
1141
|
+
) => void;
|
1012
1142
|
|
1013
1143
|
onunmuteevent: (unmute_event: UnmuteEvent) => void;
|
1014
1144
|
|
1015
|
-
ontokensent: (token: ApiTokenSentEvent) => void;
|
1145
|
+
ontokensent: (token: ApiTokenSentEvent) => void;
|
1016
1146
|
}
|
1017
1147
|
|
1018
1148
|
/** Reports an error received from a socket message. */
|
@@ -1034,13 +1164,13 @@ export class DefaultSocket implements Socket {
|
|
1034
1164
|
private _heartbeatTimeoutMs: number;
|
1035
1165
|
|
1036
1166
|
constructor(
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1167
|
+
readonly host: string,
|
1168
|
+
readonly port: string,
|
1169
|
+
readonly useSSL: boolean = false,
|
1170
|
+
public verbose: boolean = false,
|
1171
|
+
readonly adapter: WebSocketAdapter = new WebSocketAdapterText(),
|
1172
|
+
readonly sendTimeoutMs: number = DefaultSocket.DefaultSendTimeoutMs
|
1173
|
+
) {
|
1044
1174
|
this.cIds = {};
|
1045
1175
|
this.nextCid = 1;
|
1046
1176
|
this._heartbeatTimeoutMs = DefaultSocket.DefaultHeartbeatTimeoutMs;
|
@@ -1056,23 +1186,37 @@ export class DefaultSocket implements Socket {
|
|
1056
1186
|
return this.adapter.isOpen();
|
1057
1187
|
}
|
1058
1188
|
|
1059
|
-
connect(
|
1189
|
+
connect(
|
1190
|
+
session: Session,
|
1191
|
+
createStatus: boolean = false,
|
1192
|
+
platform: string = "",
|
1193
|
+
connectTimeoutMs: number = DefaultSocket.DefaultConnectTimeoutMs,
|
1194
|
+
signal?: AbortSignal
|
1195
|
+
): Promise<Session> {
|
1060
1196
|
if (this.adapter.isOpen()) {
|
1061
1197
|
return Promise.resolve(session);
|
1062
1198
|
}
|
1063
1199
|
|
1064
|
-
const scheme =
|
1065
|
-
this.adapter.connect(
|
1200
|
+
const scheme = this.useSSL ? "wss://" : "ws://";
|
1201
|
+
this.adapter.connect(
|
1202
|
+
scheme,
|
1203
|
+
this.host,
|
1204
|
+
this.port,
|
1205
|
+
createStatus,
|
1206
|
+
session.token,
|
1207
|
+
platform,
|
1208
|
+
signal
|
1209
|
+
);
|
1066
1210
|
|
1067
1211
|
this.adapter.onClose = (evt: Event) => {
|
1068
1212
|
this.ondisconnect(evt);
|
1069
|
-
}
|
1213
|
+
};
|
1070
1214
|
|
1071
1215
|
this.adapter.onError = (evt: Event) => {
|
1072
1216
|
this.onerror(evt);
|
1073
|
-
}
|
1217
|
+
};
|
1074
1218
|
|
1075
|
-
this.adapter.onMessage = (message: any) => {
|
1219
|
+
this.adapter.onMessage = async (message: any) => {
|
1076
1220
|
if (this.verbose && window && window.console) {
|
1077
1221
|
console.log("Response: %o", JSON.stringify(message));
|
1078
1222
|
}
|
@@ -1081,8 +1225,8 @@ export class DefaultSocket implements Socket {
|
|
1081
1225
|
if (!message.cid) {
|
1082
1226
|
if (message.notifications) {
|
1083
1227
|
message.notifications.notifications.forEach((n: ApiNotification) => {
|
1084
|
-
|
1085
|
-
|
1228
|
+
n.content = n.content ? JSON.parse(n.content) : undefined;
|
1229
|
+
this.onnotification(n);
|
1086
1230
|
});
|
1087
1231
|
} else if (message.voice_started_event) {
|
1088
1232
|
this.onvoicestarted(message.voice_started_event);
|
@@ -1091,19 +1235,19 @@ export class DefaultSocket implements Socket {
|
|
1091
1235
|
} else if (message.voice_joined_event) {
|
1092
1236
|
this.onvoicejoined(message.voice_joined_event);
|
1093
1237
|
} else if (message.voice_leaved_event) {
|
1094
|
-
this.onvoiceleaved(message.voice_leaved_event);
|
1238
|
+
this.onvoiceleaved(message.voice_leaved_event);
|
1095
1239
|
} else if (message.channel_created_event) {
|
1096
1240
|
this.onchannelcreated(message.channel_created_event);
|
1097
1241
|
} else if (message.role_event) {
|
1098
1242
|
this.onroleevent(message.role_event);
|
1099
|
-
} else if(message.event_emoji) {
|
1243
|
+
} else if (message.event_emoji) {
|
1100
1244
|
this.oneventemoji(message.event_emoji);
|
1101
1245
|
} else if (message.channel_deleted_event) {
|
1102
1246
|
this.onchanneldeleted(message.channel_deleted_event);
|
1103
1247
|
} else if (message.clan_deleted_event) {
|
1104
|
-
this.onclandeleted(message.clan_deleted_event);
|
1248
|
+
this.onclandeleted(message.clan_deleted_event);
|
1105
1249
|
} else if (message.sticker_create_event) {
|
1106
|
-
this.onstickercreated(message.sticker_create_event);
|
1250
|
+
this.onstickercreated(message.sticker_create_event);
|
1107
1251
|
} else if (message.sticker_update_event) {
|
1108
1252
|
this.onstickerupdated(message.sticker_update_event);
|
1109
1253
|
} else if (message.sticker_delete_event) {
|
@@ -1117,36 +1261,40 @@ export class DefaultSocket implements Socket {
|
|
1117
1261
|
} else if (message.last_seen_message_event) {
|
1118
1262
|
this.onlastseenupdated(message.last_seen_message_event);
|
1119
1263
|
} else if (message.status_presence_event) {
|
1120
|
-
this.onstatuspresence(
|
1264
|
+
this.onstatuspresence(
|
1265
|
+
<StatusPresenceEvent>message.status_presence_event
|
1266
|
+
);
|
1121
1267
|
} else if (message.stream_presence_event) {
|
1122
|
-
this.onstreampresence(
|
1268
|
+
this.onstreampresence(
|
1269
|
+
<StreamPresenceEvent>message.stream_presence_event
|
1270
|
+
);
|
1123
1271
|
} else if (message.stream_data) {
|
1124
1272
|
this.onstreamdata(<StreamData>message.stream_data);
|
1125
1273
|
} else if (message.channel_message) {
|
1126
1274
|
var content, reactions, mentions, attachments, references;
|
1127
|
-
try {
|
1275
|
+
try {
|
1128
1276
|
content = JSON.parse(message.channel_message.content);
|
1129
|
-
} catch(e) {
|
1130
|
-
console.log("content is invalid", e)
|
1131
|
-
}
|
1277
|
+
} catch (e) {
|
1278
|
+
console.log("content is invalid", e);
|
1279
|
+
}
|
1132
1280
|
try {
|
1133
1281
|
reactions = JSON.parse(message.channel_message.reactions);
|
1134
|
-
} catch(e) {
|
1135
|
-
console.log("reactions is invalid", e)
|
1136
|
-
}
|
1282
|
+
} catch (e) {
|
1283
|
+
console.log("reactions is invalid", e);
|
1284
|
+
}
|
1137
1285
|
try {
|
1138
1286
|
mentions = JSON.parse(message.channel_message.mentions);
|
1139
|
-
} catch(e) {
|
1140
|
-
console.log("mentions is invalid", e)
|
1141
|
-
}
|
1287
|
+
} catch (e) {
|
1288
|
+
console.log("mentions is invalid", e);
|
1289
|
+
}
|
1142
1290
|
try {
|
1143
1291
|
attachments = JSON.parse(message.channel_message.attachments);
|
1144
|
-
} catch(e) {
|
1145
|
-
console.log("attachments is invalid", e)
|
1292
|
+
} catch (e) {
|
1293
|
+
console.log("attachments is invalid", e);
|
1146
1294
|
}
|
1147
1295
|
try {
|
1148
1296
|
references = JSON.parse(message.channel_message.references);
|
1149
|
-
} catch(e) {
|
1297
|
+
} catch (e) {
|
1150
1298
|
console.log("references is invalid", e);
|
1151
1299
|
}
|
1152
1300
|
var e: ChannelMessage = {
|
@@ -1156,7 +1304,7 @@ export class DefaultSocket implements Socket {
|
|
1156
1304
|
mode: message.channel_message.mode,
|
1157
1305
|
channel_label: message.channel_message.channel_label,
|
1158
1306
|
clan_id: message.channel_message.clan_id,
|
1159
|
-
code: message.channel_message.code,
|
1307
|
+
code: message.channel_message.code,
|
1160
1308
|
create_time: message.channel_message.create_time,
|
1161
1309
|
message_id: message.channel_message.message_id,
|
1162
1310
|
sender_id: message.channel_message.sender_id,
|
@@ -1173,55 +1321,83 @@ export class DefaultSocket implements Socket {
|
|
1173
1321
|
attachments: attachments,
|
1174
1322
|
references: references,
|
1175
1323
|
hide_editted: message.channel_message.hide_editted,
|
1176
|
-
is_public: message.channel_message.is_public,
|
1324
|
+
is_public: message.channel_message.is_public,
|
1177
1325
|
create_time_seconds: message.channel_message.create_time_seconds,
|
1178
1326
|
update_time_seconds: message.channel_message.update_time_seconds,
|
1179
1327
|
};
|
1180
|
-
this.onchannelmessage(e);
|
1328
|
+
this.onchannelmessage(e);
|
1181
1329
|
} else if (message.message_typing_event) {
|
1182
|
-
this.onmessagetyping(
|
1330
|
+
this.onmessagetyping(
|
1331
|
+
<MessageTypingEvent>message.message_typing_event
|
1332
|
+
);
|
1183
1333
|
} else if (message.message_reaction_event) {
|
1184
|
-
this.onmessagereaction(
|
1334
|
+
this.onmessagereaction(
|
1335
|
+
<ApiMessageReaction>message.message_reaction_event
|
1336
|
+
);
|
1185
1337
|
} else if (message.channel_presence_event) {
|
1186
|
-
this.onchannelpresence(
|
1338
|
+
this.onchannelpresence(
|
1339
|
+
<ChannelPresenceEvent>message.channel_presence_event
|
1340
|
+
);
|
1187
1341
|
} else if (message.last_pin_message_event) {
|
1188
|
-
this.onpinmessage(
|
1342
|
+
this.onpinmessage(
|
1343
|
+
<LastPinMessageEvent>message.last_pin_message_event
|
1344
|
+
);
|
1189
1345
|
} else if (message.custom_status_event) {
|
1190
1346
|
this.oncustomstatus(<CustomStatusEvent>message.custom_status_event);
|
1191
1347
|
} else if (message.user_channel_added_event) {
|
1192
|
-
this.onuserchanneladded(
|
1348
|
+
this.onuserchanneladded(
|
1349
|
+
<UserChannelAddedEvent>message.user_channel_added_event
|
1350
|
+
);
|
1193
1351
|
} else if (message.add_clan_user_event) {
|
1194
1352
|
this.onuserclanadded(<AddClanUserEvent>message.add_clan_user_event);
|
1195
1353
|
} else if (message.user_profile_updated_event) {
|
1196
|
-
this.onuserprofileupdate(
|
1354
|
+
this.onuserprofileupdate(
|
1355
|
+
<UserProfileUpdatedEvent>message.user_profile_updated_event
|
1356
|
+
);
|
1197
1357
|
} else if (message.user_channel_removed_event) {
|
1198
|
-
this.onuserchannelremoved(
|
1358
|
+
this.onuserchannelremoved(
|
1359
|
+
<UserChannelRemovedEvent>message.user_channel_removed_event
|
1360
|
+
);
|
1199
1361
|
} else if (message.user_clan_removed_event) {
|
1200
|
-
this.onuserclanremoved(
|
1201
|
-
|
1362
|
+
this.onuserclanremoved(
|
1363
|
+
<UserClanRemovedEvent>message.user_clan_removed_event
|
1364
|
+
);
|
1365
|
+
} else if (message.clan_event_created) {
|
1202
1366
|
this.oneventcreated(message.clan_event_created);
|
1203
|
-
} else if(message.give_coffee_event){
|
1367
|
+
} else if (message.give_coffee_event) {
|
1204
1368
|
this.oncoffeegiven(<ApiGiveCoffeeEvent>message.give_coffee_event);
|
1205
|
-
} else if(message.role_assign_event){
|
1369
|
+
} else if (message.role_assign_event) {
|
1206
1370
|
this.onroleassign(<RoleAssignedEvent>message.role_assign_event);
|
1207
|
-
} else if(message.streaming_started_event){
|
1208
|
-
this.onstreamingchannelstarted(
|
1209
|
-
|
1210
|
-
|
1211
|
-
} else if(message.
|
1212
|
-
this.
|
1213
|
-
|
1214
|
-
|
1215
|
-
} else if(message.
|
1371
|
+
} else if (message.streaming_started_event) {
|
1372
|
+
this.onstreamingchannelstarted(
|
1373
|
+
<StreamingStartedEvent>message.streaming_started_event
|
1374
|
+
);
|
1375
|
+
} else if (message.streaming_ended_event) {
|
1376
|
+
this.onstreamingchannelended(
|
1377
|
+
<StreamingEndedEvent>message.streaming_ended_event
|
1378
|
+
);
|
1379
|
+
} else if (message.streaming_joined_event) {
|
1380
|
+
this.onstreamingchanneljoined(
|
1381
|
+
<StreamingJoinedEvent>message.streaming_joined_event
|
1382
|
+
);
|
1383
|
+
} else if (message.streaming_leaved_event) {
|
1384
|
+
this.onstreamingchannelleaved(
|
1385
|
+
<StreamingLeavedEvent>message.streaming_leaved_event
|
1386
|
+
);
|
1387
|
+
} else if (message.permission_set_event) {
|
1216
1388
|
this.onpermissionset(<PermissionSet>message.permission_set_event);
|
1217
|
-
} else if(message.permission_changed_event){
|
1218
|
-
this.onpermissionchanged(
|
1219
|
-
|
1389
|
+
} else if (message.permission_changed_event) {
|
1390
|
+
this.onpermissionchanged(
|
1391
|
+
<PermissionChangedEvent>message.permission_changed_event
|
1392
|
+
);
|
1393
|
+
} else if (message.unmute_event) {
|
1220
1394
|
this.onunmuteevent(<UnmuteEvent>message.unmute_event);
|
1221
1395
|
} else if (message.token_sent_event) {
|
1222
1396
|
this.ontokensent(<ApiTokenSentEvent>message.token_sent_event);
|
1223
|
-
} else if (message.message_button_clicked){
|
1224
|
-
this.
|
1397
|
+
} else if (message.message_button_clicked) {
|
1398
|
+
this.onmessagebuttonclicked( <MessageButtonClicked>message.message_button_clicked);
|
1399
|
+
} else if (message.webrtc_signaling_fwd) {
|
1400
|
+
this.onwebrtcsignalingfwd(<WebrtcSignalingFwd>message.webrtc_signaling_fwd);
|
1225
1401
|
} else {
|
1226
1402
|
if (this.verbose && window && window.console) {
|
1227
1403
|
console.log("Unrecognized message received: %o", message);
|
@@ -1243,7 +1419,7 @@ export class DefaultSocket implements Socket {
|
|
1243
1419
|
executor.resolve(message);
|
1244
1420
|
}
|
1245
1421
|
}
|
1246
|
-
}
|
1422
|
+
};
|
1247
1423
|
|
1248
1424
|
return new Promise((resolve, reject) => {
|
1249
1425
|
this.adapter.onOpen = (evt: Event) => {
|
@@ -1253,11 +1429,11 @@ export class DefaultSocket implements Socket {
|
|
1253
1429
|
|
1254
1430
|
this.pingPong();
|
1255
1431
|
resolve(session);
|
1256
|
-
}
|
1432
|
+
};
|
1257
1433
|
this.adapter.onError = (evt: Event) => {
|
1258
1434
|
reject(evt);
|
1259
1435
|
this.adapter.close();
|
1260
|
-
}
|
1436
|
+
};
|
1261
1437
|
|
1262
1438
|
setTimeout(() => {
|
1263
1439
|
// if promise has resolved by now, the reject() is a no-op
|
@@ -1275,11 +1451,11 @@ export class DefaultSocket implements Socket {
|
|
1275
1451
|
}
|
1276
1452
|
}
|
1277
1453
|
|
1278
|
-
setHeartbeatTimeoutMs(ms
|
1454
|
+
setHeartbeatTimeoutMs(ms: number) {
|
1279
1455
|
this._heartbeatTimeoutMs = ms;
|
1280
1456
|
}
|
1281
1457
|
|
1282
|
-
getHeartbeatTimeoutMs()
|
1458
|
+
getHeartbeatTimeoutMs(): number {
|
1283
1459
|
return this._heartbeatTimeoutMs;
|
1284
1460
|
}
|
1285
1461
|
|
@@ -1336,7 +1512,7 @@ export class DefaultSocket implements Socket {
|
|
1336
1512
|
console.log(user);
|
1337
1513
|
}
|
1338
1514
|
}
|
1339
|
-
|
1515
|
+
|
1340
1516
|
onuserchannelremoved(user: UserChannelRemovedEvent) {
|
1341
1517
|
if (this.verbose && window && window.console) {
|
1342
1518
|
console.log(user);
|
@@ -1439,7 +1615,6 @@ export class DefaultSocket implements Socket {
|
|
1439
1615
|
}
|
1440
1616
|
}
|
1441
1617
|
|
1442
|
-
|
1443
1618
|
onchannelupdated(channelUpdated: ChannelUpdatedEvent) {
|
1444
1619
|
if (this.verbose && window && window.console) {
|
1445
1620
|
console.log(channelUpdated);
|
@@ -1529,20 +1704,20 @@ export class DefaultSocket implements Socket {
|
|
1529
1704
|
console.log(streaming_leaved_event);
|
1530
1705
|
}
|
1531
1706
|
}
|
1532
|
-
|
1533
|
-
onpermissionset(permission_set_event: PermissionSet){
|
1707
|
+
|
1708
|
+
onpermissionset(permission_set_event: PermissionSet) {
|
1534
1709
|
if (this.verbose && window && window.console) {
|
1535
1710
|
console.log(permission_set_event);
|
1536
1711
|
}
|
1537
1712
|
}
|
1538
1713
|
|
1539
|
-
onpermissionchanged(permission_changed_event: PermissionChangedEvent){
|
1714
|
+
onpermissionchanged(permission_changed_event: PermissionChangedEvent) {
|
1540
1715
|
if (this.verbose && window && window.console) {
|
1541
1716
|
console.log(permission_changed_event);
|
1542
1717
|
}
|
1543
1718
|
}
|
1544
1719
|
|
1545
|
-
onunmuteevent(unmute_event: UnmuteEvent){
|
1720
|
+
onunmuteevent(unmute_event: UnmuteEvent) {
|
1546
1721
|
if (this.verbose && window && window.console) {
|
1547
1722
|
console.log(unmute_event);
|
1548
1723
|
}
|
@@ -1554,31 +1729,57 @@ export class DefaultSocket implements Socket {
|
|
1554
1729
|
}
|
1555
1730
|
}
|
1556
1731
|
|
1557
|
-
|
1732
|
+
onmessagebuttonclicked(messageButtonClicked: MessageButtonClicked) {
|
1558
1733
|
if (this.verbose && window && window.console) {
|
1559
1734
|
console.log(messageButtonClicked);
|
1560
1735
|
}
|
1561
1736
|
}
|
1562
1737
|
|
1563
|
-
|
1564
|
-
|
1738
|
+
onwebrtcsignalingfwd(event: WebrtcSignalingFwd) {
|
1739
|
+
if (this.verbose && window && window.console) {
|
1740
|
+
console.log(event);
|
1741
|
+
}
|
1742
|
+
}
|
1743
|
+
|
1744
|
+
send(
|
1745
|
+
message:
|
1746
|
+
| ChannelJoin
|
1747
|
+
| ChannelLeave
|
1748
|
+
| ChannelMessageSend
|
1749
|
+
| ChannelMessageUpdate
|
1750
|
+
| CustomStatusEvent
|
1751
|
+
| ChannelMessageRemove
|
1752
|
+
| MessageTypingEvent
|
1753
|
+
| LastSeenMessageEvent
|
1754
|
+
| Rpc
|
1755
|
+
| StatusFollow
|
1756
|
+
| StatusUnfollow
|
1757
|
+
| StatusUpdate
|
1758
|
+
| Ping
|
1759
|
+
| WebrtcSignalingFwd
|
1760
|
+
| MessageButtonClicked,
|
1761
|
+
sendTimeout = DefaultSocket.DefaultSendTimeoutMs
|
1762
|
+
): Promise<any> {
|
1565
1763
|
const untypedMessage = message as any;
|
1566
1764
|
|
1567
1765
|
return new Promise<void>((resolve, reject) => {
|
1568
1766
|
if (!this.adapter.isOpen()) {
|
1569
1767
|
reject("Socket connection has not been established yet.");
|
1570
|
-
}
|
1571
|
-
else {
|
1768
|
+
} else {
|
1572
1769
|
if (untypedMessage.channel_message_send) {
|
1573
|
-
untypedMessage.channel_message_send.content = JSON.stringify(
|
1770
|
+
untypedMessage.channel_message_send.content = JSON.stringify(
|
1771
|
+
untypedMessage.channel_message_send.content
|
1772
|
+
);
|
1574
1773
|
} else if (untypedMessage.channel_message_update) {
|
1575
|
-
untypedMessage.channel_message_update.content = JSON.stringify(
|
1774
|
+
untypedMessage.channel_message_update.content = JSON.stringify(
|
1775
|
+
untypedMessage.channel_message_update.content
|
1776
|
+
);
|
1576
1777
|
}
|
1577
1778
|
|
1578
1779
|
const cid = this.generatecid();
|
1579
|
-
this.cIds[cid] = {resolve, reject};
|
1780
|
+
this.cIds[cid] = { resolve, reject };
|
1580
1781
|
setTimeout(() => {
|
1581
|
-
reject("The socket timed out while waiting for a response.")
|
1782
|
+
reject("The socket timed out while waiting for a response.");
|
1582
1783
|
}, sendTimeout);
|
1583
1784
|
|
1584
1785
|
/** Add id for promise executor. */
|
@@ -1588,149 +1789,348 @@ export class DefaultSocket implements Socket {
|
|
1588
1789
|
});
|
1589
1790
|
}
|
1590
1791
|
|
1591
|
-
async followUsers(userIds
|
1592
|
-
const response = await this.send({status_follow: {user_ids: userIds}});
|
1792
|
+
async followUsers(userIds: string[]): Promise<Status> {
|
1793
|
+
const response = await this.send({ status_follow: { user_ids: userIds } });
|
1593
1794
|
return response.status;
|
1594
1795
|
}
|
1595
1796
|
|
1596
1797
|
async joinClanChat(clan_id: string): Promise<ClanJoin> {
|
1597
|
-
|
1598
1798
|
const response = await this.send({
|
1599
1799
|
clan_join: {
|
1600
|
-
|
1601
|
-
}
|
1800
|
+
clan_id: clan_id,
|
1801
|
+
},
|
1602
1802
|
});
|
1603
1803
|
|
1604
1804
|
return response.clan_join;
|
1605
1805
|
}
|
1606
1806
|
|
1607
|
-
async joinChat(
|
1608
|
-
|
1807
|
+
async joinChat(
|
1808
|
+
clan_id: string,
|
1809
|
+
channel_id: string,
|
1810
|
+
channel_type: number,
|
1811
|
+
is_public: boolean
|
1812
|
+
): Promise<Channel> {
|
1609
1813
|
const response = await this.send({
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
);
|
1814
|
+
channel_join: {
|
1815
|
+
clan_id: clan_id,
|
1816
|
+
channel_id: channel_id,
|
1817
|
+
channel_type: channel_type,
|
1818
|
+
is_public: is_public,
|
1819
|
+
},
|
1820
|
+
});
|
1618
1821
|
|
1619
1822
|
return response.channel;
|
1620
1823
|
}
|
1621
1824
|
|
1622
|
-
leaveChat(
|
1623
|
-
|
1825
|
+
leaveChat(
|
1826
|
+
clan_id: string,
|
1827
|
+
channel_id: string,
|
1828
|
+
channel_type: number,
|
1829
|
+
is_public: boolean
|
1830
|
+
): Promise<void> {
|
1831
|
+
return this.send({
|
1832
|
+
channel_leave: {
|
1833
|
+
clan_id: clan_id,
|
1834
|
+
channel_id: channel_id,
|
1835
|
+
channel_type: channel_type,
|
1836
|
+
is_public: is_public,
|
1837
|
+
},
|
1838
|
+
});
|
1624
1839
|
}
|
1625
1840
|
|
1626
|
-
async removeChatMessage(
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1841
|
+
async removeChatMessage(
|
1842
|
+
clan_id: string,
|
1843
|
+
channel_id: string,
|
1844
|
+
mode: number,
|
1845
|
+
is_public: boolean,
|
1846
|
+
message_id: string
|
1847
|
+
): Promise<ChannelMessageAck> {
|
1848
|
+
const response = await this.send({
|
1849
|
+
channel_message_remove: {
|
1850
|
+
clan_id: clan_id,
|
1851
|
+
channel_id: channel_id,
|
1852
|
+
mode: mode,
|
1853
|
+
message_id: message_id,
|
1854
|
+
is_public: is_public,
|
1855
|
+
},
|
1856
|
+
});
|
1638
1857
|
|
1639
1858
|
return response.channel_message_ack;
|
1640
1859
|
}
|
1641
1860
|
|
1642
1861
|
async rpc(id?: string, payload?: string, http_key?: string): Promise<ApiRpc> {
|
1643
|
-
const response = await this.send(
|
1644
|
-
{
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
});
|
1862
|
+
const response = await this.send({
|
1863
|
+
rpc: {
|
1864
|
+
id: id,
|
1865
|
+
payload: payload,
|
1866
|
+
http_key: http_key,
|
1867
|
+
},
|
1868
|
+
});
|
1651
1869
|
|
1652
|
-
|
1870
|
+
return response.rpc;
|
1653
1871
|
}
|
1654
1872
|
|
1655
|
-
unfollowUsers(user_ids
|
1656
|
-
return this.send({status_unfollow: {user_ids: user_ids}});
|
1873
|
+
unfollowUsers(user_ids: string[]): Promise<void> {
|
1874
|
+
return this.send({ status_unfollow: { user_ids: user_ids } });
|
1657
1875
|
}
|
1658
1876
|
|
1659
|
-
async updateChatMessage(
|
1660
|
-
|
1877
|
+
async updateChatMessage(
|
1878
|
+
clan_id: string,
|
1879
|
+
channel_id: string,
|
1880
|
+
mode: number,
|
1881
|
+
is_public: boolean,
|
1882
|
+
message_id: string,
|
1883
|
+
content: any,
|
1884
|
+
mentions?: Array<ApiMessageMention>,
|
1885
|
+
attachments?: Array<ApiMessageAttachment>,
|
1886
|
+
hideEditted?: boolean
|
1887
|
+
): Promise<ChannelMessageAck> {
|
1888
|
+
const response = await this.send({
|
1889
|
+
channel_message_update: {
|
1890
|
+
clan_id: clan_id,
|
1891
|
+
channel_id: channel_id,
|
1892
|
+
message_id: message_id,
|
1893
|
+
content: content,
|
1894
|
+
mentions: mentions,
|
1895
|
+
attachments: attachments,
|
1896
|
+
mode: mode,
|
1897
|
+
is_public: is_public,
|
1898
|
+
hide_editted: hideEditted,
|
1899
|
+
},
|
1900
|
+
});
|
1661
1901
|
return response.channel_message_ack;
|
1662
1902
|
}
|
1663
1903
|
|
1664
1904
|
updateStatus(status?: string): Promise<void> {
|
1665
|
-
return this.send({status_update: {status: status}});
|
1905
|
+
return this.send({ status_update: { status: status } });
|
1666
1906
|
}
|
1667
1907
|
|
1668
|
-
async writeChatMessage(
|
1669
|
-
|
1908
|
+
async writeChatMessage(
|
1909
|
+
clan_id: string,
|
1910
|
+
channel_id: string,
|
1911
|
+
mode: number,
|
1912
|
+
is_public: boolean,
|
1913
|
+
content: any,
|
1914
|
+
mentions?: Array<ApiMessageMention>,
|
1915
|
+
attachments?: Array<ApiMessageAttachment>,
|
1916
|
+
references?: Array<ApiMessageRef>,
|
1917
|
+
anonymous_message?: boolean,
|
1918
|
+
mention_everyone?: Boolean,
|
1919
|
+
avatar?: string
|
1920
|
+
): Promise<ChannelMessageAck> {
|
1921
|
+
const response = await this.send({
|
1922
|
+
channel_message_send: {
|
1923
|
+
clan_id: clan_id,
|
1924
|
+
channel_id: channel_id,
|
1925
|
+
mode: mode,
|
1926
|
+
is_public: is_public,
|
1927
|
+
content: content,
|
1928
|
+
mentions: mentions,
|
1929
|
+
attachments: attachments,
|
1930
|
+
references: references,
|
1931
|
+
anonymous_message: anonymous_message,
|
1932
|
+
mention_everyone: mention_everyone,
|
1933
|
+
avatar: avatar,
|
1934
|
+
},
|
1935
|
+
});
|
1670
1936
|
return response.channel_message_ack;
|
1671
1937
|
}
|
1672
1938
|
|
1673
|
-
async writeMessageReaction(
|
1674
|
-
|
1939
|
+
async writeMessageReaction(
|
1940
|
+
id: string,
|
1941
|
+
clan_id: string,
|
1942
|
+
channel_id: string,
|
1943
|
+
mode: number,
|
1944
|
+
is_public: boolean,
|
1945
|
+
message_id: string,
|
1946
|
+
emoji_id: string,
|
1947
|
+
emoji: string,
|
1948
|
+
count: number,
|
1949
|
+
message_sender_id: string,
|
1950
|
+
action_delete: boolean
|
1951
|
+
): Promise<ApiMessageReaction> {
|
1952
|
+
const response = await this.send({
|
1953
|
+
message_reaction_event: {
|
1954
|
+
id: id,
|
1955
|
+
clan_id: clan_id,
|
1956
|
+
channel_id: channel_id,
|
1957
|
+
mode: mode,
|
1958
|
+
is_public: is_public,
|
1959
|
+
message_id: message_id,
|
1960
|
+
emoji_id: emoji_id,
|
1961
|
+
emoji: emoji,
|
1962
|
+
count: count,
|
1963
|
+
message_sender_id: message_sender_id,
|
1964
|
+
action: action_delete,
|
1965
|
+
},
|
1966
|
+
});
|
1675
1967
|
return response.message_reaction_event;
|
1676
1968
|
}
|
1677
1969
|
|
1678
|
-
async writeMessageTyping(
|
1679
|
-
|
1970
|
+
async writeMessageTyping(
|
1971
|
+
clan_id: string,
|
1972
|
+
channel_id: string,
|
1973
|
+
mode: number,
|
1974
|
+
is_public: boolean
|
1975
|
+
): Promise<MessageTypingEvent> {
|
1976
|
+
const response = await this.send({
|
1977
|
+
message_typing_event: {
|
1978
|
+
clan_id: clan_id,
|
1979
|
+
channel_id: channel_id,
|
1980
|
+
mode: mode,
|
1981
|
+
is_public: is_public,
|
1982
|
+
},
|
1983
|
+
});
|
1680
1984
|
return response.message_typing_event;
|
1681
1985
|
}
|
1682
1986
|
|
1683
|
-
async writeLastSeenMessage(
|
1684
|
-
|
1987
|
+
async writeLastSeenMessage(
|
1988
|
+
clan_id: string,
|
1989
|
+
channel_id: string,
|
1990
|
+
mode: number,
|
1991
|
+
message_id: string,
|
1992
|
+
timestamp_seconds: number
|
1993
|
+
): Promise<LastSeenMessageEvent> {
|
1994
|
+
const response = await this.send({
|
1995
|
+
last_seen_message_event: {
|
1996
|
+
clan_id: clan_id,
|
1997
|
+
channel_id: channel_id,
|
1998
|
+
mode: mode,
|
1999
|
+
message_id: message_id,
|
2000
|
+
timestamp_seconds: timestamp_seconds,
|
2001
|
+
},
|
2002
|
+
});
|
1685
2003
|
return response.last_seen_message_event;
|
1686
2004
|
}
|
1687
2005
|
|
1688
|
-
async writeLastPinMessage(
|
1689
|
-
|
2006
|
+
async writeLastPinMessage(
|
2007
|
+
clan_id: string,
|
2008
|
+
channel_id: string,
|
2009
|
+
mode: number,
|
2010
|
+
is_public: boolean,
|
2011
|
+
message_id: string,
|
2012
|
+
timestamp_seconds: number,
|
2013
|
+
operation: number
|
2014
|
+
): Promise<LastPinMessageEvent> {
|
2015
|
+
const response = await this.send({
|
2016
|
+
last_pin_message_event: {
|
2017
|
+
clan_id: clan_id,
|
2018
|
+
channel_id: channel_id,
|
2019
|
+
mode: mode,
|
2020
|
+
is_public: is_public,
|
2021
|
+
message_id: message_id,
|
2022
|
+
timestamp_seconds: timestamp_seconds,
|
2023
|
+
operation: operation,
|
2024
|
+
},
|
2025
|
+
});
|
1690
2026
|
return response.last_pin_message_event;
|
1691
2027
|
}
|
1692
2028
|
|
1693
|
-
async writeVoiceJoined(
|
1694
|
-
|
2029
|
+
async writeVoiceJoined(
|
2030
|
+
id: string,
|
2031
|
+
clanId: string,
|
2032
|
+
clanName: string,
|
2033
|
+
voiceChannelId: string,
|
2034
|
+
voiceChannelLabel: string,
|
2035
|
+
participant: string,
|
2036
|
+
lastScreenshot: string
|
2037
|
+
): Promise<VoiceJoinedEvent> {
|
2038
|
+
const response = await this.send({
|
2039
|
+
voice_joined_event: {
|
2040
|
+
clan_id: clanId,
|
2041
|
+
clan_name: clanName,
|
2042
|
+
id: id,
|
2043
|
+
participant: participant,
|
2044
|
+
voice_channel_id: voiceChannelId,
|
2045
|
+
voice_channel_label: voiceChannelLabel,
|
2046
|
+
last_screenshot: lastScreenshot,
|
2047
|
+
},
|
2048
|
+
});
|
1695
2049
|
return response.voice_joined_event;
|
1696
2050
|
}
|
1697
2051
|
|
1698
|
-
async writeVoiceLeaved(
|
1699
|
-
|
2052
|
+
async writeVoiceLeaved(
|
2053
|
+
id: string,
|
2054
|
+
clanId: string,
|
2055
|
+
voiceChannelId: string,
|
2056
|
+
voiceUserId: string
|
2057
|
+
): Promise<VoiceLeavedEvent> {
|
2058
|
+
const response = await this.send({
|
2059
|
+
voice_leaved_event: {
|
2060
|
+
id: id,
|
2061
|
+
clan_id: clanId,
|
2062
|
+
voice_channel_id: voiceChannelId,
|
2063
|
+
voice_user_id: voiceUserId,
|
2064
|
+
},
|
2065
|
+
});
|
1700
2066
|
return response.voice_leaved_event;
|
1701
2067
|
}
|
1702
2068
|
|
1703
|
-
async writeCustomStatus(
|
1704
|
-
|
2069
|
+
async writeCustomStatus(
|
2070
|
+
clan_id: string,
|
2071
|
+
status: string
|
2072
|
+
): Promise<CustomStatusEvent> {
|
2073
|
+
const response = await this.send({
|
2074
|
+
custom_status_event: { clan_id: clan_id, status: status },
|
2075
|
+
});
|
1705
2076
|
return response.custom_status_event;
|
1706
2077
|
}
|
1707
|
-
|
1708
|
-
async checkDuplicateName(
|
1709
|
-
|
2078
|
+
|
2079
|
+
async checkDuplicateName(
|
2080
|
+
name: string,
|
2081
|
+
condition_id: string,
|
2082
|
+
type: number
|
2083
|
+
): Promise<CheckNameExistedEvent> {
|
2084
|
+
const response = await this.send({
|
2085
|
+
check_name_existed_event: {
|
2086
|
+
name: name,
|
2087
|
+
condition_id: condition_id,
|
2088
|
+
type: type,
|
2089
|
+
},
|
2090
|
+
});
|
1710
2091
|
return response.check_name_existed_event;
|
1711
2092
|
}
|
1712
2093
|
|
2094
|
+
async forwardWebrtcSignaling(receiver_id: string, data_type: number, json_data: string): Promise<WebrtcSignalingFwd> {
|
2095
|
+
const response = await this.send({
|
2096
|
+
webrtc_signaling_fwd: { receiver_id: receiver_id, data_type: data_type, json_data: json_data },
|
2097
|
+
});
|
2098
|
+
return response.webrtc_signaling_fwd;
|
2099
|
+
}
|
2100
|
+
|
2101
|
+
async handleMessageButtonClick (
|
2102
|
+
message_id: string,
|
2103
|
+
channel_id: string,
|
2104
|
+
button_id: string,
|
2105
|
+
sender_id: string,
|
2106
|
+
user_id: string): Promise<MessageButtonClicked> {
|
2107
|
+
const response = await this.send({
|
2108
|
+
message_button_clicked: { message_id: message_id, channel_id: channel_id, button_id: button_id, sender_id: sender_id, user_id: user_id },
|
2109
|
+
});
|
2110
|
+
return response.webrtc_signaling_fwd;
|
2111
|
+
}
|
2112
|
+
|
1713
2113
|
private async pingPong(): Promise<void> {
|
1714
2114
|
if (!this.adapter.isOpen()) {
|
1715
|
-
|
2115
|
+
return;
|
1716
2116
|
}
|
1717
2117
|
|
1718
2118
|
try {
|
1719
|
-
|
2119
|
+
await this.send({ ping: {} }, this._heartbeatTimeoutMs);
|
1720
2120
|
} catch {
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
}
|
1725
|
-
this.onheartbeattimeout();
|
1726
|
-
this.adapter.close();
|
2121
|
+
if (this.adapter.isOpen()) {
|
2122
|
+
if (window && window.console) {
|
2123
|
+
console.error("Server unreachable from heartbeat.");
|
1727
2124
|
}
|
2125
|
+
this.onheartbeattimeout();
|
2126
|
+
this.adapter.close();
|
2127
|
+
}
|
1728
2128
|
|
1729
|
-
|
2129
|
+
return;
|
1730
2130
|
}
|
1731
2131
|
|
1732
2132
|
// reuse the timeout as the interval for now.
|
1733
2133
|
// we can separate them out into separate values if needed later.
|
1734
2134
|
setTimeout(() => this.pingPong(), this._heartbeatTimeoutMs);
|
1735
2135
|
}
|
1736
|
-
}
|
2136
|
+
}
|