@supabase/realtime-js 2.99.3 → 2.100.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main/RealtimeChannel.d.ts +35 -28
- package/dist/main/RealtimeChannel.d.ts.map +1 -1
- package/dist/main/RealtimeChannel.js +140 -301
- package/dist/main/RealtimeChannel.js.map +1 -1
- package/dist/main/RealtimeClient.d.ts +37 -56
- package/dist/main/RealtimeClient.d.ts.map +1 -1
- package/dist/main/RealtimeClient.js +233 -520
- package/dist/main/RealtimeClient.js.map +1 -1
- package/dist/main/RealtimePresence.d.ts +8 -24
- package/dist/main/RealtimePresence.d.ts.map +1 -1
- package/dist/main/RealtimePresence.js +6 -202
- package/dist/main/RealtimePresence.js.map +1 -1
- package/dist/main/lib/constants.d.ts +39 -35
- package/dist/main/lib/constants.d.ts.map +1 -1
- package/dist/main/lib/constants.js +30 -35
- package/dist/main/lib/constants.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.d.ts.map +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/main/lib/version.js.map +1 -1
- package/dist/main/lib/websocket-factory.d.ts +0 -9
- package/dist/main/lib/websocket-factory.d.ts.map +1 -1
- package/dist/main/lib/websocket-factory.js +0 -12
- package/dist/main/lib/websocket-factory.js.map +1 -1
- package/dist/main/phoenix/channelAdapter.d.ts +32 -0
- package/dist/main/phoenix/channelAdapter.d.ts.map +1 -0
- package/dist/main/phoenix/channelAdapter.js +103 -0
- package/dist/main/phoenix/channelAdapter.js.map +1 -0
- package/dist/main/phoenix/presenceAdapter.d.ts +53 -0
- package/dist/main/phoenix/presenceAdapter.d.ts.map +1 -0
- package/dist/main/phoenix/presenceAdapter.js +93 -0
- package/dist/main/phoenix/presenceAdapter.js.map +1 -0
- package/dist/main/phoenix/socketAdapter.d.ts +38 -0
- package/dist/main/phoenix/socketAdapter.d.ts.map +1 -0
- package/dist/main/phoenix/socketAdapter.js +114 -0
- package/dist/main/phoenix/socketAdapter.js.map +1 -0
- package/dist/main/phoenix/types.d.ts +5 -0
- package/dist/main/phoenix/types.d.ts.map +1 -0
- package/dist/main/phoenix/types.js +3 -0
- package/dist/main/phoenix/types.js.map +1 -0
- package/dist/module/RealtimeChannel.d.ts +35 -28
- package/dist/module/RealtimeChannel.d.ts.map +1 -1
- package/dist/module/RealtimeChannel.js +141 -302
- package/dist/module/RealtimeChannel.js.map +1 -1
- package/dist/module/RealtimeClient.d.ts +37 -56
- package/dist/module/RealtimeClient.d.ts.map +1 -1
- package/dist/module/RealtimeClient.js +234 -521
- package/dist/module/RealtimeClient.js.map +1 -1
- package/dist/module/RealtimePresence.d.ts +8 -24
- package/dist/module/RealtimePresence.d.ts.map +1 -1
- package/dist/module/RealtimePresence.js +5 -202
- package/dist/module/RealtimePresence.js.map +1 -1
- package/dist/module/lib/constants.d.ts +39 -35
- package/dist/module/lib/constants.d.ts.map +1 -1
- package/dist/module/lib/constants.js +30 -35
- package/dist/module/lib/constants.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.d.ts.map +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/module/lib/version.js.map +1 -1
- package/dist/module/lib/websocket-factory.d.ts +0 -9
- package/dist/module/lib/websocket-factory.d.ts.map +1 -1
- package/dist/module/lib/websocket-factory.js +0 -12
- package/dist/module/lib/websocket-factory.js.map +1 -1
- package/dist/module/phoenix/channelAdapter.d.ts +32 -0
- package/dist/module/phoenix/channelAdapter.d.ts.map +1 -0
- package/dist/module/phoenix/channelAdapter.js +100 -0
- package/dist/module/phoenix/channelAdapter.js.map +1 -0
- package/dist/module/phoenix/presenceAdapter.d.ts +53 -0
- package/dist/module/phoenix/presenceAdapter.d.ts.map +1 -0
- package/dist/module/phoenix/presenceAdapter.js +90 -0
- package/dist/module/phoenix/presenceAdapter.js.map +1 -0
- package/dist/module/phoenix/socketAdapter.d.ts +38 -0
- package/dist/module/phoenix/socketAdapter.d.ts.map +1 -0
- package/dist/module/phoenix/socketAdapter.js +111 -0
- package/dist/module/phoenix/socketAdapter.js.map +1 -0
- package/dist/module/phoenix/types.d.ts +5 -0
- package/dist/module/phoenix/types.d.ts.map +1 -0
- package/dist/module/phoenix/types.js +2 -0
- package/dist/module/phoenix/types.js.map +1 -0
- package/dist/tsconfig.module.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/RealtimeChannel.ts +201 -364
- package/src/RealtimeClient.ts +290 -581
- package/src/RealtimePresence.ts +10 -287
- package/src/lib/constants.ts +50 -37
- package/src/lib/version.ts +1 -1
- package/src/lib/websocket-factory.ts +0 -13
- package/src/phoenix/channelAdapter.ts +147 -0
- package/src/phoenix/presenceAdapter.ts +116 -0
- package/src/phoenix/socketAdapter.ts +168 -0
- package/src/phoenix/types.ts +32 -0
- package/dist/main/lib/push.d.ts +0 -48
- package/dist/main/lib/push.d.ts.map +0 -1
- package/dist/main/lib/push.js +0 -102
- package/dist/main/lib/push.js.map +0 -1
- package/dist/main/lib/timer.d.ts +0 -22
- package/dist/main/lib/timer.d.ts.map +0 -1
- package/dist/main/lib/timer.js +0 -39
- package/dist/main/lib/timer.js.map +0 -1
- package/dist/module/lib/push.d.ts +0 -48
- package/dist/module/lib/push.d.ts.map +0 -1
- package/dist/module/lib/push.js +0 -99
- package/dist/module/lib/push.js.map +0 -1
- package/dist/module/lib/timer.d.ts +0 -22
- package/dist/module/lib/timer.d.ts.map +0 -1
- package/dist/module/lib/timer.js +0 -36
- package/dist/module/lib/timer.js.map +0 -1
- package/src/lib/push.ts +0 -121
- package/src/lib/timer.ts +0 -43
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Socket } from '@supabase/phoenix'
|
|
2
|
+
import type {
|
|
3
|
+
Message,
|
|
4
|
+
SocketOnClose,
|
|
5
|
+
SocketOnMessage,
|
|
6
|
+
SocketOnOpen,
|
|
7
|
+
SocketOnError,
|
|
8
|
+
SocketOptions,
|
|
9
|
+
SocketStateChangeCallbacks,
|
|
10
|
+
Vsn,
|
|
11
|
+
Encode,
|
|
12
|
+
Decode,
|
|
13
|
+
HeartbeatCallback,
|
|
14
|
+
Timer,
|
|
15
|
+
} from './types'
|
|
16
|
+
import { CONNECTION_STATE, ConnectionState } from '../lib/constants'
|
|
17
|
+
import type { HeartbeatTimer, WebSocketLikeConstructor } from '../RealtimeClient'
|
|
18
|
+
|
|
19
|
+
export default class SocketAdapter {
|
|
20
|
+
private socket: Socket
|
|
21
|
+
|
|
22
|
+
constructor(endPoint: string, options: SocketOptions) {
|
|
23
|
+
this.socket = new Socket(endPoint, options)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get timeout(): number {
|
|
27
|
+
return this.socket.timeout
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get endPoint(): string {
|
|
31
|
+
return this.socket.endPoint
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get transport(): WebSocketLikeConstructor {
|
|
35
|
+
return this.socket.transport as WebSocketLikeConstructor
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get heartbeatIntervalMs(): number {
|
|
39
|
+
return this.socket.heartbeatIntervalMs
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get heartbeatCallback(): HeartbeatCallback {
|
|
43
|
+
return this.socket.heartbeatCallback
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
set heartbeatCallback(callback: HeartbeatCallback) {
|
|
47
|
+
this.socket.heartbeatCallback = callback
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get heartbeatTimer(): HeartbeatTimer {
|
|
51
|
+
return this.socket.heartbeatTimer
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get pendingHeartbeatRef(): string | null {
|
|
55
|
+
return this.socket.pendingHeartbeatRef
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get reconnectTimer(): Timer {
|
|
59
|
+
return this.socket.reconnectTimer
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get vsn(): Vsn {
|
|
63
|
+
return this.socket.vsn
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get encode(): Encode<void> {
|
|
67
|
+
return this.socket.encode
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get decode(): Decode<void> {
|
|
71
|
+
return this.socket.decode
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get reconnectAfterMs(): (tries: number) => number {
|
|
75
|
+
return this.socket.reconnectAfterMs
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get sendBuffer(): (() => void)[] {
|
|
79
|
+
return this.socket.sendBuffer
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get stateChangeCallbacks(): SocketStateChangeCallbacks {
|
|
83
|
+
return this.socket.stateChangeCallbacks
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
connect() {
|
|
87
|
+
this.socket.connect()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
disconnect(
|
|
91
|
+
callback: () => void,
|
|
92
|
+
code?: number,
|
|
93
|
+
reason?: string,
|
|
94
|
+
timeout: number = 10000
|
|
95
|
+
): Promise<'ok' | 'timeout'> {
|
|
96
|
+
return new Promise((resolve) => {
|
|
97
|
+
setTimeout(() => resolve('timeout'), timeout)
|
|
98
|
+
this.socket.disconnect(
|
|
99
|
+
() => {
|
|
100
|
+
callback()
|
|
101
|
+
resolve('ok')
|
|
102
|
+
},
|
|
103
|
+
code,
|
|
104
|
+
reason
|
|
105
|
+
)
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
push(data: Message<Record<string, unknown>>) {
|
|
110
|
+
this.socket.push(data)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
log(kind: string, msg: string, data?: any) {
|
|
114
|
+
this.socket.log(kind, msg, data)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
makeRef(): string {
|
|
118
|
+
return this.socket.makeRef()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
onOpen(callback: SocketOnOpen) {
|
|
122
|
+
this.socket.onOpen(callback)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
onClose(callback: SocketOnClose) {
|
|
126
|
+
this.socket.onClose(callback)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
onError(callback: SocketOnError) {
|
|
130
|
+
this.socket.onError(callback)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
onMessage(callback: SocketOnMessage) {
|
|
134
|
+
this.socket.onMessage(callback)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
isConnected() {
|
|
138
|
+
return this.socket.isConnected()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
isConnecting() {
|
|
142
|
+
return this.socket.connectionState() == CONNECTION_STATE.connecting
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
isDisconnecting() {
|
|
146
|
+
return this.socket.connectionState() == CONNECTION_STATE.closing
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
connectionState(): ConnectionState {
|
|
150
|
+
// @ts-ignore - requires better typing and exposing type in phoenix
|
|
151
|
+
return this.socket.connectionState()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
endPointURL(): string {
|
|
155
|
+
return this.socket.endPointURL()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
sendHeartbeat() {
|
|
159
|
+
this.socket.sendHeartbeat()
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
getSocket() {
|
|
166
|
+
return this.socket
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
Socket,
|
|
3
|
+
SocketOptions,
|
|
4
|
+
SocketState,
|
|
5
|
+
SocketOnOpen,
|
|
6
|
+
SocketOnError,
|
|
7
|
+
SocketOnMessage,
|
|
8
|
+
SocketOnClose,
|
|
9
|
+
SocketStateChangeCallbacks,
|
|
10
|
+
Channel,
|
|
11
|
+
ChannelState,
|
|
12
|
+
ChannelEvent,
|
|
13
|
+
ChannelBindingCallback,
|
|
14
|
+
ChannelFilterBindings,
|
|
15
|
+
ChannelOnMessage,
|
|
16
|
+
ChannelOnErrorCallback,
|
|
17
|
+
PresenceState,
|
|
18
|
+
Message,
|
|
19
|
+
Params,
|
|
20
|
+
Transport,
|
|
21
|
+
Timer,
|
|
22
|
+
Vsn,
|
|
23
|
+
Encode,
|
|
24
|
+
Decode,
|
|
25
|
+
HeartbeatCallback,
|
|
26
|
+
HeartbeatStatus,
|
|
27
|
+
} from '@supabase/phoenix'
|
|
28
|
+
|
|
29
|
+
import type { Channel, PresenceState } from '@supabase/phoenix'
|
|
30
|
+
|
|
31
|
+
export type Push = ReturnType<Channel['push']>
|
|
32
|
+
export type PresenceStates = Record<string, PresenceState>
|
package/dist/main/lib/push.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type RealtimeChannel from '../RealtimeChannel';
|
|
2
|
-
export default class Push {
|
|
3
|
-
channel: RealtimeChannel;
|
|
4
|
-
event: string;
|
|
5
|
-
payload: {
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
};
|
|
8
|
-
timeout: number;
|
|
9
|
-
sent: boolean;
|
|
10
|
-
timeoutTimer: number | undefined;
|
|
11
|
-
ref: string;
|
|
12
|
-
receivedResp: {
|
|
13
|
-
status: string;
|
|
14
|
-
response: {
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
};
|
|
17
|
-
} | null;
|
|
18
|
-
recHooks: {
|
|
19
|
-
status: string;
|
|
20
|
-
callback: Function;
|
|
21
|
-
}[];
|
|
22
|
-
refEvent: string | null;
|
|
23
|
-
/**
|
|
24
|
-
* Initializes the Push
|
|
25
|
-
*
|
|
26
|
-
* @param channel The Channel
|
|
27
|
-
* @param event The event, for example `"phx_join"`
|
|
28
|
-
* @param payload The payload, for example `{user_id: 123}`
|
|
29
|
-
* @param timeout The push timeout in milliseconds
|
|
30
|
-
*/
|
|
31
|
-
constructor(channel: RealtimeChannel, event: string, payload?: {
|
|
32
|
-
[key: string]: any;
|
|
33
|
-
}, timeout?: number);
|
|
34
|
-
resend(timeout: number): void;
|
|
35
|
-
send(): void;
|
|
36
|
-
updatePayload(payload: {
|
|
37
|
-
[key: string]: any;
|
|
38
|
-
}): void;
|
|
39
|
-
receive(status: string, callback: Function): this;
|
|
40
|
-
startTimeout(): void;
|
|
41
|
-
trigger(status: string, response: any): void;
|
|
42
|
-
destroy(): void;
|
|
43
|
-
private _cancelRefEvent;
|
|
44
|
-
private _cancelTimeout;
|
|
45
|
-
private _matchReceive;
|
|
46
|
-
private _hasReceived;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=push.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../../src/lib/push.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAA;AAErD,MAAM,CAAC,OAAO,OAAO,IAAI;IAuBd,OAAO,EAAE,eAAe;IACxB,KAAK,EAAE,MAAM;IACb,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE;IAC/B,OAAO,EAAE,MAAM;IAzBxB,IAAI,EAAE,OAAO,CAAQ;IACrB,YAAY,EAAE,MAAM,GAAG,SAAS,CAAY;IAC5C,GAAG,EAAE,MAAM,CAAK;IAChB,YAAY,EAAE;QACZ,MAAM,EAAE,MAAM,CAAA;QACd,QAAQ,EAAE;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAA;KACjC,GAAG,IAAI,CAAO;IACf,QAAQ,EAAE;QACR,MAAM,EAAE,MAAM,CAAA;QACd,QAAQ,EAAE,QAAQ,CAAA;KACnB,EAAE,CAAK;IACR,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAO;IAE9B;;;;;;;OAOG;gBAEM,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAO,EACpC,OAAO,GAAE,MAAwB;IAG1C,MAAM,CAAC,OAAO,EAAE,MAAM;IAUtB,IAAI;IAeJ,aAAa,CAAC,OAAO,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,GAAG,IAAI;IAIpD,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;IAS1C,YAAY;IAqBZ,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG;IAIrC,OAAO;IAKP,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,YAAY;CAGrB"}
|
package/dist/main/lib/push.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const constants_1 = require("../lib/constants");
|
|
4
|
-
class Push {
|
|
5
|
-
/**
|
|
6
|
-
* Initializes the Push
|
|
7
|
-
*
|
|
8
|
-
* @param channel The Channel
|
|
9
|
-
* @param event The event, for example `"phx_join"`
|
|
10
|
-
* @param payload The payload, for example `{user_id: 123}`
|
|
11
|
-
* @param timeout The push timeout in milliseconds
|
|
12
|
-
*/
|
|
13
|
-
constructor(channel, event, payload = {}, timeout = constants_1.DEFAULT_TIMEOUT) {
|
|
14
|
-
this.channel = channel;
|
|
15
|
-
this.event = event;
|
|
16
|
-
this.payload = payload;
|
|
17
|
-
this.timeout = timeout;
|
|
18
|
-
this.sent = false;
|
|
19
|
-
this.timeoutTimer = undefined;
|
|
20
|
-
this.ref = '';
|
|
21
|
-
this.receivedResp = null;
|
|
22
|
-
this.recHooks = [];
|
|
23
|
-
this.refEvent = null;
|
|
24
|
-
}
|
|
25
|
-
resend(timeout) {
|
|
26
|
-
this.timeout = timeout;
|
|
27
|
-
this._cancelRefEvent();
|
|
28
|
-
this.ref = '';
|
|
29
|
-
this.refEvent = null;
|
|
30
|
-
this.receivedResp = null;
|
|
31
|
-
this.sent = false;
|
|
32
|
-
this.send();
|
|
33
|
-
}
|
|
34
|
-
send() {
|
|
35
|
-
if (this._hasReceived('timeout')) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
this.startTimeout();
|
|
39
|
-
this.sent = true;
|
|
40
|
-
this.channel.socket.push({
|
|
41
|
-
topic: this.channel.topic,
|
|
42
|
-
event: this.event,
|
|
43
|
-
payload: this.payload,
|
|
44
|
-
ref: this.ref,
|
|
45
|
-
join_ref: this.channel._joinRef(),
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
updatePayload(payload) {
|
|
49
|
-
this.payload = Object.assign(Object.assign({}, this.payload), payload);
|
|
50
|
-
}
|
|
51
|
-
receive(status, callback) {
|
|
52
|
-
var _a;
|
|
53
|
-
if (this._hasReceived(status)) {
|
|
54
|
-
callback((_a = this.receivedResp) === null || _a === void 0 ? void 0 : _a.response);
|
|
55
|
-
}
|
|
56
|
-
this.recHooks.push({ status, callback });
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
startTimeout() {
|
|
60
|
-
if (this.timeoutTimer) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
this.ref = this.channel.socket._makeRef();
|
|
64
|
-
this.refEvent = this.channel._replyEventName(this.ref);
|
|
65
|
-
const callback = (payload) => {
|
|
66
|
-
this._cancelRefEvent();
|
|
67
|
-
this._cancelTimeout();
|
|
68
|
-
this.receivedResp = payload;
|
|
69
|
-
this._matchReceive(payload);
|
|
70
|
-
};
|
|
71
|
-
this.channel._on(this.refEvent, {}, callback);
|
|
72
|
-
this.timeoutTimer = setTimeout(() => {
|
|
73
|
-
this.trigger('timeout', {});
|
|
74
|
-
}, this.timeout);
|
|
75
|
-
}
|
|
76
|
-
trigger(status, response) {
|
|
77
|
-
if (this.refEvent)
|
|
78
|
-
this.channel._trigger(this.refEvent, { status, response });
|
|
79
|
-
}
|
|
80
|
-
destroy() {
|
|
81
|
-
this._cancelRefEvent();
|
|
82
|
-
this._cancelTimeout();
|
|
83
|
-
}
|
|
84
|
-
_cancelRefEvent() {
|
|
85
|
-
if (!this.refEvent) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
this.channel._off(this.refEvent, {});
|
|
89
|
-
}
|
|
90
|
-
_cancelTimeout() {
|
|
91
|
-
clearTimeout(this.timeoutTimer);
|
|
92
|
-
this.timeoutTimer = undefined;
|
|
93
|
-
}
|
|
94
|
-
_matchReceive({ status, response }) {
|
|
95
|
-
this.recHooks.filter((h) => h.status === status).forEach((h) => h.callback(response));
|
|
96
|
-
}
|
|
97
|
-
_hasReceived(status) {
|
|
98
|
-
return this.receivedResp && this.receivedResp.status === status;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.default = Push;
|
|
102
|
-
//# sourceMappingURL=push.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push.js","sourceRoot":"","sources":["../../../src/lib/push.ts"],"names":[],"mappings":";;AAAA,gDAAkD;AAGlD,MAAqB,IAAI;IAcvB;;;;;;;OAOG;IACH,YACS,OAAwB,EACxB,KAAa,EACb,UAAkC,EAAE,EACpC,UAAkB,2BAAe;QAHjC,YAAO,GAAP,OAAO,CAAiB;QACxB,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAA6B;QACpC,YAAO,GAAP,OAAO,CAA0B;QAzB1C,SAAI,GAAY,KAAK,CAAA;QACrB,iBAAY,GAAuB,SAAS,CAAA;QAC5C,QAAG,GAAW,EAAE,CAAA;QAChB,iBAAY,GAGD,IAAI,CAAA;QACf,aAAQ,GAGF,EAAE,CAAA;QACR,aAAQ,GAAkB,IAAI,CAAA;IAe3B,CAAC;IAEJ,MAAM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CAAC,CAAA;QAC/B,IAAI,CAAC,YAAY,GAAG,SAAS,CAAA;IAC/B,CAAC;IAEO,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAA0C;QAChF,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;IACvF,CAAC;IAEO,YAAY,CAAC,MAAc;QACjC,OAAO,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,KAAK,MAAM,CAAA;IACjE,CAAC;CACF;AArHD,uBAqHC"}
|
package/dist/main/lib/timer.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a timer that accepts a `timerCalc` function to perform calculated timeout retries, such as exponential backoff.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* let reconnectTimer = new Timer(() => this.connect(), function(tries){
|
|
6
|
-
* return [1000, 5000, 10000][tries - 1] || 10000
|
|
7
|
-
* })
|
|
8
|
-
* reconnectTimer.scheduleTimeout() // fires after 1000
|
|
9
|
-
* reconnectTimer.scheduleTimeout() // fires after 5000
|
|
10
|
-
* reconnectTimer.reset()
|
|
11
|
-
* reconnectTimer.scheduleTimeout() // fires after 1000
|
|
12
|
-
*/
|
|
13
|
-
export default class Timer {
|
|
14
|
-
callback: Function;
|
|
15
|
-
timerCalc: Function;
|
|
16
|
-
timer: number | undefined;
|
|
17
|
-
tries: number;
|
|
18
|
-
constructor(callback: Function, timerCalc: Function);
|
|
19
|
-
reset(): void;
|
|
20
|
-
scheduleTimeout(): void;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=timer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../../src/lib/timer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IAKf,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,QAAQ;IAL5B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAY;IACrC,KAAK,EAAE,MAAM,CAAI;gBAGR,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,QAAQ;IAM5B,KAAK;IAOL,eAAe;CAWhB"}
|
package/dist/main/lib/timer.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/**
|
|
4
|
-
* Creates a timer that accepts a `timerCalc` function to perform calculated timeout retries, such as exponential backoff.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* let reconnectTimer = new Timer(() => this.connect(), function(tries){
|
|
8
|
-
* return [1000, 5000, 10000][tries - 1] || 10000
|
|
9
|
-
* })
|
|
10
|
-
* reconnectTimer.scheduleTimeout() // fires after 1000
|
|
11
|
-
* reconnectTimer.scheduleTimeout() // fires after 5000
|
|
12
|
-
* reconnectTimer.reset()
|
|
13
|
-
* reconnectTimer.scheduleTimeout() // fires after 1000
|
|
14
|
-
*/
|
|
15
|
-
class Timer {
|
|
16
|
-
constructor(callback, timerCalc) {
|
|
17
|
-
this.callback = callback;
|
|
18
|
-
this.timerCalc = timerCalc;
|
|
19
|
-
this.timer = undefined;
|
|
20
|
-
this.tries = 0;
|
|
21
|
-
this.callback = callback;
|
|
22
|
-
this.timerCalc = timerCalc;
|
|
23
|
-
}
|
|
24
|
-
reset() {
|
|
25
|
-
this.tries = 0;
|
|
26
|
-
clearTimeout(this.timer);
|
|
27
|
-
this.timer = undefined;
|
|
28
|
-
}
|
|
29
|
-
// Cancels any previous scheduleTimeout and schedules callback
|
|
30
|
-
scheduleTimeout() {
|
|
31
|
-
clearTimeout(this.timer);
|
|
32
|
-
this.timer = setTimeout(() => {
|
|
33
|
-
this.tries = this.tries + 1;
|
|
34
|
-
this.callback();
|
|
35
|
-
}, this.timerCalc(this.tries + 1));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
exports.default = Timer;
|
|
39
|
-
//# sourceMappingURL=timer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../../../src/lib/timer.ts"],"names":[],"mappings":";;AAAA;;;;;;;;;;;GAWG;AACH,MAAqB,KAAK;IAIxB,YACS,QAAkB,EAClB,SAAmB;QADnB,aAAQ,GAAR,QAAQ,CAAU;QAClB,cAAS,GAAT,SAAS,CAAU;QAL5B,UAAK,GAAuB,SAAS,CAAA;QACrC,UAAK,GAAW,CAAC,CAAA;QAMf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;QACd,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACxB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;IACxB,CAAC;IAED,8DAA8D;IAC9D,eAAe;QACb,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAExB,IAAI,CAAC,KAAK,GAAQ,UAAU,CAC1B,GAAG,EAAE;YACH,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;YAC3B,IAAI,CAAC,QAAQ,EAAE,CAAA;QACjB,CAAC,EACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAC/B,CAAA;IACH,CAAC;CACF;AA9BD,wBA8BC"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type RealtimeChannel from '../RealtimeChannel';
|
|
2
|
-
export default class Push {
|
|
3
|
-
channel: RealtimeChannel;
|
|
4
|
-
event: string;
|
|
5
|
-
payload: {
|
|
6
|
-
[key: string]: any;
|
|
7
|
-
};
|
|
8
|
-
timeout: number;
|
|
9
|
-
sent: boolean;
|
|
10
|
-
timeoutTimer: number | undefined;
|
|
11
|
-
ref: string;
|
|
12
|
-
receivedResp: {
|
|
13
|
-
status: string;
|
|
14
|
-
response: {
|
|
15
|
-
[key: string]: any;
|
|
16
|
-
};
|
|
17
|
-
} | null;
|
|
18
|
-
recHooks: {
|
|
19
|
-
status: string;
|
|
20
|
-
callback: Function;
|
|
21
|
-
}[];
|
|
22
|
-
refEvent: string | null;
|
|
23
|
-
/**
|
|
24
|
-
* Initializes the Push
|
|
25
|
-
*
|
|
26
|
-
* @param channel The Channel
|
|
27
|
-
* @param event The event, for example `"phx_join"`
|
|
28
|
-
* @param payload The payload, for example `{user_id: 123}`
|
|
29
|
-
* @param timeout The push timeout in milliseconds
|
|
30
|
-
*/
|
|
31
|
-
constructor(channel: RealtimeChannel, event: string, payload?: {
|
|
32
|
-
[key: string]: any;
|
|
33
|
-
}, timeout?: number);
|
|
34
|
-
resend(timeout: number): void;
|
|
35
|
-
send(): void;
|
|
36
|
-
updatePayload(payload: {
|
|
37
|
-
[key: string]: any;
|
|
38
|
-
}): void;
|
|
39
|
-
receive(status: string, callback: Function): this;
|
|
40
|
-
startTimeout(): void;
|
|
41
|
-
trigger(status: string, response: any): void;
|
|
42
|
-
destroy(): void;
|
|
43
|
-
private _cancelRefEvent;
|
|
44
|
-
private _cancelTimeout;
|
|
45
|
-
private _matchReceive;
|
|
46
|
-
private _hasReceived;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=push.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../../src/lib/push.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,eAAe,MAAM,oBAAoB,CAAA;AAErD,MAAM,CAAC,OAAO,OAAO,IAAI;IAuBd,OAAO,EAAE,eAAe;IACx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* Initializes the Push
|
|
5
|
-
*
|
|
6
|
-
* @param channel The Channel
|
|
7
|
-
* @param event The event, for example `"phx_join"`
|
|
8
|
-
* @param payload The payload, for example `{user_id: 123}`
|
|
9
|
-
* @param timeout The push timeout in milliseconds
|
|
10
|
-
*/
|
|
11
|
-
constructor(channel, event, payload = {}, timeout = DEFAULT_TIMEOUT) {
|
|
12
|
-
this.channel = channel;
|
|
13
|
-
this.event = event;
|
|
14
|
-
this.payload = payload;
|
|
15
|
-
this.timeout = timeout;
|
|
16
|
-
this.sent = false;
|
|
17
|
-
this.timeoutTimer = undefined;
|
|
18
|
-
this.ref = '';
|
|
19
|
-
this.receivedResp = null;
|
|
20
|
-
this.recHooks = [];
|
|
21
|
-
this.refEvent = null;
|
|
22
|
-
}
|
|
23
|
-
resend(timeout) {
|
|
24
|
-
this.timeout = timeout;
|
|
25
|
-
this._cancelRefEvent();
|
|
26
|
-
this.ref = '';
|
|
27
|
-
this.refEvent = null;
|
|
28
|
-
this.receivedResp = null;
|
|
29
|
-
this.sent = false;
|
|
30
|
-
this.send();
|
|
31
|
-
}
|
|
32
|
-
send() {
|
|
33
|
-
if (this._hasReceived('timeout')) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
this.startTimeout();
|
|
37
|
-
this.sent = true;
|
|
38
|
-
this.channel.socket.push({
|
|
39
|
-
topic: this.channel.topic,
|
|
40
|
-
event: this.event,
|
|
41
|
-
payload: this.payload,
|
|
42
|
-
ref: this.ref,
|
|
43
|
-
join_ref: this.channel._joinRef(),
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
updatePayload(payload) {
|
|
47
|
-
this.payload = Object.assign(Object.assign({}, this.payload), payload);
|
|
48
|
-
}
|
|
49
|
-
receive(status, callback) {
|
|
50
|
-
var _a;
|
|
51
|
-
if (this._hasReceived(status)) {
|
|
52
|
-
callback((_a = this.receivedResp) === null || _a === void 0 ? void 0 : _a.response);
|
|
53
|
-
}
|
|
54
|
-
this.recHooks.push({ status, callback });
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
startTimeout() {
|
|
58
|
-
if (this.timeoutTimer) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
this.ref = this.channel.socket._makeRef();
|
|
62
|
-
this.refEvent = this.channel._replyEventName(this.ref);
|
|
63
|
-
const callback = (payload) => {
|
|
64
|
-
this._cancelRefEvent();
|
|
65
|
-
this._cancelTimeout();
|
|
66
|
-
this.receivedResp = payload;
|
|
67
|
-
this._matchReceive(payload);
|
|
68
|
-
};
|
|
69
|
-
this.channel._on(this.refEvent, {}, callback);
|
|
70
|
-
this.timeoutTimer = setTimeout(() => {
|
|
71
|
-
this.trigger('timeout', {});
|
|
72
|
-
}, this.timeout);
|
|
73
|
-
}
|
|
74
|
-
trigger(status, response) {
|
|
75
|
-
if (this.refEvent)
|
|
76
|
-
this.channel._trigger(this.refEvent, { status, response });
|
|
77
|
-
}
|
|
78
|
-
destroy() {
|
|
79
|
-
this._cancelRefEvent();
|
|
80
|
-
this._cancelTimeout();
|
|
81
|
-
}
|
|
82
|
-
_cancelRefEvent() {
|
|
83
|
-
if (!this.refEvent) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
this.channel._off(this.refEvent, {});
|
|
87
|
-
}
|
|
88
|
-
_cancelTimeout() {
|
|
89
|
-
clearTimeout(this.timeoutTimer);
|
|
90
|
-
this.timeoutTimer = undefined;
|
|
91
|
-
}
|
|
92
|
-
_matchReceive({ status, response }) {
|
|
93
|
-
this.recHooks.filter((h) => h.status === status).forEach((h) => h.callback(response));
|
|
94
|
-
}
|
|
95
|
-
_hasReceived(status) {
|
|
96
|
-
return this.receivedResp && this.receivedResp.status === status;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
//# sourceMappingURL=push.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"push.js","sourceRoot":"","sources":["../../../src/lib/push.ts"],"names":[],"mappings":"AAAA,OAAO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CAAC,MAAc,EAAE,QAAa;QACnC,IAAI,IAAI,CAAC,QAAQ;YAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC/E,CAAC;IAED,OAAO;QACL,IAAI,CAAC,eAAe,EAAE,CAAA;QACtB,IAAI,CAAC,cAAc,EAAE,CAAA;IACvB,CAAC;IAEO,eAAe;QACrB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAM;QACR,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IACtC,CAAC;IAEO,cAAc;QACpB,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAC/B,IAAI,CAAC,YAAY,GAAG,SAAS,CAAA;IAC/B,CAAC;IAEO,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAA0C;QAChF,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;IACvF,CAAC;IAEO,YAAY,CAAC,MAAc;QACjC,OAAO,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,KAAK,MAAM,CAAA;IACjE,CAAC;CACF"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a timer that accepts a `timerCalc` function to perform calculated timeout retries, such as exponential backoff.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* let reconnectTimer = new Timer(() => this.connect(), function(tries){
|
|
6
|
-
* return [1000, 5000, 10000][tries - 1] || 10000
|
|
7
|
-
* })
|
|
8
|
-
* reconnectTimer.scheduleTimeout() // fires after 1000
|
|
9
|
-
* reconnectTimer.scheduleTimeout() // fires after 5000
|
|
10
|
-
* reconnectTimer.reset()
|
|
11
|
-
* reconnectTimer.scheduleTimeout() // fires after 1000
|
|
12
|
-
*/
|
|
13
|
-
export default class Timer {
|
|
14
|
-
callback: Function;
|
|
15
|
-
timerCalc: Function;
|
|
16
|
-
timer: number | undefined;
|
|
17
|
-
tries: number;
|
|
18
|
-
constructor(callback: Function, timerCalc: Function);
|
|
19
|
-
reset(): void;
|
|
20
|
-
scheduleTimeout(): void;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=timer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../../src/lib/timer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IAKf,QAAQ,EAAE,QAAQ;IAClB,SAAS,EAAE,QAAQ;IAL5B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAY;IACrC,KAAK,EAAE,MAAM,CAAI;gBAGR,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,QAAQ;IAM5B,KAAK;IAOL,eAAe;CAWhB"}
|
package/dist/module/lib/timer.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a timer that accepts a `timerCalc` function to perform calculated timeout retries, such as exponential backoff.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* let reconnectTimer = new Timer(() => this.connect(), function(tries){
|
|
6
|
-
* return [1000, 5000, 10000][tries - 1] || 10000
|
|
7
|
-
* })
|
|
8
|
-
* reconnectTimer.scheduleTimeout() // fires after 1000
|
|
9
|
-
* reconnectTimer.scheduleTimeout() // fires after 5000
|
|
10
|
-
* reconnectTimer.reset()
|
|
11
|
-
* reconnectTimer.scheduleTimeout() // fires after 1000
|
|
12
|
-
*/
|
|
13
|
-
export default class Timer {
|
|
14
|
-
constructor(callback, timerCalc) {
|
|
15
|
-
this.callback = callback;
|
|
16
|
-
this.timerCalc = timerCalc;
|
|
17
|
-
this.timer = undefined;
|
|
18
|
-
this.tries = 0;
|
|
19
|
-
this.callback = callback;
|
|
20
|
-
this.timerCalc = timerCalc;
|
|
21
|
-
}
|
|
22
|
-
reset() {
|
|
23
|
-
this.tries = 0;
|
|
24
|
-
clearTimeout(this.timer);
|
|
25
|
-
this.timer = undefined;
|
|
26
|
-
}
|
|
27
|
-
// Cancels any previous scheduleTimeout and schedules callback
|
|
28
|
-
scheduleTimeout() {
|
|
29
|
-
clearTimeout(this.timer);
|
|
30
|
-
this.timer = setTimeout(() => {
|
|
31
|
-
this.tries = this.tries + 1;
|
|
32
|
-
this.callback();
|
|
33
|
-
}, this.timerCalc(this.tries + 1));
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=timer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timer.js","sourceRoot":"","sources":["../../../src/lib/timer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,KAAK;IAIxB,YACS,QAAkB,EAClB,SAAmB;QADnB,aAAQ,GAAR,QAAQ,CAAU;QAClB,cAAS,GAAT,SAAS,CAAU;QAL5B,UAAK,GAAuB,SAAS,CAAA;QACrC,UAAK,GAAW,CAAC,CAAA;QAMf,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;QACd,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACxB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;IACxB,CAAC;IAED,8DAA8D;IAC9D,eAAe;QACb,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAExB,IAAI,CAAC,KAAK,GAAQ,UAAU,CAC1B,GAAG,EAAE;YACH,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;YAC3B,IAAI,CAAC,QAAQ,EAAE,CAAA;QACjB,CAAC,EACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAC/B,CAAA;IACH,CAAC;CACF"}
|