@supabase/phoenix 0.1.0
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/LICENSE.md +22 -0
- package/README.md +122 -0
- package/assets/js/phoenix/ajax.js +116 -0
- package/assets/js/phoenix/channel.js +331 -0
- package/assets/js/phoenix/constants.js +35 -0
- package/assets/js/phoenix/index.js +212 -0
- package/assets/js/phoenix/longpoll.js +192 -0
- package/assets/js/phoenix/presence.js +208 -0
- package/assets/js/phoenix/push.js +134 -0
- package/assets/js/phoenix/serializer.js +133 -0
- package/assets/js/phoenix/socket.js +747 -0
- package/assets/js/phoenix/timer.js +48 -0
- package/assets/js/phoenix/types.js +184 -0
- package/assets/js/phoenix/utils.js +16 -0
- package/package.json +58 -0
- package/priv/static/favicon.ico +0 -0
- package/priv/static/phoenix-orange.png +0 -0
- package/priv/static/phoenix.cjs.js +1812 -0
- package/priv/static/phoenix.cjs.js.map +7 -0
- package/priv/static/phoenix.js +1834 -0
- package/priv/static/phoenix.min.js +2 -0
- package/priv/static/phoenix.mjs +1789 -0
- package/priv/static/phoenix.mjs.map +7 -0
- package/priv/static/phoenix.png +0 -0
- package/priv/static/types/ajax.d.ts +10 -0
- package/priv/static/types/ajax.d.ts.map +1 -0
- package/priv/static/types/channel.d.ts +167 -0
- package/priv/static/types/channel.d.ts.map +1 -0
- package/priv/static/types/constants.d.ts +36 -0
- package/priv/static/types/constants.d.ts.map +1 -0
- package/priv/static/types/index.d.ts +10 -0
- package/priv/static/types/index.d.ts.map +1 -0
- package/priv/static/types/longpoll.d.ts +29 -0
- package/priv/static/types/longpoll.d.ts.map +1 -0
- package/priv/static/types/presence.d.ts +107 -0
- package/priv/static/types/presence.d.ts.map +1 -0
- package/priv/static/types/push.d.ts +70 -0
- package/priv/static/types/push.d.ts.map +1 -0
- package/priv/static/types/serializer.d.ts +74 -0
- package/priv/static/types/serializer.d.ts.map +1 -0
- package/priv/static/types/socket.d.ts +284 -0
- package/priv/static/types/socket.d.ts.map +1 -0
- package/priv/static/types/timer.d.ts +36 -0
- package/priv/static/types/timer.d.ts.map +1 -0
- package/priv/static/types/types.d.ts +280 -0
- package/priv/static/types/types.d.ts.map +1 -0
- package/priv/static/types/utils.d.ts +2 -0
- package/priv/static/types/utils.d.ts.map +1 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import Channel from "./channel"
|
|
3
|
+
* @import { ChannelEvent } from "./types"
|
|
4
|
+
*/
|
|
5
|
+
export default class Push {
|
|
6
|
+
/**
|
|
7
|
+
* Initializes the Push
|
|
8
|
+
* @param {Channel} channel - The Channel
|
|
9
|
+
* @param {ChannelEvent} event - The event, for example `"phx_join"`
|
|
10
|
+
* @param {() => Record<string, unknown>} payload - The payload, for example `{user_id: 123}`
|
|
11
|
+
* @param {number} timeout - The push timeout in milliseconds
|
|
12
|
+
*/
|
|
13
|
+
constructor(channel: Channel, event: ChannelEvent, payload: () => Record<string, unknown>, timeout: number);
|
|
14
|
+
/** @type{Channel} */
|
|
15
|
+
channel: Channel;
|
|
16
|
+
/** @type{ChannelEvent} */
|
|
17
|
+
event: ChannelEvent;
|
|
18
|
+
/** @type{() => Record<string, unknown>} */
|
|
19
|
+
payload: () => Record<string, unknown>;
|
|
20
|
+
receivedResp: unknown;
|
|
21
|
+
/** @type{number} */
|
|
22
|
+
timeout: number;
|
|
23
|
+
/** @type{(ReturnType<typeof setTimeout>) | null} */
|
|
24
|
+
timeoutTimer: (ReturnType<typeof setTimeout>) | null;
|
|
25
|
+
/** @type{{status: string; callback: (response: any) => void}[]} */
|
|
26
|
+
recHooks: {
|
|
27
|
+
status: string;
|
|
28
|
+
callback: (response: any) => void;
|
|
29
|
+
}[];
|
|
30
|
+
/** @type{boolean} */
|
|
31
|
+
sent: boolean;
|
|
32
|
+
/** @type{string | null | undefined} */
|
|
33
|
+
ref: string | null | undefined;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param {number} timeout
|
|
37
|
+
*/
|
|
38
|
+
resend(timeout: number): void;
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
send(): void;
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param {string} status
|
|
46
|
+
* @param {(response: any) => void} callback
|
|
47
|
+
*/
|
|
48
|
+
receive(status: string, callback: (response: any) => void): this;
|
|
49
|
+
reset(): void;
|
|
50
|
+
refEvent: string | null | undefined;
|
|
51
|
+
destroy(): void;
|
|
52
|
+
/**
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
private matchReceive;
|
|
56
|
+
/**
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
private cancelRefEvent;
|
|
60
|
+
cancelTimeout(): void;
|
|
61
|
+
startTimeout(): void;
|
|
62
|
+
/**
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
private hasReceived;
|
|
66
|
+
trigger(status: any, response: any): void;
|
|
67
|
+
}
|
|
68
|
+
import type Channel from "./channel";
|
|
69
|
+
import type { ChannelEvent } from "./types";
|
|
70
|
+
//# sourceMappingURL=push.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push.d.ts","sourceRoot":"","sources":["../../../assets/js/phoenix/push.js"],"names":[],"mappings":"AAAA;;;GAGG;AACH;IACE;;;;;;OAMG;IACH,qBALW,OAAO,SACP,YAAY,WACZ,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAC7B,MAAM,EAoBhB;IAjBC,qBAAqB;IACrB,SADU,OAAO,CACK;IACtB,0BAA0B;IAC1B,OADU,YAAY,CACJ;IAClB,2CAA2C;IAC3C,SADU,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACW;IAClD,sBAAwB;IACxB,oBAAoB;IACpB,SADU,MAAM,CACM;IACtB,oDAAoD;IACpD,cADU,CAAC,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC,GAAG,IAAI,CACxB;IACxB,mEAAmE;IACnE,UADU;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,CAAA;KAAC,EAAE,CAC7C;IAClB,qBAAqB;IACrB,MADU,OAAO,CACA;IACjB,uCAAuC;IACvC,KADU,MAAM,GAAG,IAAI,GAAG,SAAS,CACf;IAGtB;;;OAGG;IACH,gBAFW,MAAM,QAMhB;IAED;;OAEG;IACH,aAWC;IAED;;;;OAIG;IACH,gBAHW,MAAM,YACN,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI,QASjC;IAED,cAMC;IAHC,oCAAoB;IAKtB,gBAGC;IAED;;OAEG;IACH,qBAGC;IAED;;OAEG;IACH,uBAGC;IAED,sBAGC;IAED,qBAeC;IAED;;OAEG;IACH,oBAEC;IAED,0CAEC;CACF;yBApIuB,WAAW;kCACF,SAAS"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
let HEADER_LENGTH: number;
|
|
3
|
+
let META_LENGTH: number;
|
|
4
|
+
namespace KINDS {
|
|
5
|
+
let push: number;
|
|
6
|
+
let reply: number;
|
|
7
|
+
let broadcast: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @template T
|
|
11
|
+
* @param {Message<Record<string, any>>} msg
|
|
12
|
+
* @param {(msg: ArrayBuffer | string) => T} callback
|
|
13
|
+
* @returns {T}
|
|
14
|
+
*/
|
|
15
|
+
function encode<T>(msg: Message<Record<string, any>>, callback: (msg: ArrayBuffer | string) => T): T;
|
|
16
|
+
/**
|
|
17
|
+
* @template T
|
|
18
|
+
* @param {ArrayBuffer | string} rawPayload
|
|
19
|
+
* @param {(msg: Message<unknown>) => T} callback
|
|
20
|
+
* @returns {T}
|
|
21
|
+
*/
|
|
22
|
+
function decode<T>(rawPayload: ArrayBuffer | string, callback: (msg: Message<unknown>) => T): T;
|
|
23
|
+
/** @private */
|
|
24
|
+
function binaryEncode(message: any): any;
|
|
25
|
+
/**
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
function binaryDecode(buffer: any): {
|
|
29
|
+
join_ref: any;
|
|
30
|
+
ref: null;
|
|
31
|
+
topic: any;
|
|
32
|
+
event: any;
|
|
33
|
+
payload: any;
|
|
34
|
+
} | {
|
|
35
|
+
join_ref: any;
|
|
36
|
+
ref: any;
|
|
37
|
+
topic: any;
|
|
38
|
+
event: "phx_reply";
|
|
39
|
+
payload: {
|
|
40
|
+
status: any;
|
|
41
|
+
response: any;
|
|
42
|
+
};
|
|
43
|
+
} | undefined;
|
|
44
|
+
/** @private */
|
|
45
|
+
function decodePush(buffer: any, view: any, decoder: any): {
|
|
46
|
+
join_ref: any;
|
|
47
|
+
ref: null;
|
|
48
|
+
topic: any;
|
|
49
|
+
event: any;
|
|
50
|
+
payload: any;
|
|
51
|
+
};
|
|
52
|
+
/** @private */
|
|
53
|
+
function decodeReply(buffer: any, view: any, decoder: any): {
|
|
54
|
+
join_ref: any;
|
|
55
|
+
ref: any;
|
|
56
|
+
topic: any;
|
|
57
|
+
event: "phx_reply";
|
|
58
|
+
payload: {
|
|
59
|
+
status: any;
|
|
60
|
+
response: any;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
/** @private */
|
|
64
|
+
function decodeBroadcast(buffer: any, view: any, decoder: any): {
|
|
65
|
+
join_ref: null;
|
|
66
|
+
ref: null;
|
|
67
|
+
topic: any;
|
|
68
|
+
event: any;
|
|
69
|
+
payload: any;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export default _default;
|
|
73
|
+
import type { Message } from "./types";
|
|
74
|
+
//# sourceMappingURL=serializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../../../assets/js/phoenix/serializer.js"],"names":[],"mappings":";;;;;;;;IAcE;;;;;MAKE;IACF,gBALY,CAAC,OACH,QAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,YAC5B,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,KAAK,CAAC,GAC9B,CAAC,CASZ;IAED;;;;;MAKE;IACF,gBALY,CAAC,cACH,WAAW,GAAG,MAAM,YACpB,CAAC,GAAG,EAAE,QAAQ,OAAO,CAAC,KAAK,CAAC,GAC1B,CAAC,CASZ;IAED,eAAe;IACf,yCAsBC;IAED;;MAEE;IACF;;;;;;;;;;;;;;;kBASC;IAED,eAAe;IACf;;;;;;MAaC;IAED,eAAe;IACf;;;;;;;;;MAiBC;IAED,eAAe;IACf;;;;;;MAWC;;;6BA7HyB,SAAS"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { Encode, Decode, Message, Vsn, SocketTransport, Params, SocketOnOpen, SocketOnClose, SocketOnError, SocketOnMessage, SocketOptions, SocketStateChangeCallbacks, HeartbeatCallback } from "./types"
|
|
3
|
+
*/
|
|
4
|
+
export default class Socket {
|
|
5
|
+
/** Initializes the Socket *
|
|
6
|
+
*
|
|
7
|
+
* For IE8 support use an ES5-shim (https://github.com/es-shims/es5-shim)
|
|
8
|
+
*
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param {string} endPoint - The string WebSocket endpoint, ie, `"ws://example.com/socket"`,
|
|
11
|
+
* `"wss://example.com"`
|
|
12
|
+
* `"/socket"` (inherited host & protocol)
|
|
13
|
+
* @param {SocketOptions} [opts] - Optional configuration
|
|
14
|
+
*/
|
|
15
|
+
constructor(endPoint: string, opts?: SocketOptions);
|
|
16
|
+
/** @type{SocketStateChangeCallbacks} */
|
|
17
|
+
stateChangeCallbacks: SocketStateChangeCallbacks;
|
|
18
|
+
/** @type{Channel[]} */
|
|
19
|
+
channels: Channel[];
|
|
20
|
+
/** @type{(() => void)[]} */
|
|
21
|
+
sendBuffer: (() => void)[];
|
|
22
|
+
/** @type{number} */
|
|
23
|
+
ref: number;
|
|
24
|
+
/** @type{?string} */
|
|
25
|
+
fallbackRef: string | null;
|
|
26
|
+
/** @type{number} */
|
|
27
|
+
timeout: number;
|
|
28
|
+
/** @type{SocketTransport} */
|
|
29
|
+
transport: SocketTransport;
|
|
30
|
+
/** @type{InstanceType<SocketTransport> | undefined | null} */
|
|
31
|
+
conn: InstanceType<SocketTransport> | undefined | null;
|
|
32
|
+
/** @type{boolean} */
|
|
33
|
+
primaryPassedHealthCheck: boolean;
|
|
34
|
+
/** @type{number | undefined} */
|
|
35
|
+
longPollFallbackMs: number | undefined;
|
|
36
|
+
/** @type{ReturnType<typeof setTimeout>} */
|
|
37
|
+
fallbackTimer: ReturnType<typeof setTimeout>;
|
|
38
|
+
/** @type{Storage} */
|
|
39
|
+
sessionStore: Storage;
|
|
40
|
+
/** @type{number} */
|
|
41
|
+
establishedConnections: number;
|
|
42
|
+
/** @type{Encode<void>} */
|
|
43
|
+
defaultEncoder: Encode<void>;
|
|
44
|
+
/** @type{Decode<void>} */
|
|
45
|
+
defaultDecoder: Decode<void>;
|
|
46
|
+
/** @type{boolean} */
|
|
47
|
+
closeWasClean: boolean;
|
|
48
|
+
/** @type{boolean} */
|
|
49
|
+
disconnecting: boolean;
|
|
50
|
+
/** @type{BinaryType} */
|
|
51
|
+
binaryType: BinaryType;
|
|
52
|
+
/** @type{number} */
|
|
53
|
+
connectClock: number;
|
|
54
|
+
/** @type{boolean} */
|
|
55
|
+
pageHidden: boolean;
|
|
56
|
+
/** @type{Encode<void>} */
|
|
57
|
+
encode: Encode<void>;
|
|
58
|
+
/** @type{Decode<void>} */
|
|
59
|
+
decode: Decode<void>;
|
|
60
|
+
/** @type{number} */
|
|
61
|
+
heartbeatIntervalMs: number;
|
|
62
|
+
/** @type{boolean} */
|
|
63
|
+
autoSendHeartbeat: boolean;
|
|
64
|
+
/** @type{HeartbeatCallback} */
|
|
65
|
+
heartbeatCallback: HeartbeatCallback;
|
|
66
|
+
/** @type{(tries: number) => number} */
|
|
67
|
+
rejoinAfterMs: (tries: number) => number;
|
|
68
|
+
/** @type{(tries: number) => number} */
|
|
69
|
+
reconnectAfterMs: (tries: number) => number;
|
|
70
|
+
/** @type{((kind: string, msg: string, data: any) => void) | null} */
|
|
71
|
+
logger: ((kind: string, msg: string, data: any) => void) | null;
|
|
72
|
+
/** @type{number} */
|
|
73
|
+
longpollerTimeout: number;
|
|
74
|
+
/** @type{() => Params} */
|
|
75
|
+
params: () => Params;
|
|
76
|
+
/** @type{string} */
|
|
77
|
+
endPoint: string;
|
|
78
|
+
/** @type{Vsn} */
|
|
79
|
+
vsn: Vsn;
|
|
80
|
+
/** @type{ReturnType<typeof setTimeout>} */
|
|
81
|
+
heartbeatTimeoutTimer: ReturnType<typeof setTimeout>;
|
|
82
|
+
/** @type{ReturnType<typeof setTimeout>} */
|
|
83
|
+
heartbeatTimer: ReturnType<typeof setTimeout>;
|
|
84
|
+
/** @type{number | null} */
|
|
85
|
+
heartbeatSentAt: number | null;
|
|
86
|
+
/** @type{?string} */
|
|
87
|
+
pendingHeartbeatRef: string | null;
|
|
88
|
+
/** @type{Timer} */
|
|
89
|
+
reconnectTimer: Timer;
|
|
90
|
+
/** @type{string | undefined} */
|
|
91
|
+
authToken: string | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Returns the LongPoll transport reference
|
|
94
|
+
*/
|
|
95
|
+
getLongPollTransport(): typeof LongPoll;
|
|
96
|
+
/**
|
|
97
|
+
* Disconnects and replaces the active transport
|
|
98
|
+
*
|
|
99
|
+
* @param {SocketTransport} newTransport - The new transport class to instantiate
|
|
100
|
+
*
|
|
101
|
+
*/
|
|
102
|
+
replaceTransport(newTransport: SocketTransport): void;
|
|
103
|
+
/**
|
|
104
|
+
* Returns the socket protocol
|
|
105
|
+
*
|
|
106
|
+
* @returns {"wss" | "ws"}
|
|
107
|
+
*/
|
|
108
|
+
protocol(): "wss" | "ws";
|
|
109
|
+
/**
|
|
110
|
+
* The fully qualified socket url
|
|
111
|
+
*
|
|
112
|
+
* @returns {string}
|
|
113
|
+
*/
|
|
114
|
+
endPointURL(): string;
|
|
115
|
+
/**
|
|
116
|
+
* Disconnects the socket
|
|
117
|
+
*
|
|
118
|
+
* See https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes for valid status codes.
|
|
119
|
+
*
|
|
120
|
+
* @param {() => void} [callback] - Optional callback which is called after socket is disconnected.
|
|
121
|
+
* @param {number} [code] - A status code for disconnection (Optional).
|
|
122
|
+
* @param {string} [reason] - A textual description of the reason to disconnect. (Optional)
|
|
123
|
+
*/
|
|
124
|
+
disconnect(callback?: () => void, code?: number, reason?: string): void;
|
|
125
|
+
/**
|
|
126
|
+
* @param {Params} [params] - [DEPRECATED] The params to send when connecting, for example `{user_id: userToken}`
|
|
127
|
+
*
|
|
128
|
+
* Passing params to connect is deprecated; pass them in the Socket constructor instead:
|
|
129
|
+
* `new Socket("/socket", {params: {user_id: userToken}})`.
|
|
130
|
+
*/
|
|
131
|
+
connect(params?: Params): void;
|
|
132
|
+
/**
|
|
133
|
+
* Logs the message. Override `this.logger` for specialized logging. noops by default
|
|
134
|
+
* @param {string} kind
|
|
135
|
+
* @param {string} msg
|
|
136
|
+
* @param {Object} data
|
|
137
|
+
*/
|
|
138
|
+
log(kind: string, msg: string, data: Object): void;
|
|
139
|
+
/**
|
|
140
|
+
* Returns true if a logger has been set on this socket.
|
|
141
|
+
*/
|
|
142
|
+
hasLogger(): boolean;
|
|
143
|
+
/**
|
|
144
|
+
* Registers callbacks for connection open events
|
|
145
|
+
*
|
|
146
|
+
* @example socket.onOpen(function(){ console.info("the socket was opened") })
|
|
147
|
+
*
|
|
148
|
+
* @param {SocketOnOpen} callback
|
|
149
|
+
*/
|
|
150
|
+
onOpen(callback: SocketOnOpen): string;
|
|
151
|
+
/**
|
|
152
|
+
* Registers callbacks for connection close events
|
|
153
|
+
* @param {SocketOnClose} callback
|
|
154
|
+
* @returns {string}
|
|
155
|
+
*/
|
|
156
|
+
onClose(callback: SocketOnClose): string;
|
|
157
|
+
/**
|
|
158
|
+
* Registers callbacks for connection error events
|
|
159
|
+
*
|
|
160
|
+
* @example socket.onError(function(error){ alert("An error occurred") })
|
|
161
|
+
*
|
|
162
|
+
* @param {SocketOnError} callback
|
|
163
|
+
* @returns {string}
|
|
164
|
+
*/
|
|
165
|
+
onError(callback: SocketOnError): string;
|
|
166
|
+
/**
|
|
167
|
+
* Registers callbacks for connection message events
|
|
168
|
+
* @param {SocketOnMessage} callback
|
|
169
|
+
* @returns {string}
|
|
170
|
+
*/
|
|
171
|
+
onMessage(callback: SocketOnMessage): string;
|
|
172
|
+
/**
|
|
173
|
+
* Sets a callback that receives lifecycle events for internal heartbeat messages.
|
|
174
|
+
* Useful for instrumenting connection health (e.g. sent/ok/timeout/disconnected).
|
|
175
|
+
* @param {HeartbeatCallback} callback
|
|
176
|
+
*/
|
|
177
|
+
onHeartbeat(callback: HeartbeatCallback): void;
|
|
178
|
+
/**
|
|
179
|
+
* Pings the server and invokes the callback with the RTT in milliseconds
|
|
180
|
+
* @param {(timeDelta: number) => void} callback
|
|
181
|
+
*
|
|
182
|
+
* Returns true if the ping was pushed or false if unable to be pushed.
|
|
183
|
+
*/
|
|
184
|
+
ping(callback: (timeDelta: number) => void): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* @private
|
|
187
|
+
*/
|
|
188
|
+
private transportConnect;
|
|
189
|
+
getSession(key: any): string | null;
|
|
190
|
+
storeSession(key: any, val: any): void;
|
|
191
|
+
connectWithFallback(fallbackTransport: any, fallbackThreshold?: number): void;
|
|
192
|
+
clearHeartbeats(): void;
|
|
193
|
+
onConnOpen(): void;
|
|
194
|
+
/**
|
|
195
|
+
* @private
|
|
196
|
+
*/
|
|
197
|
+
private heartbeatTimeout;
|
|
198
|
+
resetHeartbeat(): void;
|
|
199
|
+
teardown(callback: any, code: any, reason: any): any;
|
|
200
|
+
waitForBufferDone(callback: any, tries?: number): void;
|
|
201
|
+
waitForSocketClosed(callback: any, tries?: number): void;
|
|
202
|
+
/**
|
|
203
|
+
* @param {CloseEvent} event
|
|
204
|
+
*/
|
|
205
|
+
onConnClose(event: CloseEvent): void;
|
|
206
|
+
/**
|
|
207
|
+
* @private
|
|
208
|
+
* @param {Event} error
|
|
209
|
+
*/
|
|
210
|
+
private onConnError;
|
|
211
|
+
/**
|
|
212
|
+
* @private
|
|
213
|
+
*/
|
|
214
|
+
private triggerChanError;
|
|
215
|
+
/**
|
|
216
|
+
* @returns {string}
|
|
217
|
+
*/
|
|
218
|
+
connectionState(): string;
|
|
219
|
+
/**
|
|
220
|
+
* @returns {boolean}
|
|
221
|
+
*/
|
|
222
|
+
isConnected(): boolean;
|
|
223
|
+
/**
|
|
224
|
+
*
|
|
225
|
+
* @param {Channel} channel
|
|
226
|
+
*/
|
|
227
|
+
remove(channel: Channel): void;
|
|
228
|
+
/**
|
|
229
|
+
* Removes `onOpen`, `onClose`, `onError,` and `onMessage` registrations.
|
|
230
|
+
*
|
|
231
|
+
* @param {string[]} refs - list of refs returned by calls to
|
|
232
|
+
* `onOpen`, `onClose`, `onError,` and `onMessage`
|
|
233
|
+
*/
|
|
234
|
+
off(refs: string[]): void;
|
|
235
|
+
/**
|
|
236
|
+
* Initiates a new channel for the given topic
|
|
237
|
+
*
|
|
238
|
+
* @param {string} topic
|
|
239
|
+
* @param {Params | (() => Params)} [chanParams]- Parameters for the channel
|
|
240
|
+
* @returns {Channel}
|
|
241
|
+
*/
|
|
242
|
+
channel(topic: string, chanParams?: Params | (() => Params)): Channel;
|
|
243
|
+
/**
|
|
244
|
+
* @param {Message<Record<string, any>>} data
|
|
245
|
+
*/
|
|
246
|
+
push(data: Message<Record<string, any>>): void;
|
|
247
|
+
/**
|
|
248
|
+
* Return the next message ref, accounting for overflows
|
|
249
|
+
* @returns {string}
|
|
250
|
+
*/
|
|
251
|
+
makeRef(): string;
|
|
252
|
+
sendHeartbeat(): void;
|
|
253
|
+
flushSendBuffer(): void;
|
|
254
|
+
/**
|
|
255
|
+
* @param {MessageEvent<any>} rawMessage
|
|
256
|
+
*/
|
|
257
|
+
onConnMessage(rawMessage: MessageEvent<any>): void;
|
|
258
|
+
/**
|
|
259
|
+
* @private
|
|
260
|
+
* @template {keyof SocketStateChangeCallbacks} K
|
|
261
|
+
* @param {K} event
|
|
262
|
+
* @param {...Parameters<SocketStateChangeCallbacks[K][number][1]>} args
|
|
263
|
+
* @returns {void}
|
|
264
|
+
*/
|
|
265
|
+
private triggerStateCallbacks;
|
|
266
|
+
leaveOpenTopic(topic: any): void;
|
|
267
|
+
}
|
|
268
|
+
import type { SocketStateChangeCallbacks } from "./types";
|
|
269
|
+
import Channel from "./channel";
|
|
270
|
+
import type { SocketTransport } from "./types";
|
|
271
|
+
import type { Encode } from "./types";
|
|
272
|
+
import type { Decode } from "./types";
|
|
273
|
+
import type { HeartbeatCallback } from "./types";
|
|
274
|
+
import type { Params } from "./types";
|
|
275
|
+
import type { Vsn } from "./types";
|
|
276
|
+
import Timer from "./timer";
|
|
277
|
+
import LongPoll from "./longpoll";
|
|
278
|
+
import type { SocketOnOpen } from "./types";
|
|
279
|
+
import type { SocketOnClose } from "./types";
|
|
280
|
+
import type { SocketOnError } from "./types";
|
|
281
|
+
import type { SocketOnMessage } from "./types";
|
|
282
|
+
import type { Message } from "./types";
|
|
283
|
+
import type { SocketOptions } from "./types";
|
|
284
|
+
//# sourceMappingURL=socket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"socket.d.ts","sourceRoot":"","sources":["../../../assets/js/phoenix/socket.js"],"names":[],"mappings":"AAsBA;;EAEE;AAEF;IACE;;;;;;;;;OASG;IACH,sBALW,MAAM,SAGN,aAAa,EA2IvB;IAxIC,wCAAwC;IACxC,sBADU,0BAA0B,CACqC;IACzE,uBAAuB;IACvB,UADU,OAAO,EAAE,CACD;IAClB,4BAA4B;IAC5B,YADU,CAAC,MAAM,IAAI,CAAC,EAAE,CACJ;IACpB,oBAAoB;IACpB,KADU,MAAM,CACJ;IACZ,qBAAqB;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;IAED,uBAKC;IAED,qDAyBC;IAED,uDASC;IAED,yDASC;IAED;;MAEE;IACF,mBAFU,UAAU,QAWnB;IAED;;;OAGG;IACH,oBAQC;IAED;;OAEG;IACH,yBAMC;IAED;;OAEG;IACH,mBAFa,MAAM,CASlB;IAED;;OAEG;IACH,eAFa,OAAO,CAEqC;IAEzD;;;OAGG;IACH,gBAFW,OAAO,QAKjB;IAED;;;;;OAKG;IACH,UAHW,MAAM,EAAE,QASlB;IAED;;;;;;OAMG;IACH,eAJW,MAAM,eACN,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,GACrB,OAAO,CAMnB;IAED;;OAEG;IACH,WAFW,QAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,QAatC;IAED;;;OAGG;IACH,WAFa,MAAM,CAOlB;IAED,sBAsBC;IAED,wBAKC;IAED;;MAEE;IACF,0BAFU,YAAY,CAAC,GAAG,CAAC,QA8B1B;IAED;;;;;;OAMG;IACH,8BAYC;IAED,iCAMC;CACF;gDAhsBmM,SAAS;oBANzL,WAAW;qCAMqK,SAAS;4BAAT,SAAS;4BAAT,SAAS;uCAAT,SAAS;4BAAT,SAAS;yBAAT,SAAS;kBAH3L,SAAS;qBAFN,YAAY;kCAKmK,SAAS;mCAAT,SAAS;mCAAT,SAAS;qCAAT,SAAS;6BAAT,SAAS;mCAAT,SAAS"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Creates a timer that accepts a `timerCalc` function to perform
|
|
4
|
+
* 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
|
+
*/
|
|
16
|
+
export default class Timer {
|
|
17
|
+
/**
|
|
18
|
+
* @param {() => void} callback
|
|
19
|
+
* @param {(tries: number) => number} timerCalc
|
|
20
|
+
*/
|
|
21
|
+
constructor(callback: () => void, timerCalc: (tries: number) => number);
|
|
22
|
+
/** @type {() => void} */
|
|
23
|
+
callback: () => void;
|
|
24
|
+
/** @type {(tries: number) => number} */
|
|
25
|
+
timerCalc: (tries: number) => number;
|
|
26
|
+
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
|
27
|
+
timer: ReturnType<typeof setTimeout> | undefined;
|
|
28
|
+
/** @type {number} */
|
|
29
|
+
tries: number;
|
|
30
|
+
reset(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Cancels any previous scheduleTimeout and schedules callback
|
|
33
|
+
*/
|
|
34
|
+
scheduleTimeout(): void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=timer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../../../assets/js/phoenix/timer.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH;IACE;;;MAGE;IACF,sBAHU,MAAM,IAAI,aACV,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAWlC;IARC,yBAAyB;IACzB,UADW,MAAM,IAAI,CACG;IACxB,wCAAwC;IACxC,WADW,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CACV;IAC1B,wDAAwD;IACxD,OADW,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,SAAS,CAC9B;IACtB,qBAAqB;IACrB,OADW,MAAM,CACH;IAGhB,cAGC;IAED;;OAEG;IACH,wBAOC;CACF"}
|