mezon-js 2.9.68 → 2.9.70
Sign up to get free protection for your applications and to get access to all the features.
- package/api.gen.ts +30 -7
- package/dist/api.gen.d.ts +19 -5
- package/dist/mezon-js.cjs.js +309 -63
- package/dist/mezon-js.esm.mjs +309 -63
- package/dist/socket.d.ts +59 -1
- package/dist/web_socket_adapter.d.ts +9 -0
- package/package.json +1 -1
- package/socket.ts +748 -225
- package/web_socket_adapter.ts +144 -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,26 @@ 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 CallRequest {
|
831
|
+
type: string;
|
832
|
+
sdp: string;
|
833
|
+
}
|
834
|
+
|
835
|
+
export interface CallAccept {
|
836
|
+
type: string;
|
837
|
+
sdp: string;
|
838
|
+
}
|
839
|
+
|
840
|
+
export interface ICECandidateInit {
|
841
|
+
candidate: string;
|
842
|
+
sdpMid: string | undefined;
|
843
|
+
sdpMLineIndex: number | undefined;
|
844
|
+
usernameFragment: string | undefined;
|
817
845
|
}
|
818
846
|
|
819
847
|
/** A socket connection to Mezon server. */
|
@@ -822,61 +850,154 @@ export interface Socket {
|
|
822
850
|
isOpen(): boolean;
|
823
851
|
|
824
852
|
/** Connect to the server. */
|
825
|
-
connect(
|
853
|
+
connect(
|
854
|
+
session: Session,
|
855
|
+
createStatus: boolean,
|
856
|
+
platform: string,
|
857
|
+
connectTimeoutMs?: number,
|
858
|
+
signal?: AbortSignal
|
859
|
+
): Promise<Session>;
|
860
|
+
|
861
|
+
getRTCPeerConnection(): RTCPeerConnection;
|
826
862
|
|
827
863
|
/** Disconnect from the server. */
|
828
864
|
disconnect(fireDisconnectEvent: boolean): void;
|
829
865
|
|
830
866
|
/** Subscribe to one or more users for their status updates. */
|
831
|
-
followUsers(user_ids: string[])
|
867
|
+
followUsers(user_ids: string[]): Promise<Status>;
|
832
868
|
|
833
869
|
/** Join clan chat */
|
834
|
-
joinClanChat(clan_id: string)
|
870
|
+
joinClanChat(clan_id: string): Promise<ClanJoin>;
|
835
871
|
|
836
872
|
/** Join a chat channel on the server. */
|
837
|
-
joinChat(
|
873
|
+
joinChat(
|
874
|
+
clan_id: string,
|
875
|
+
channel_id: string,
|
876
|
+
channel_type: number,
|
877
|
+
is_public: boolean
|
878
|
+
): Promise<Channel>;
|
838
879
|
|
839
880
|
/** Leave a chat channel on the server. */
|
840
|
-
leaveChat(
|
881
|
+
leaveChat(
|
882
|
+
clan_id: string,
|
883
|
+
channel_id: string,
|
884
|
+
channel_type: number,
|
885
|
+
is_public: boolean
|
886
|
+
): Promise<void>;
|
841
887
|
|
842
888
|
/** Remove a chat message from a chat channel on the server. */
|
843
|
-
removeChatMessage(
|
889
|
+
removeChatMessage(
|
890
|
+
clan_id: string,
|
891
|
+
channel_id: string,
|
892
|
+
mode: number,
|
893
|
+
is_public: boolean,
|
894
|
+
message_id: string
|
895
|
+
): Promise<ChannelMessageAck>;
|
844
896
|
|
845
897
|
/** Execute an RPC function to the server. */
|
846
|
-
rpc(id?: string, payload?: string, http_key?: string)
|
898
|
+
rpc(id?: string, payload?: string, http_key?: string): Promise<ApiRpc>;
|
847
899
|
|
848
900
|
/** Unfollow one or more users from their status updates. */
|
849
|
-
unfollowUsers(user_ids
|
901
|
+
unfollowUsers(user_ids: string[]): Promise<void>;
|
850
902
|
|
851
903
|
/** Update a chat message on a chat channel in the server. */
|
852
|
-
updateChatMessage(
|
904
|
+
updateChatMessage(
|
905
|
+
clan_id: string,
|
906
|
+
channel_id: string,
|
907
|
+
mode: number,
|
908
|
+
is_public: boolean,
|
909
|
+
message_id: string,
|
910
|
+
content: any,
|
911
|
+
mentions?: Array<ApiMessageMention>,
|
912
|
+
attachments?: Array<ApiMessageAttachment>,
|
913
|
+
hideEditted?: boolean
|
914
|
+
): Promise<ChannelMessageAck>;
|
853
915
|
|
854
916
|
/** Update the status for the current user online. */
|
855
|
-
updateStatus(status?: string)
|
917
|
+
updateStatus(status?: string): Promise<void>;
|
856
918
|
|
857
919
|
/** Send a chat message to a chat channel on the server. */
|
858
|
-
writeChatMessage(
|
920
|
+
writeChatMessage(
|
921
|
+
clan_id: string,
|
922
|
+
channel_id: string,
|
923
|
+
mode: number,
|
924
|
+
is_public: boolean,
|
925
|
+
content?: any,
|
926
|
+
mentions?: Array<ApiMessageMention>,
|
927
|
+
attachments?: Array<ApiMessageAttachment>,
|
928
|
+
references?: Array<ApiMessageRef>,
|
929
|
+
anonymous_message?: boolean,
|
930
|
+
mention_everyone?: boolean,
|
931
|
+
avatar?: string
|
932
|
+
): Promise<ChannelMessageAck>;
|
859
933
|
|
860
934
|
/** Send message typing */
|
861
|
-
writeMessageTyping(
|
935
|
+
writeMessageTyping(
|
936
|
+
clan_id: string,
|
937
|
+
channel_id: string,
|
938
|
+
mode: number,
|
939
|
+
is_public: boolean
|
940
|
+
): Promise<MessageTypingEvent>;
|
862
941
|
|
863
942
|
/** Send message reaction */
|
864
|
-
writeMessageReaction(
|
943
|
+
writeMessageReaction(
|
944
|
+
id: string,
|
945
|
+
clan_id: string,
|
946
|
+
channel_id: string,
|
947
|
+
mode: number,
|
948
|
+
is_public: boolean,
|
949
|
+
message_id: string,
|
950
|
+
emoji_id: string,
|
951
|
+
emoji: string,
|
952
|
+
count: number,
|
953
|
+
message_sender_id: string,
|
954
|
+
action_delete: boolean
|
955
|
+
): Promise<ApiMessageReaction>;
|
865
956
|
|
866
957
|
/** Send last seen message */
|
867
|
-
writeLastSeenMessage(
|
958
|
+
writeLastSeenMessage(
|
959
|
+
clan_id: string,
|
960
|
+
channel_id: string,
|
961
|
+
mode: number,
|
962
|
+
message_id: string,
|
963
|
+
timestamp_seconds: number
|
964
|
+
): Promise<LastSeenMessageEvent>;
|
868
965
|
|
869
966
|
/** Send last pin message */
|
870
|
-
writeLastPinMessage(
|
967
|
+
writeLastPinMessage(
|
968
|
+
clan_id: string,
|
969
|
+
channel_id: string,
|
970
|
+
mode: number,
|
971
|
+
is_public: boolean,
|
972
|
+
message_id: string,
|
973
|
+
timestamp_seconds: number,
|
974
|
+
operation: number
|
975
|
+
): Promise<LastPinMessageEvent>;
|
871
976
|
|
872
977
|
/** Send custom user status */
|
873
|
-
writeCustomStatus(
|
978
|
+
writeCustomStatus(
|
979
|
+
clan_id: string,
|
980
|
+
status: string
|
981
|
+
): Promise<CustomStatusEvent>;
|
874
982
|
|
875
983
|
/** send voice joined */
|
876
|
-
writeVoiceJoined(
|
984
|
+
writeVoiceJoined(
|
985
|
+
id: string,
|
986
|
+
clanId: string,
|
987
|
+
clanName: string,
|
988
|
+
voiceChannelId: string,
|
989
|
+
voiceChannelLabel: string,
|
990
|
+
participant: string,
|
991
|
+
lastScreenshot: string
|
992
|
+
): Promise<VoiceJoinedEvent>;
|
877
993
|
|
878
994
|
/** send voice leaved */
|
879
|
-
writeVoiceLeaved(
|
995
|
+
writeVoiceLeaved(
|
996
|
+
id: string,
|
997
|
+
clanId: string,
|
998
|
+
voiceChannelId: string,
|
999
|
+
voiceUserId: string
|
1000
|
+
): Promise<VoiceLeavedEvent>;
|
880
1001
|
|
881
1002
|
/** Handle disconnect events received from the socket. */
|
882
1003
|
ondisconnect: (evt: Event) => void;
|
@@ -920,7 +1041,7 @@ export interface Socket {
|
|
920
1041
|
|
921
1042
|
/** pin message event */
|
922
1043
|
onpinmessage: (pin: LastPinMessageEvent) => void;
|
923
|
-
|
1044
|
+
|
924
1045
|
/** Receive added user event */
|
925
1046
|
onuserchanneladded: (user: UserChannelAddedEvent) => void;
|
926
1047
|
|
@@ -938,13 +1059,13 @@ export interface Socket {
|
|
938
1059
|
|
939
1060
|
// when someone start the voice room
|
940
1061
|
onvoicestarted: (voice: VoiceStartedEvent) => void;
|
941
|
-
|
1062
|
+
|
942
1063
|
// when someone end the voice room
|
943
1064
|
onvoiceended: (voice: VoiceEndedEvent) => void;
|
944
1065
|
|
945
1066
|
// when someone join to voice room
|
946
1067
|
onvoicejoined: (voiceParticipant: VoiceJoinedEvent) => void;
|
947
|
-
|
1068
|
+
|
948
1069
|
// when someone join to voice room
|
949
1070
|
onvoiceleaved: (voiceParticipant: VoiceLeavedEvent) => void;
|
950
1071
|
|
@@ -978,17 +1099,29 @@ export interface Socket {
|
|
978
1099
|
onclanupdated: (clan: ClanUpdatedEvent) => void;
|
979
1100
|
|
980
1101
|
// when user update last seen message
|
981
|
-
onlastseenupdated: (event: LastSeenMessageEvent)
|
1102
|
+
onlastseenupdated: (event: LastSeenMessageEvent) => void;
|
982
1103
|
|
983
1104
|
/* Set the heartbeat timeout used by the socket to detect if it has lost connectivity to the server. */
|
984
|
-
setHeartbeatTimeoutMs(ms
|
1105
|
+
setHeartbeatTimeoutMs(ms: number): void;
|
985
1106
|
|
986
1107
|
/* Get the heartbeat timeout used by the socket to detect if it has lost connectivity to the server. */
|
987
|
-
getHeartbeatTimeoutMs()
|
1108
|
+
getHeartbeatTimeoutMs(): number;
|
1109
|
+
|
1110
|
+
checkDuplicateName(
|
1111
|
+
name: string,
|
1112
|
+
condition_id: string,
|
1113
|
+
type: number
|
1114
|
+
): Promise<CheckNameExistedEvent>;
|
1115
|
+
|
1116
|
+
handleMessageButtonClick: (
|
1117
|
+
message_button_clicked: MessageButtonClicked
|
1118
|
+
) => void;
|
1119
|
+
|
1120
|
+
onCallRequest: (call_request: CallRequest) => void;
|
988
1121
|
|
989
|
-
|
1122
|
+
onCallAccept: (call_accept: CallAccept) => void;
|
990
1123
|
|
991
|
-
|
1124
|
+
onIceCandidateInit: (ice_candidate_init: ICECandidateInit) => void;
|
992
1125
|
|
993
1126
|
oneventcreated: (clan_event_created: ApiCreateEventRequest) => void;
|
994
1127
|
|
@@ -998,21 +1131,43 @@ export interface Socket {
|
|
998
1131
|
|
999
1132
|
onroleassign: (role_assign_event: RoleAssignedEvent) => void;
|
1000
1133
|
|
1001
|
-
onstreamingchannelstarted: (
|
1134
|
+
onstreamingchannelstarted: (
|
1135
|
+
streaming_started_event: StreamingStartedEvent
|
1136
|
+
) => void;
|
1002
1137
|
|
1003
1138
|
onstreamingchannelended: (streaming_ended_event: StreamingEndedEvent) => void;
|
1004
1139
|
|
1005
|
-
onstreamingchanneljoined: (
|
1140
|
+
onstreamingchanneljoined: (
|
1141
|
+
streaming_joined_event: StreamingJoinedEvent
|
1142
|
+
) => void;
|
1006
1143
|
|
1007
|
-
onstreamingchannelleaved: (
|
1144
|
+
onstreamingchannelleaved: (
|
1145
|
+
streaming_leaved_event: StreamingLeavedEvent
|
1146
|
+
) => void;
|
1008
1147
|
|
1009
1148
|
onpermissionset: (permission_set_event: PermissionSet) => void;
|
1010
1149
|
|
1011
|
-
onpermissionchanged: (
|
1150
|
+
onpermissionchanged: (
|
1151
|
+
permission_changed_event: PermissionChangedEvent
|
1152
|
+
) => void;
|
1012
1153
|
|
1013
1154
|
onunmuteevent: (unmute_event: UnmuteEvent) => void;
|
1014
1155
|
|
1015
1156
|
ontokensent: (token: ApiTokenSentEvent) => void;
|
1157
|
+
|
1158
|
+
sendCallRequest(req: { type: string; sdp: string }): Promise<void>;
|
1159
|
+
sendCallAccept(req: { type: string; sdp: string }): Promise<void>;
|
1160
|
+
sendICECandidateInit(req: {
|
1161
|
+
candidate: string;
|
1162
|
+
sdpMid: string | undefined;
|
1163
|
+
sdpMLineIndex: number | undefined;
|
1164
|
+
usernameFragment: string | undefined;
|
1165
|
+
}): Promise<void>;
|
1166
|
+
startCall(
|
1167
|
+
localVideoRef: any,
|
1168
|
+
remoteVideoRef: any,
|
1169
|
+
grant_permissions: { video: boolean; audio: boolean }
|
1170
|
+
): Promise<void>;
|
1016
1171
|
}
|
1017
1172
|
|
1018
1173
|
/** Reports an error received from a socket message. */
|
@@ -1034,13 +1189,13 @@ export class DefaultSocket implements Socket {
|
|
1034
1189
|
private _heartbeatTimeoutMs: number;
|
1035
1190
|
|
1036
1191
|
constructor(
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1192
|
+
readonly host: string,
|
1193
|
+
readonly port: string,
|
1194
|
+
readonly useSSL: boolean = false,
|
1195
|
+
public verbose: boolean = false,
|
1196
|
+
readonly adapter: WebSocketAdapter = new WebSocketAdapterText(),
|
1197
|
+
readonly sendTimeoutMs: number = DefaultSocket.DefaultSendTimeoutMs
|
1198
|
+
) {
|
1044
1199
|
this.cIds = {};
|
1045
1200
|
this.nextCid = 1;
|
1046
1201
|
this._heartbeatTimeoutMs = DefaultSocket.DefaultHeartbeatTimeoutMs;
|
@@ -1056,23 +1211,37 @@ export class DefaultSocket implements Socket {
|
|
1056
1211
|
return this.adapter.isOpen();
|
1057
1212
|
}
|
1058
1213
|
|
1059
|
-
connect(
|
1214
|
+
connect(
|
1215
|
+
session: Session,
|
1216
|
+
createStatus: boolean = false,
|
1217
|
+
platform: string = "",
|
1218
|
+
connectTimeoutMs: number = DefaultSocket.DefaultConnectTimeoutMs,
|
1219
|
+
signal?: AbortSignal
|
1220
|
+
): Promise<Session> {
|
1060
1221
|
if (this.adapter.isOpen()) {
|
1061
1222
|
return Promise.resolve(session);
|
1062
1223
|
}
|
1063
1224
|
|
1064
|
-
const scheme =
|
1065
|
-
this.adapter.connect(
|
1225
|
+
const scheme = this.useSSL ? "wss://" : "ws://";
|
1226
|
+
this.adapter.connect(
|
1227
|
+
scheme,
|
1228
|
+
this.host,
|
1229
|
+
this.port,
|
1230
|
+
createStatus,
|
1231
|
+
session.token,
|
1232
|
+
platform,
|
1233
|
+
signal
|
1234
|
+
);
|
1066
1235
|
|
1067
1236
|
this.adapter.onClose = (evt: Event) => {
|
1068
1237
|
this.ondisconnect(evt);
|
1069
|
-
}
|
1238
|
+
};
|
1070
1239
|
|
1071
1240
|
this.adapter.onError = (evt: Event) => {
|
1072
1241
|
this.onerror(evt);
|
1073
|
-
}
|
1242
|
+
};
|
1074
1243
|
|
1075
|
-
this.adapter.onMessage = (message: any) => {
|
1244
|
+
this.adapter.onMessage = async (message: any) => {
|
1076
1245
|
if (this.verbose && window && window.console) {
|
1077
1246
|
console.log("Response: %o", JSON.stringify(message));
|
1078
1247
|
}
|
@@ -1081,8 +1250,8 @@ export class DefaultSocket implements Socket {
|
|
1081
1250
|
if (!message.cid) {
|
1082
1251
|
if (message.notifications) {
|
1083
1252
|
message.notifications.notifications.forEach((n: ApiNotification) => {
|
1084
|
-
|
1085
|
-
|
1253
|
+
n.content = n.content ? JSON.parse(n.content) : undefined;
|
1254
|
+
this.onnotification(n);
|
1086
1255
|
});
|
1087
1256
|
} else if (message.voice_started_event) {
|
1088
1257
|
this.onvoicestarted(message.voice_started_event);
|
@@ -1091,19 +1260,19 @@ export class DefaultSocket implements Socket {
|
|
1091
1260
|
} else if (message.voice_joined_event) {
|
1092
1261
|
this.onvoicejoined(message.voice_joined_event);
|
1093
1262
|
} else if (message.voice_leaved_event) {
|
1094
|
-
this.onvoiceleaved(message.voice_leaved_event);
|
1263
|
+
this.onvoiceleaved(message.voice_leaved_event);
|
1095
1264
|
} else if (message.channel_created_event) {
|
1096
1265
|
this.onchannelcreated(message.channel_created_event);
|
1097
1266
|
} else if (message.role_event) {
|
1098
1267
|
this.onroleevent(message.role_event);
|
1099
|
-
} else if(message.event_emoji) {
|
1268
|
+
} else if (message.event_emoji) {
|
1100
1269
|
this.oneventemoji(message.event_emoji);
|
1101
1270
|
} else if (message.channel_deleted_event) {
|
1102
1271
|
this.onchanneldeleted(message.channel_deleted_event);
|
1103
1272
|
} else if (message.clan_deleted_event) {
|
1104
|
-
this.onclandeleted(message.clan_deleted_event);
|
1273
|
+
this.onclandeleted(message.clan_deleted_event);
|
1105
1274
|
} else if (message.sticker_create_event) {
|
1106
|
-
this.onstickercreated(message.sticker_create_event);
|
1275
|
+
this.onstickercreated(message.sticker_create_event);
|
1107
1276
|
} else if (message.sticker_update_event) {
|
1108
1277
|
this.onstickerupdated(message.sticker_update_event);
|
1109
1278
|
} else if (message.sticker_delete_event) {
|
@@ -1117,36 +1286,40 @@ export class DefaultSocket implements Socket {
|
|
1117
1286
|
} else if (message.last_seen_message_event) {
|
1118
1287
|
this.onlastseenupdated(message.last_seen_message_event);
|
1119
1288
|
} else if (message.status_presence_event) {
|
1120
|
-
this.onstatuspresence(
|
1289
|
+
this.onstatuspresence(
|
1290
|
+
<StatusPresenceEvent>message.status_presence_event
|
1291
|
+
);
|
1121
1292
|
} else if (message.stream_presence_event) {
|
1122
|
-
this.onstreampresence(
|
1293
|
+
this.onstreampresence(
|
1294
|
+
<StreamPresenceEvent>message.stream_presence_event
|
1295
|
+
);
|
1123
1296
|
} else if (message.stream_data) {
|
1124
1297
|
this.onstreamdata(<StreamData>message.stream_data);
|
1125
1298
|
} else if (message.channel_message) {
|
1126
1299
|
var content, reactions, mentions, attachments, references;
|
1127
|
-
try {
|
1300
|
+
try {
|
1128
1301
|
content = JSON.parse(message.channel_message.content);
|
1129
|
-
} catch(e) {
|
1130
|
-
console.log("content is invalid", e)
|
1131
|
-
}
|
1302
|
+
} catch (e) {
|
1303
|
+
console.log("content is invalid", e);
|
1304
|
+
}
|
1132
1305
|
try {
|
1133
1306
|
reactions = JSON.parse(message.channel_message.reactions);
|
1134
|
-
} catch(e) {
|
1135
|
-
console.log("reactions is invalid", e)
|
1136
|
-
}
|
1307
|
+
} catch (e) {
|
1308
|
+
console.log("reactions is invalid", e);
|
1309
|
+
}
|
1137
1310
|
try {
|
1138
1311
|
mentions = JSON.parse(message.channel_message.mentions);
|
1139
|
-
} catch(e) {
|
1140
|
-
console.log("mentions is invalid", e)
|
1141
|
-
}
|
1312
|
+
} catch (e) {
|
1313
|
+
console.log("mentions is invalid", e);
|
1314
|
+
}
|
1142
1315
|
try {
|
1143
1316
|
attachments = JSON.parse(message.channel_message.attachments);
|
1144
|
-
} catch(e) {
|
1145
|
-
console.log("attachments is invalid", e)
|
1317
|
+
} catch (e) {
|
1318
|
+
console.log("attachments is invalid", e);
|
1146
1319
|
}
|
1147
1320
|
try {
|
1148
1321
|
references = JSON.parse(message.channel_message.references);
|
1149
|
-
} catch(e) {
|
1322
|
+
} catch (e) {
|
1150
1323
|
console.log("references is invalid", e);
|
1151
1324
|
}
|
1152
1325
|
var e: ChannelMessage = {
|
@@ -1156,7 +1329,7 @@ export class DefaultSocket implements Socket {
|
|
1156
1329
|
mode: message.channel_message.mode,
|
1157
1330
|
channel_label: message.channel_message.channel_label,
|
1158
1331
|
clan_id: message.channel_message.clan_id,
|
1159
|
-
code: message.channel_message.code,
|
1332
|
+
code: message.channel_message.code,
|
1160
1333
|
create_time: message.channel_message.create_time,
|
1161
1334
|
message_id: message.channel_message.message_id,
|
1162
1335
|
sender_id: message.channel_message.sender_id,
|
@@ -1173,55 +1346,127 @@ export class DefaultSocket implements Socket {
|
|
1173
1346
|
attachments: attachments,
|
1174
1347
|
references: references,
|
1175
1348
|
hide_editted: message.channel_message.hide_editted,
|
1176
|
-
is_public: message.channel_message.is_public,
|
1349
|
+
is_public: message.channel_message.is_public,
|
1177
1350
|
create_time_seconds: message.channel_message.create_time_seconds,
|
1178
1351
|
update_time_seconds: message.channel_message.update_time_seconds,
|
1179
1352
|
};
|
1180
|
-
this.onchannelmessage(e);
|
1353
|
+
this.onchannelmessage(e);
|
1181
1354
|
} else if (message.message_typing_event) {
|
1182
|
-
this.onmessagetyping(
|
1355
|
+
this.onmessagetyping(
|
1356
|
+
<MessageTypingEvent>message.message_typing_event
|
1357
|
+
);
|
1183
1358
|
} else if (message.message_reaction_event) {
|
1184
|
-
this.onmessagereaction(
|
1359
|
+
this.onmessagereaction(
|
1360
|
+
<ApiMessageReaction>message.message_reaction_event
|
1361
|
+
);
|
1185
1362
|
} else if (message.channel_presence_event) {
|
1186
|
-
this.onchannelpresence(
|
1363
|
+
this.onchannelpresence(
|
1364
|
+
<ChannelPresenceEvent>message.channel_presence_event
|
1365
|
+
);
|
1187
1366
|
} else if (message.last_pin_message_event) {
|
1188
|
-
this.onpinmessage(
|
1367
|
+
this.onpinmessage(
|
1368
|
+
<LastPinMessageEvent>message.last_pin_message_event
|
1369
|
+
);
|
1189
1370
|
} else if (message.custom_status_event) {
|
1190
1371
|
this.oncustomstatus(<CustomStatusEvent>message.custom_status_event);
|
1191
1372
|
} else if (message.user_channel_added_event) {
|
1192
|
-
this.onuserchanneladded(
|
1373
|
+
this.onuserchanneladded(
|
1374
|
+
<UserChannelAddedEvent>message.user_channel_added_event
|
1375
|
+
);
|
1193
1376
|
} else if (message.add_clan_user_event) {
|
1194
1377
|
this.onuserclanadded(<AddClanUserEvent>message.add_clan_user_event);
|
1195
1378
|
} else if (message.user_profile_updated_event) {
|
1196
|
-
this.onuserprofileupdate(
|
1379
|
+
this.onuserprofileupdate(
|
1380
|
+
<UserProfileUpdatedEvent>message.user_profile_updated_event
|
1381
|
+
);
|
1197
1382
|
} else if (message.user_channel_removed_event) {
|
1198
|
-
this.onuserchannelremoved(
|
1383
|
+
this.onuserchannelremoved(
|
1384
|
+
<UserChannelRemovedEvent>message.user_channel_removed_event
|
1385
|
+
);
|
1199
1386
|
} else if (message.user_clan_removed_event) {
|
1200
|
-
this.onuserclanremoved(
|
1201
|
-
|
1387
|
+
this.onuserclanremoved(
|
1388
|
+
<UserClanRemovedEvent>message.user_clan_removed_event
|
1389
|
+
);
|
1390
|
+
} else if (message.clan_event_created) {
|
1202
1391
|
this.oneventcreated(message.clan_event_created);
|
1203
|
-
} else if(message.give_coffee_event){
|
1392
|
+
} else if (message.give_coffee_event) {
|
1204
1393
|
this.oncoffeegiven(<ApiGiveCoffeeEvent>message.give_coffee_event);
|
1205
|
-
} else if(message.role_assign_event){
|
1394
|
+
} else if (message.role_assign_event) {
|
1206
1395
|
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.
|
1396
|
+
} else if (message.streaming_started_event) {
|
1397
|
+
this.onstreamingchannelstarted(
|
1398
|
+
<StreamingStartedEvent>message.streaming_started_event
|
1399
|
+
);
|
1400
|
+
} else if (message.streaming_ended_event) {
|
1401
|
+
this.onstreamingchannelended(
|
1402
|
+
<StreamingEndedEvent>message.streaming_ended_event
|
1403
|
+
);
|
1404
|
+
} else if (message.streaming_joined_event) {
|
1405
|
+
this.onstreamingchanneljoined(
|
1406
|
+
<StreamingJoinedEvent>message.streaming_joined_event
|
1407
|
+
);
|
1408
|
+
} else if (message.streaming_leaved_event) {
|
1409
|
+
this.onstreamingchannelleaved(
|
1410
|
+
<StreamingLeavedEvent>message.streaming_leaved_event
|
1411
|
+
);
|
1412
|
+
} else if (message.permission_set_event) {
|
1216
1413
|
this.onpermissionset(<PermissionSet>message.permission_set_event);
|
1217
|
-
} else if(message.permission_changed_event){
|
1218
|
-
this.onpermissionchanged(
|
1219
|
-
|
1414
|
+
} else if (message.permission_changed_event) {
|
1415
|
+
this.onpermissionchanged(
|
1416
|
+
<PermissionChangedEvent>message.permission_changed_event
|
1417
|
+
);
|
1418
|
+
} else if (message.unmute_event) {
|
1220
1419
|
this.onunmuteevent(<UnmuteEvent>message.unmute_event);
|
1221
1420
|
} else if (message.token_sent_event) {
|
1222
1421
|
this.ontokensent(<ApiTokenSentEvent>message.token_sent_event);
|
1223
|
-
} else if (message.message_button_clicked){
|
1224
|
-
this.handleMessageButtonClick(
|
1422
|
+
} else if (message.message_button_clicked) {
|
1423
|
+
this.handleMessageButtonClick(
|
1424
|
+
<MessageButtonClicked>message.message_button_clicked
|
1425
|
+
);
|
1426
|
+
} else if (message.call_request) {
|
1427
|
+
console.log("message.call_request", message.call_request);
|
1428
|
+
await this.adapter.getRTCPeerConnection().setRemoteDescription(
|
1429
|
+
new RTCSessionDescription({
|
1430
|
+
type: "offer",
|
1431
|
+
sdp: message.call_request.sdp,
|
1432
|
+
})
|
1433
|
+
);
|
1434
|
+
const answer = await this.adapter
|
1435
|
+
.getRTCPeerConnection()
|
1436
|
+
.createAnswer();
|
1437
|
+
await this.adapter.getRTCPeerConnection().setLocalDescription(answer);
|
1438
|
+
// Check if WebSocket is initialized before sending message
|
1439
|
+
await this.sendCallAccept({
|
1440
|
+
sdp: answer.sdp,
|
1441
|
+
type: "answer",
|
1442
|
+
});
|
1443
|
+
|
1444
|
+
this.onCallRequest(<CallRequest>message.call_request);
|
1445
|
+
} else if (message.call_accept) {
|
1446
|
+
console.log("message.call_accept", message.call_accept);
|
1447
|
+
await this.adapter.getRTCPeerConnection().setRemoteDescription(
|
1448
|
+
new RTCSessionDescription({
|
1449
|
+
type: "answer",
|
1450
|
+
sdp: message.call_accept.sdp,
|
1451
|
+
})
|
1452
|
+
);
|
1453
|
+
|
1454
|
+
this.onCallAccept(<CallAccept>message.call_accept);
|
1455
|
+
} else if (message.ice_candidate_init) {
|
1456
|
+
console.log("message.ice_candidate_init", message.ice_candidate_init);
|
1457
|
+
const rtcIceCandidate = new RTCIceCandidate({
|
1458
|
+
candidate: message.ice_candidate_init.candidate,
|
1459
|
+
sdpMid: message.ice_candidate_init.sdpMid || "audio",
|
1460
|
+
sdpMLineIndex: message.ice_candidate_init.sdpMLineIndex || 0,
|
1461
|
+
usernameFragment:
|
1462
|
+
message.ice_candidate_init.usernameFragment || undefined,
|
1463
|
+
});
|
1464
|
+
|
1465
|
+
await this.adapter
|
1466
|
+
.getRTCPeerConnection()
|
1467
|
+
.addIceCandidate(rtcIceCandidate);
|
1468
|
+
|
1469
|
+
this.onIceCandidateInit(<ICECandidateInit>message.ice_candidate_init);
|
1225
1470
|
} else {
|
1226
1471
|
if (this.verbose && window && window.console) {
|
1227
1472
|
console.log("Unrecognized message received: %o", message);
|
@@ -1243,7 +1488,7 @@ export class DefaultSocket implements Socket {
|
|
1243
1488
|
executor.resolve(message);
|
1244
1489
|
}
|
1245
1490
|
}
|
1246
|
-
}
|
1491
|
+
};
|
1247
1492
|
|
1248
1493
|
return new Promise((resolve, reject) => {
|
1249
1494
|
this.adapter.onOpen = (evt: Event) => {
|
@@ -1253,11 +1498,11 @@ export class DefaultSocket implements Socket {
|
|
1253
1498
|
|
1254
1499
|
this.pingPong();
|
1255
1500
|
resolve(session);
|
1256
|
-
}
|
1501
|
+
};
|
1257
1502
|
this.adapter.onError = (evt: Event) => {
|
1258
1503
|
reject(evt);
|
1259
1504
|
this.adapter.close();
|
1260
|
-
}
|
1505
|
+
};
|
1261
1506
|
|
1262
1507
|
setTimeout(() => {
|
1263
1508
|
// if promise has resolved by now, the reject() is a no-op
|
@@ -1275,11 +1520,11 @@ export class DefaultSocket implements Socket {
|
|
1275
1520
|
}
|
1276
1521
|
}
|
1277
1522
|
|
1278
|
-
setHeartbeatTimeoutMs(ms
|
1523
|
+
setHeartbeatTimeoutMs(ms: number) {
|
1279
1524
|
this._heartbeatTimeoutMs = ms;
|
1280
1525
|
}
|
1281
1526
|
|
1282
|
-
getHeartbeatTimeoutMs()
|
1527
|
+
getHeartbeatTimeoutMs(): number {
|
1283
1528
|
return this._heartbeatTimeoutMs;
|
1284
1529
|
}
|
1285
1530
|
|
@@ -1336,7 +1581,7 @@ export class DefaultSocket implements Socket {
|
|
1336
1581
|
console.log(user);
|
1337
1582
|
}
|
1338
1583
|
}
|
1339
|
-
|
1584
|
+
|
1340
1585
|
onuserchannelremoved(user: UserChannelRemovedEvent) {
|
1341
1586
|
if (this.verbose && window && window.console) {
|
1342
1587
|
console.log(user);
|
@@ -1439,7 +1684,6 @@ export class DefaultSocket implements Socket {
|
|
1439
1684
|
}
|
1440
1685
|
}
|
1441
1686
|
|
1442
|
-
|
1443
1687
|
onchannelupdated(channelUpdated: ChannelUpdatedEvent) {
|
1444
1688
|
if (this.verbose && window && window.console) {
|
1445
1689
|
console.log(channelUpdated);
|
@@ -1529,20 +1773,20 @@ export class DefaultSocket implements Socket {
|
|
1529
1773
|
console.log(streaming_leaved_event);
|
1530
1774
|
}
|
1531
1775
|
}
|
1532
|
-
|
1533
|
-
onpermissionset(permission_set_event: PermissionSet){
|
1776
|
+
|
1777
|
+
onpermissionset(permission_set_event: PermissionSet) {
|
1534
1778
|
if (this.verbose && window && window.console) {
|
1535
1779
|
console.log(permission_set_event);
|
1536
1780
|
}
|
1537
1781
|
}
|
1538
1782
|
|
1539
|
-
onpermissionchanged(permission_changed_event: PermissionChangedEvent){
|
1783
|
+
onpermissionchanged(permission_changed_event: PermissionChangedEvent) {
|
1540
1784
|
if (this.verbose && window && window.console) {
|
1541
1785
|
console.log(permission_changed_event);
|
1542
1786
|
}
|
1543
1787
|
}
|
1544
1788
|
|
1545
|
-
onunmuteevent(unmute_event: UnmuteEvent){
|
1789
|
+
onunmuteevent(unmute_event: UnmuteEvent) {
|
1546
1790
|
if (this.verbose && window && window.console) {
|
1547
1791
|
console.log(unmute_event);
|
1548
1792
|
}
|
@@ -1560,25 +1804,64 @@ export class DefaultSocket implements Socket {
|
|
1560
1804
|
}
|
1561
1805
|
}
|
1562
1806
|
|
1563
|
-
|
1564
|
-
|
1807
|
+
onCallRequest(callRequest: CallRequest) {
|
1808
|
+
if (this.verbose && window && window.console) {
|
1809
|
+
console.log(callRequest);
|
1810
|
+
}
|
1811
|
+
}
|
1812
|
+
|
1813
|
+
onCallAccept(callAccept: CallAccept) {
|
1814
|
+
if (this.verbose && window && window.console) {
|
1815
|
+
console.log(callAccept);
|
1816
|
+
}
|
1817
|
+
}
|
1818
|
+
|
1819
|
+
onIceCandidateInit(iceCandidateInit: ICECandidateInit) {
|
1820
|
+
if (this.verbose && window && window.console) {
|
1821
|
+
console.log(iceCandidateInit);
|
1822
|
+
}
|
1823
|
+
}
|
1824
|
+
|
1825
|
+
send(
|
1826
|
+
message:
|
1827
|
+
| ChannelJoin
|
1828
|
+
| ChannelLeave
|
1829
|
+
| ChannelMessageSend
|
1830
|
+
| ChannelMessageUpdate
|
1831
|
+
| CustomStatusEvent
|
1832
|
+
| ChannelMessageRemove
|
1833
|
+
| MessageTypingEvent
|
1834
|
+
| LastSeenMessageEvent
|
1835
|
+
| Rpc
|
1836
|
+
| StatusFollow
|
1837
|
+
| StatusUnfollow
|
1838
|
+
| StatusUpdate
|
1839
|
+
| Ping
|
1840
|
+
| CallRequest
|
1841
|
+
| CallAccept
|
1842
|
+
| ICECandidateInit,
|
1843
|
+
sendTimeout = DefaultSocket.DefaultSendTimeoutMs
|
1844
|
+
): Promise<any> {
|
1565
1845
|
const untypedMessage = message as any;
|
1566
1846
|
|
1567
1847
|
return new Promise<void>((resolve, reject) => {
|
1568
1848
|
if (!this.adapter.isOpen()) {
|
1569
1849
|
reject("Socket connection has not been established yet.");
|
1570
|
-
}
|
1571
|
-
else {
|
1850
|
+
} else {
|
1572
1851
|
if (untypedMessage.channel_message_send) {
|
1573
|
-
untypedMessage.channel_message_send.content = JSON.stringify(
|
1852
|
+
untypedMessage.channel_message_send.content = JSON.stringify(
|
1853
|
+
untypedMessage.channel_message_send.content
|
1854
|
+
);
|
1574
1855
|
} else if (untypedMessage.channel_message_update) {
|
1575
|
-
untypedMessage.channel_message_update.content = JSON.stringify(
|
1856
|
+
untypedMessage.channel_message_update.content = JSON.stringify(
|
1857
|
+
untypedMessage.channel_message_update.content
|
1858
|
+
);
|
1576
1859
|
}
|
1577
1860
|
|
1578
1861
|
const cid = this.generatecid();
|
1579
|
-
this.cIds[cid] = {resolve, reject};
|
1862
|
+
this.cIds[cid] = { resolve, reject };
|
1580
1863
|
setTimeout(() => {
|
1581
|
-
reject("The socket timed out while waiting for a response.")
|
1864
|
+
reject("The socket timed out while waiting for a response.");
|
1582
1865
|
}, sendTimeout);
|
1583
1866
|
|
1584
1867
|
/** Add id for promise executor. */
|
@@ -1588,149 +1871,389 @@ export class DefaultSocket implements Socket {
|
|
1588
1871
|
});
|
1589
1872
|
}
|
1590
1873
|
|
1591
|
-
|
1592
|
-
|
1874
|
+
getRTCPeerConnection(): RTCPeerConnection {
|
1875
|
+
return this.adapter.getRTCPeerConnection();
|
1876
|
+
}
|
1877
|
+
|
1878
|
+
async startCall(
|
1879
|
+
localVideoRef: any,
|
1880
|
+
remoteVideoRef: any,
|
1881
|
+
grant_permissions: { video: boolean; audio: boolean }
|
1882
|
+
): Promise<void> {
|
1883
|
+
// setup peer connection
|
1884
|
+
this.adapter.getRTCPeerConnection().onicecandidate = (event: any) => {
|
1885
|
+
if (event && event.candidate) {
|
1886
|
+
this.sendICECandidateInit({ candidate: event?.candidate });
|
1887
|
+
}
|
1888
|
+
};
|
1889
|
+
|
1890
|
+
this.adapter.getRTCPeerConnection().ontrack = (event) => {
|
1891
|
+
// Display remote stream in remote video element
|
1892
|
+
if (remoteVideoRef) {
|
1893
|
+
remoteVideoRef.srcObject = event.streams[0];
|
1894
|
+
}
|
1895
|
+
};
|
1896
|
+
// Get user media
|
1897
|
+
const stream = await navigator.mediaDevices.getUserMedia(grant_permissions);
|
1898
|
+
if (localVideoRef) {
|
1899
|
+
localVideoRef.srcObject = stream;
|
1900
|
+
}
|
1901
|
+
// Add tracks to PeerConnection
|
1902
|
+
stream
|
1903
|
+
.getTracks()
|
1904
|
+
.forEach((track) =>
|
1905
|
+
this.adapter.getRTCPeerConnection()?.addTrack(track, stream)
|
1906
|
+
);
|
1907
|
+
|
1908
|
+
// Create offer and send it to backend via WebSocket
|
1909
|
+
const offer = await this.adapter.getRTCPeerConnection().createOffer();
|
1910
|
+
await this.adapter.getRTCPeerConnection().setLocalDescription(offer);
|
1911
|
+
await this.sendCallRequest({
|
1912
|
+
sdp: offer?.sdp,
|
1913
|
+
type: "offer",
|
1914
|
+
});
|
1915
|
+
}
|
1916
|
+
|
1917
|
+
async sendCallRequest(req: { type: string; sdp?: string }): Promise<void> {
|
1918
|
+
return await this.send({ call_request: req });
|
1919
|
+
}
|
1920
|
+
|
1921
|
+
async sendCallAccept(req: { type: string; sdp?: string }): Promise<void> {
|
1922
|
+
return await this.send({ call_accept: req });
|
1923
|
+
}
|
1924
|
+
|
1925
|
+
async sendICECandidateInit(req: {
|
1926
|
+
candidate: string;
|
1927
|
+
sdpMid?: string | undefined;
|
1928
|
+
sdpMLineIndex?: number | undefined;
|
1929
|
+
usernameFragment?: string | undefined;
|
1930
|
+
}): Promise<void> {
|
1931
|
+
return await this.send({ ice_candidate_init: req });
|
1932
|
+
}
|
1933
|
+
|
1934
|
+
async followUsers(userIds: string[]): Promise<Status> {
|
1935
|
+
const response = await this.send({ status_follow: { user_ids: userIds } });
|
1593
1936
|
return response.status;
|
1594
1937
|
}
|
1595
1938
|
|
1596
1939
|
async joinClanChat(clan_id: string): Promise<ClanJoin> {
|
1597
|
-
|
1598
1940
|
const response = await this.send({
|
1599
1941
|
clan_join: {
|
1600
|
-
|
1601
|
-
}
|
1942
|
+
clan_id: clan_id,
|
1943
|
+
},
|
1602
1944
|
});
|
1603
1945
|
|
1604
1946
|
return response.clan_join;
|
1605
1947
|
}
|
1606
1948
|
|
1607
|
-
async joinChat(
|
1608
|
-
|
1949
|
+
async joinChat(
|
1950
|
+
clan_id: string,
|
1951
|
+
channel_id: string,
|
1952
|
+
channel_type: number,
|
1953
|
+
is_public: boolean
|
1954
|
+
): Promise<Channel> {
|
1609
1955
|
const response = await this.send({
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
);
|
1956
|
+
channel_join: {
|
1957
|
+
clan_id: clan_id,
|
1958
|
+
channel_id: channel_id,
|
1959
|
+
channel_type: channel_type,
|
1960
|
+
is_public: is_public,
|
1961
|
+
},
|
1962
|
+
});
|
1618
1963
|
|
1619
1964
|
return response.channel;
|
1620
1965
|
}
|
1621
1966
|
|
1622
|
-
leaveChat(
|
1623
|
-
|
1967
|
+
leaveChat(
|
1968
|
+
clan_id: string,
|
1969
|
+
channel_id: string,
|
1970
|
+
channel_type: number,
|
1971
|
+
is_public: boolean
|
1972
|
+
): Promise<void> {
|
1973
|
+
return this.send({
|
1974
|
+
channel_leave: {
|
1975
|
+
clan_id: clan_id,
|
1976
|
+
channel_id: channel_id,
|
1977
|
+
channel_type: channel_type,
|
1978
|
+
is_public: is_public,
|
1979
|
+
},
|
1980
|
+
});
|
1624
1981
|
}
|
1625
1982
|
|
1626
|
-
async removeChatMessage(
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1983
|
+
async removeChatMessage(
|
1984
|
+
clan_id: string,
|
1985
|
+
channel_id: string,
|
1986
|
+
mode: number,
|
1987
|
+
is_public: boolean,
|
1988
|
+
message_id: string
|
1989
|
+
): Promise<ChannelMessageAck> {
|
1990
|
+
const response = await this.send({
|
1991
|
+
channel_message_remove: {
|
1992
|
+
clan_id: clan_id,
|
1993
|
+
channel_id: channel_id,
|
1994
|
+
mode: mode,
|
1995
|
+
message_id: message_id,
|
1996
|
+
is_public: is_public,
|
1997
|
+
},
|
1998
|
+
});
|
1638
1999
|
|
1639
2000
|
return response.channel_message_ack;
|
1640
2001
|
}
|
1641
2002
|
|
1642
2003
|
async rpc(id?: string, payload?: string, http_key?: string): Promise<ApiRpc> {
|
1643
|
-
const response = await this.send(
|
1644
|
-
{
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
});
|
2004
|
+
const response = await this.send({
|
2005
|
+
rpc: {
|
2006
|
+
id: id,
|
2007
|
+
payload: payload,
|
2008
|
+
http_key: http_key,
|
2009
|
+
},
|
2010
|
+
});
|
1651
2011
|
|
1652
|
-
|
2012
|
+
return response.rpc;
|
1653
2013
|
}
|
1654
2014
|
|
1655
|
-
unfollowUsers(user_ids
|
1656
|
-
return this.send({status_unfollow: {user_ids: user_ids}});
|
2015
|
+
unfollowUsers(user_ids: string[]): Promise<void> {
|
2016
|
+
return this.send({ status_unfollow: { user_ids: user_ids } });
|
1657
2017
|
}
|
1658
2018
|
|
1659
|
-
async updateChatMessage(
|
1660
|
-
|
2019
|
+
async updateChatMessage(
|
2020
|
+
clan_id: string,
|
2021
|
+
channel_id: string,
|
2022
|
+
mode: number,
|
2023
|
+
is_public: boolean,
|
2024
|
+
message_id: string,
|
2025
|
+
content: any,
|
2026
|
+
mentions?: Array<ApiMessageMention>,
|
2027
|
+
attachments?: Array<ApiMessageAttachment>,
|
2028
|
+
hideEditted?: boolean
|
2029
|
+
): Promise<ChannelMessageAck> {
|
2030
|
+
const response = await this.send({
|
2031
|
+
channel_message_update: {
|
2032
|
+
clan_id: clan_id,
|
2033
|
+
channel_id: channel_id,
|
2034
|
+
message_id: message_id,
|
2035
|
+
content: content,
|
2036
|
+
mentions: mentions,
|
2037
|
+
attachments: attachments,
|
2038
|
+
mode: mode,
|
2039
|
+
is_public: is_public,
|
2040
|
+
hide_editted: hideEditted,
|
2041
|
+
},
|
2042
|
+
});
|
1661
2043
|
return response.channel_message_ack;
|
1662
2044
|
}
|
1663
2045
|
|
1664
2046
|
updateStatus(status?: string): Promise<void> {
|
1665
|
-
return this.send({status_update: {status: status}});
|
2047
|
+
return this.send({ status_update: { status: status } });
|
1666
2048
|
}
|
1667
2049
|
|
1668
|
-
async writeChatMessage(
|
1669
|
-
|
2050
|
+
async writeChatMessage(
|
2051
|
+
clan_id: string,
|
2052
|
+
channel_id: string,
|
2053
|
+
mode: number,
|
2054
|
+
is_public: boolean,
|
2055
|
+
content: any,
|
2056
|
+
mentions?: Array<ApiMessageMention>,
|
2057
|
+
attachments?: Array<ApiMessageAttachment>,
|
2058
|
+
references?: Array<ApiMessageRef>,
|
2059
|
+
anonymous_message?: boolean,
|
2060
|
+
mention_everyone?: Boolean,
|
2061
|
+
avatar?: string
|
2062
|
+
): Promise<ChannelMessageAck> {
|
2063
|
+
const response = await this.send({
|
2064
|
+
channel_message_send: {
|
2065
|
+
clan_id: clan_id,
|
2066
|
+
channel_id: channel_id,
|
2067
|
+
mode: mode,
|
2068
|
+
is_public: is_public,
|
2069
|
+
content: content,
|
2070
|
+
mentions: mentions,
|
2071
|
+
attachments: attachments,
|
2072
|
+
references: references,
|
2073
|
+
anonymous_message: anonymous_message,
|
2074
|
+
mention_everyone: mention_everyone,
|
2075
|
+
avatar: avatar,
|
2076
|
+
},
|
2077
|
+
});
|
1670
2078
|
return response.channel_message_ack;
|
1671
2079
|
}
|
1672
2080
|
|
1673
|
-
async writeMessageReaction(
|
1674
|
-
|
2081
|
+
async writeMessageReaction(
|
2082
|
+
id: string,
|
2083
|
+
clan_id: string,
|
2084
|
+
channel_id: string,
|
2085
|
+
mode: number,
|
2086
|
+
is_public: boolean,
|
2087
|
+
message_id: string,
|
2088
|
+
emoji_id: string,
|
2089
|
+
emoji: string,
|
2090
|
+
count: number,
|
2091
|
+
message_sender_id: string,
|
2092
|
+
action_delete: boolean
|
2093
|
+
): Promise<ApiMessageReaction> {
|
2094
|
+
const response = await this.send({
|
2095
|
+
message_reaction_event: {
|
2096
|
+
id: id,
|
2097
|
+
clan_id: clan_id,
|
2098
|
+
channel_id: channel_id,
|
2099
|
+
mode: mode,
|
2100
|
+
is_public: is_public,
|
2101
|
+
message_id: message_id,
|
2102
|
+
emoji_id: emoji_id,
|
2103
|
+
emoji: emoji,
|
2104
|
+
count: count,
|
2105
|
+
message_sender_id: message_sender_id,
|
2106
|
+
action: action_delete,
|
2107
|
+
},
|
2108
|
+
});
|
1675
2109
|
return response.message_reaction_event;
|
1676
2110
|
}
|
1677
2111
|
|
1678
|
-
async writeMessageTyping(
|
1679
|
-
|
2112
|
+
async writeMessageTyping(
|
2113
|
+
clan_id: string,
|
2114
|
+
channel_id: string,
|
2115
|
+
mode: number,
|
2116
|
+
is_public: boolean
|
2117
|
+
): Promise<MessageTypingEvent> {
|
2118
|
+
const response = await this.send({
|
2119
|
+
message_typing_event: {
|
2120
|
+
clan_id: clan_id,
|
2121
|
+
channel_id: channel_id,
|
2122
|
+
mode: mode,
|
2123
|
+
is_public: is_public,
|
2124
|
+
},
|
2125
|
+
});
|
1680
2126
|
return response.message_typing_event;
|
1681
2127
|
}
|
1682
2128
|
|
1683
|
-
async writeLastSeenMessage(
|
1684
|
-
|
2129
|
+
async writeLastSeenMessage(
|
2130
|
+
clan_id: string,
|
2131
|
+
channel_id: string,
|
2132
|
+
mode: number,
|
2133
|
+
message_id: string,
|
2134
|
+
timestamp_seconds: number
|
2135
|
+
): Promise<LastSeenMessageEvent> {
|
2136
|
+
const response = await this.send({
|
2137
|
+
last_seen_message_event: {
|
2138
|
+
clan_id: clan_id,
|
2139
|
+
channel_id: channel_id,
|
2140
|
+
mode: mode,
|
2141
|
+
message_id: message_id,
|
2142
|
+
timestamp_seconds: timestamp_seconds,
|
2143
|
+
},
|
2144
|
+
});
|
1685
2145
|
return response.last_seen_message_event;
|
1686
2146
|
}
|
1687
2147
|
|
1688
|
-
async writeLastPinMessage(
|
1689
|
-
|
2148
|
+
async writeLastPinMessage(
|
2149
|
+
clan_id: string,
|
2150
|
+
channel_id: string,
|
2151
|
+
mode: number,
|
2152
|
+
is_public: boolean,
|
2153
|
+
message_id: string,
|
2154
|
+
timestamp_seconds: number,
|
2155
|
+
operation: number
|
2156
|
+
): Promise<LastPinMessageEvent> {
|
2157
|
+
const response = await this.send({
|
2158
|
+
last_pin_message_event: {
|
2159
|
+
clan_id: clan_id,
|
2160
|
+
channel_id: channel_id,
|
2161
|
+
mode: mode,
|
2162
|
+
is_public: is_public,
|
2163
|
+
message_id: message_id,
|
2164
|
+
timestamp_seconds: timestamp_seconds,
|
2165
|
+
operation: operation,
|
2166
|
+
},
|
2167
|
+
});
|
1690
2168
|
return response.last_pin_message_event;
|
1691
2169
|
}
|
1692
2170
|
|
1693
|
-
async writeVoiceJoined(
|
1694
|
-
|
2171
|
+
async writeVoiceJoined(
|
2172
|
+
id: string,
|
2173
|
+
clanId: string,
|
2174
|
+
clanName: string,
|
2175
|
+
voiceChannelId: string,
|
2176
|
+
voiceChannelLabel: string,
|
2177
|
+
participant: string,
|
2178
|
+
lastScreenshot: string
|
2179
|
+
): Promise<VoiceJoinedEvent> {
|
2180
|
+
const response = await this.send({
|
2181
|
+
voice_joined_event: {
|
2182
|
+
clan_id: clanId,
|
2183
|
+
clan_name: clanName,
|
2184
|
+
id: id,
|
2185
|
+
participant: participant,
|
2186
|
+
voice_channel_id: voiceChannelId,
|
2187
|
+
voice_channel_label: voiceChannelLabel,
|
2188
|
+
last_screenshot: lastScreenshot,
|
2189
|
+
},
|
2190
|
+
});
|
1695
2191
|
return response.voice_joined_event;
|
1696
2192
|
}
|
1697
2193
|
|
1698
|
-
async writeVoiceLeaved(
|
1699
|
-
|
2194
|
+
async writeVoiceLeaved(
|
2195
|
+
id: string,
|
2196
|
+
clanId: string,
|
2197
|
+
voiceChannelId: string,
|
2198
|
+
voiceUserId: string
|
2199
|
+
): Promise<VoiceLeavedEvent> {
|
2200
|
+
const response = await this.send({
|
2201
|
+
voice_leaved_event: {
|
2202
|
+
id: id,
|
2203
|
+
clan_id: clanId,
|
2204
|
+
voice_channel_id: voiceChannelId,
|
2205
|
+
voice_user_id: voiceUserId,
|
2206
|
+
},
|
2207
|
+
});
|
1700
2208
|
return response.voice_leaved_event;
|
1701
2209
|
}
|
1702
2210
|
|
1703
|
-
async writeCustomStatus(
|
1704
|
-
|
2211
|
+
async writeCustomStatus(
|
2212
|
+
clan_id: string,
|
2213
|
+
status: string
|
2214
|
+
): Promise<CustomStatusEvent> {
|
2215
|
+
const response = await this.send({
|
2216
|
+
custom_status_event: { clan_id: clan_id, status: status },
|
2217
|
+
});
|
1705
2218
|
return response.custom_status_event;
|
1706
2219
|
}
|
1707
|
-
|
1708
|
-
async checkDuplicateName(
|
1709
|
-
|
2220
|
+
|
2221
|
+
async checkDuplicateName(
|
2222
|
+
name: string,
|
2223
|
+
condition_id: string,
|
2224
|
+
type: number
|
2225
|
+
): Promise<CheckNameExistedEvent> {
|
2226
|
+
const response = await this.send({
|
2227
|
+
check_name_existed_event: {
|
2228
|
+
name: name,
|
2229
|
+
condition_id: condition_id,
|
2230
|
+
type: type,
|
2231
|
+
},
|
2232
|
+
});
|
1710
2233
|
return response.check_name_existed_event;
|
1711
2234
|
}
|
1712
2235
|
|
1713
2236
|
private async pingPong(): Promise<void> {
|
1714
2237
|
if (!this.adapter.isOpen()) {
|
1715
|
-
|
2238
|
+
return;
|
1716
2239
|
}
|
1717
2240
|
|
1718
2241
|
try {
|
1719
|
-
|
2242
|
+
await this.send({ ping: {} }, this._heartbeatTimeoutMs);
|
1720
2243
|
} catch {
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
}
|
1725
|
-
this.onheartbeattimeout();
|
1726
|
-
this.adapter.close();
|
2244
|
+
if (this.adapter.isOpen()) {
|
2245
|
+
if (window && window.console) {
|
2246
|
+
console.error("Server unreachable from heartbeat.");
|
1727
2247
|
}
|
2248
|
+
this.onheartbeattimeout();
|
2249
|
+
this.adapter.close();
|
2250
|
+
}
|
1728
2251
|
|
1729
|
-
|
2252
|
+
return;
|
1730
2253
|
}
|
1731
2254
|
|
1732
2255
|
// reuse the timeout as the interval for now.
|
1733
2256
|
// we can separate them out into separate values if needed later.
|
1734
2257
|
setTimeout(() => this.pingPong(), this._heartbeatTimeoutMs);
|
1735
2258
|
}
|
1736
|
-
}
|
2259
|
+
}
|