oorja 1.5.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/lib/commands/signout.js +2 -2
- package/lib/commands/teletype/index.js +3 -3
- package/lib/lib/config.d.ts +5 -6
- package/lib/lib/config.js +12 -7
- package/lib/lib/encryption.d.ts +1 -1
- package/lib/lib/encryption.js +12 -7
- package/lib/lib/index.js +1 -0
- package/lib/lib/oorja/index.js +14 -13
- package/lib/lib/oorja/preflight.d.ts +1 -1
- package/lib/lib/oorja/preflight.js +17 -11
- package/lib/lib/surya/index.d.ts +2 -2
- package/lib/lib/surya/index.js +15 -13
- package/lib/lib/surya/types.d.ts +10 -10
- package/lib/lib/surya/vendor/phoenix/ajax.d.ts +8 -0
- package/lib/lib/surya/vendor/phoenix/ajax.js +85 -0
- package/lib/lib/surya/vendor/phoenix/channel.d.ts +154 -0
- package/lib/lib/surya/vendor/phoenix/channel.js +311 -0
- package/lib/lib/surya/vendor/phoenix/constants.d.ts +33 -0
- package/lib/lib/surya/vendor/phoenix/constants.js +32 -0
- package/lib/lib/surya/vendor/phoenix/index.d.ts +199 -0
- package/lib/lib/surya/vendor/phoenix/index.js +207 -0
- package/lib/lib/surya/vendor/phoenix/longpoll.d.ts +12 -0
- package/lib/lib/surya/vendor/phoenix/longpoll.js +129 -0
- package/lib/lib/surya/vendor/phoenix/presence.d.ts +44 -0
- package/lib/lib/surya/vendor/phoenix/presence.js +155 -0
- package/lib/lib/surya/vendor/phoenix/push.d.ts +57 -0
- package/lib/lib/surya/vendor/phoenix/push.js +125 -0
- package/lib/lib/surya/vendor/phoenix/serializer.d.ts +53 -0
- package/lib/lib/surya/vendor/phoenix/serializer.js +102 -0
- package/lib/lib/surya/vendor/phoenix/socket.d.ts +222 -0
- package/lib/lib/surya/vendor/phoenix/socket.js +544 -0
- package/lib/lib/surya/vendor/phoenix/timer.d.ts +25 -0
- package/lib/lib/surya/vendor/phoenix/timer.js +43 -0
- package/lib/lib/surya/vendor/phoenix/utils.d.ts +1 -0
- package/lib/lib/surya/vendor/phoenix/utils.js +15 -0
- package/lib/lib/teletype/auxiliary.d.ts +1 -1
- package/lib/lib/teletype/auxiliary.js +8 -4
- package/lib/lib/teletype/index.d.ts +1 -1
- package/lib/lib/teletype/index.js +13 -12
- package/lib/lib/utils.js +2 -1
- package/oclif.manifest.json +1 -1
- package/package.json +10 -9
- package/lib/lib/surya/vendor/phoenix.d.ts +0 -486
- package/lib/lib/surya/vendor/phoenix.js +0 -1299
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import Push from "./push";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {string} topic
|
|
5
|
+
* @param {(Object|function)} params
|
|
6
|
+
* @param {Socket} socket
|
|
7
|
+
*/
|
|
8
|
+
export default class Channel {
|
|
9
|
+
constructor(topic: any, params: any, socket: any);
|
|
10
|
+
/**
|
|
11
|
+
* Join the channel
|
|
12
|
+
* @param {integer} timeout
|
|
13
|
+
* @returns {Push}
|
|
14
|
+
*/
|
|
15
|
+
join(timeout?: any): any;
|
|
16
|
+
/**
|
|
17
|
+
* Hook into channel close
|
|
18
|
+
* @param {Function} callback
|
|
19
|
+
*/
|
|
20
|
+
onClose(callback: any): void;
|
|
21
|
+
/**
|
|
22
|
+
* Hook into channel errors
|
|
23
|
+
* @param {Function} callback
|
|
24
|
+
*/
|
|
25
|
+
onError(callback: any): number;
|
|
26
|
+
/**
|
|
27
|
+
* Subscribes on channel events
|
|
28
|
+
*
|
|
29
|
+
* Subscription returns a ref counter, which can be used later to
|
|
30
|
+
* unsubscribe the exact event listener
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* const ref1 = channel.on("event", do_stuff)
|
|
34
|
+
* const ref2 = channel.on("event", do_other_stuff)
|
|
35
|
+
* channel.off("event", ref1)
|
|
36
|
+
* // Since unsubscription, do_stuff won't fire,
|
|
37
|
+
* // while do_other_stuff will keep firing on the "event"
|
|
38
|
+
*
|
|
39
|
+
* @param {string} event
|
|
40
|
+
* @param {Function} callback
|
|
41
|
+
* @returns {integer} ref
|
|
42
|
+
*/
|
|
43
|
+
on(event: any, callback: any): number;
|
|
44
|
+
/**
|
|
45
|
+
* Unsubscribes off of channel events
|
|
46
|
+
*
|
|
47
|
+
* Use the ref returned from a channel.on() to unsubscribe one
|
|
48
|
+
* handler, or pass nothing for the ref to unsubscribe all
|
|
49
|
+
* handlers for the given event.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* // Unsubscribe the do_stuff handler
|
|
53
|
+
* const ref1 = channel.on("event", do_stuff)
|
|
54
|
+
* channel.off("event", ref1)
|
|
55
|
+
*
|
|
56
|
+
* // Unsubscribe all handlers from event
|
|
57
|
+
* channel.off("event")
|
|
58
|
+
*
|
|
59
|
+
* @param {string} event
|
|
60
|
+
* @param {integer} ref
|
|
61
|
+
*/
|
|
62
|
+
off(event: any, ref: any): void;
|
|
63
|
+
/**
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
canPush(): any;
|
|
67
|
+
/**
|
|
68
|
+
* Sends a message `event` to phoenix with the payload `payload`.
|
|
69
|
+
* Phoenix receives this in the `handle_in(event, payload, socket)`
|
|
70
|
+
* function. if phoenix replies or it times out (default 10000ms),
|
|
71
|
+
* then optionally the reply can be received.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* channel.push("event")
|
|
75
|
+
* .receive("ok", payload => console.log("phoenix replied:", payload))
|
|
76
|
+
* .receive("error", err => console.log("phoenix errored", err))
|
|
77
|
+
* .receive("timeout", () => console.log("timed out pushing"))
|
|
78
|
+
* @param {string} event
|
|
79
|
+
* @param {Object} payload
|
|
80
|
+
* @param {number} [timeout]
|
|
81
|
+
* @returns {Push}
|
|
82
|
+
*/
|
|
83
|
+
push(event: any, payload: any, timeout?: any): Push;
|
|
84
|
+
/** Leaves the channel
|
|
85
|
+
*
|
|
86
|
+
* Unsubscribes from server events, and
|
|
87
|
+
* instructs channel to terminate on server
|
|
88
|
+
*
|
|
89
|
+
* Triggers onClose() hooks
|
|
90
|
+
*
|
|
91
|
+
* To receive leave acknowledgements, use the `receive`
|
|
92
|
+
* hook to bind to the server ack, ie:
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* channel.leave().receive("ok", () => alert("left!") )
|
|
96
|
+
*
|
|
97
|
+
* @param {integer} timeout
|
|
98
|
+
* @returns {Push}
|
|
99
|
+
*/
|
|
100
|
+
leave(timeout?: any): Push;
|
|
101
|
+
/**
|
|
102
|
+
* Overridable message hook
|
|
103
|
+
*
|
|
104
|
+
* Receives all events for specialized message handling
|
|
105
|
+
* before dispatching to the channel callbacks.
|
|
106
|
+
*
|
|
107
|
+
* Must return the payload, modified or unmodified
|
|
108
|
+
* @param {string} event
|
|
109
|
+
* @param {Object} payload
|
|
110
|
+
* @param {integer} ref
|
|
111
|
+
* @returns {Object}
|
|
112
|
+
*/
|
|
113
|
+
onMessage(_event: any, payload: any, _ref: any): any;
|
|
114
|
+
/**
|
|
115
|
+
* @private
|
|
116
|
+
*/
|
|
117
|
+
isMember(topic: any, event: any, payload: any, joinRef: any): boolean;
|
|
118
|
+
/**
|
|
119
|
+
* @private
|
|
120
|
+
*/
|
|
121
|
+
joinRef(): any;
|
|
122
|
+
/**
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
rejoin(timeout?: any): void;
|
|
126
|
+
/**
|
|
127
|
+
* @private
|
|
128
|
+
*/
|
|
129
|
+
trigger(event: any, payload: any, ref: any, joinRef: any): void;
|
|
130
|
+
/**
|
|
131
|
+
* @private
|
|
132
|
+
*/
|
|
133
|
+
replyEventName(ref: any): string;
|
|
134
|
+
/**
|
|
135
|
+
* @private
|
|
136
|
+
*/
|
|
137
|
+
isClosed(): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* @private
|
|
140
|
+
*/
|
|
141
|
+
isErrored(): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* @private
|
|
144
|
+
*/
|
|
145
|
+
isJoined(): boolean;
|
|
146
|
+
/**
|
|
147
|
+
* @private
|
|
148
|
+
*/
|
|
149
|
+
isJoining(): boolean;
|
|
150
|
+
/**
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
isLeaving(): boolean;
|
|
154
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const push_1 = require("./push");
|
|
7
|
+
const timer_1 = require("./timer");
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {string} topic
|
|
11
|
+
* @param {(Object|function)} params
|
|
12
|
+
* @param {Socket} socket
|
|
13
|
+
*/
|
|
14
|
+
class Channel {
|
|
15
|
+
constructor(topic, params, socket) {
|
|
16
|
+
this.state = constants_1.CHANNEL_STATES.closed;
|
|
17
|
+
this.topic = topic;
|
|
18
|
+
this.params = (0, utils_1.closure)(params || {});
|
|
19
|
+
this.socket = socket;
|
|
20
|
+
this.bindings = [];
|
|
21
|
+
this.bindingRef = 0;
|
|
22
|
+
this.timeout = this.socket.timeout;
|
|
23
|
+
this.joinedOnce = false;
|
|
24
|
+
this.joinPush = new push_1.default(this, constants_1.CHANNEL_EVENTS.join, this.params, this.timeout);
|
|
25
|
+
this.pushBuffer = [];
|
|
26
|
+
this.stateChangeRefs = [];
|
|
27
|
+
this.rejoinTimer = new timer_1.default(() => {
|
|
28
|
+
if (this.socket.isConnected()) {
|
|
29
|
+
this.rejoin();
|
|
30
|
+
}
|
|
31
|
+
}, this.socket.rejoinAfterMs);
|
|
32
|
+
this.stateChangeRefs.push(this.socket.onError(() => this.rejoinTimer.reset()));
|
|
33
|
+
this.stateChangeRefs.push(this.socket.onOpen(() => {
|
|
34
|
+
this.rejoinTimer.reset();
|
|
35
|
+
if (this.isErrored()) {
|
|
36
|
+
this.rejoin();
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
this.joinPush.receive("ok", () => {
|
|
40
|
+
this.state = constants_1.CHANNEL_STATES.joined;
|
|
41
|
+
this.rejoinTimer.reset();
|
|
42
|
+
this.pushBuffer.forEach(pushEvent => pushEvent.send());
|
|
43
|
+
this.pushBuffer = [];
|
|
44
|
+
});
|
|
45
|
+
this.joinPush.receive("error", () => {
|
|
46
|
+
this.state = constants_1.CHANNEL_STATES.errored;
|
|
47
|
+
if (this.socket.isConnected()) {
|
|
48
|
+
this.rejoinTimer.scheduleTimeout();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
this.onClose(() => {
|
|
52
|
+
this.rejoinTimer.reset();
|
|
53
|
+
if (this.socket.hasLogger())
|
|
54
|
+
this.socket.log("channel", `close ${this.topic} ${this.joinRef()}`);
|
|
55
|
+
this.state = constants_1.CHANNEL_STATES.closed;
|
|
56
|
+
this.socket.remove(this);
|
|
57
|
+
});
|
|
58
|
+
this.onError(reason => {
|
|
59
|
+
if (this.socket.hasLogger())
|
|
60
|
+
this.socket.log("channel", `error ${this.topic}`, reason);
|
|
61
|
+
if (this.isJoining()) {
|
|
62
|
+
this.joinPush.reset();
|
|
63
|
+
}
|
|
64
|
+
this.state = constants_1.CHANNEL_STATES.errored;
|
|
65
|
+
if (this.socket.isConnected()) {
|
|
66
|
+
this.rejoinTimer.scheduleTimeout();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
this.joinPush.receive("timeout", () => {
|
|
70
|
+
if (this.socket.hasLogger())
|
|
71
|
+
this.socket.log("channel", `timeout ${this.topic} (${this.joinRef()})`, this.joinPush.timeout);
|
|
72
|
+
let leavePush = new push_1.default(this, constants_1.CHANNEL_EVENTS.leave, (0, utils_1.closure)({}), this.timeout);
|
|
73
|
+
leavePush.send();
|
|
74
|
+
this.state = constants_1.CHANNEL_STATES.errored;
|
|
75
|
+
this.joinPush.reset();
|
|
76
|
+
if (this.socket.isConnected()) {
|
|
77
|
+
this.rejoinTimer.scheduleTimeout();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
this.on(constants_1.CHANNEL_EVENTS.reply, (payload, ref) => {
|
|
81
|
+
this.trigger(this.replyEventName(ref), payload);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Join the channel
|
|
86
|
+
* @param {integer} timeout
|
|
87
|
+
* @returns {Push}
|
|
88
|
+
*/
|
|
89
|
+
join(timeout = this.timeout) {
|
|
90
|
+
if (this.joinedOnce) {
|
|
91
|
+
throw new Error("tried to join multiple times. 'join' can only be called a single time per channel instance");
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
this.timeout = timeout;
|
|
95
|
+
this.joinedOnce = true;
|
|
96
|
+
this.rejoin();
|
|
97
|
+
return this.joinPush;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Hook into channel close
|
|
102
|
+
* @param {Function} callback
|
|
103
|
+
*/
|
|
104
|
+
onClose(callback) {
|
|
105
|
+
this.on(constants_1.CHANNEL_EVENTS.close, callback);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Hook into channel errors
|
|
109
|
+
* @param {Function} callback
|
|
110
|
+
*/
|
|
111
|
+
onError(callback) {
|
|
112
|
+
return this.on(constants_1.CHANNEL_EVENTS.error, reason => callback(reason));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Subscribes on channel events
|
|
116
|
+
*
|
|
117
|
+
* Subscription returns a ref counter, which can be used later to
|
|
118
|
+
* unsubscribe the exact event listener
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* const ref1 = channel.on("event", do_stuff)
|
|
122
|
+
* const ref2 = channel.on("event", do_other_stuff)
|
|
123
|
+
* channel.off("event", ref1)
|
|
124
|
+
* // Since unsubscription, do_stuff won't fire,
|
|
125
|
+
* // while do_other_stuff will keep firing on the "event"
|
|
126
|
+
*
|
|
127
|
+
* @param {string} event
|
|
128
|
+
* @param {Function} callback
|
|
129
|
+
* @returns {integer} ref
|
|
130
|
+
*/
|
|
131
|
+
on(event, callback) {
|
|
132
|
+
let ref = this.bindingRef++;
|
|
133
|
+
this.bindings.push({ event, ref, callback });
|
|
134
|
+
return ref;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Unsubscribes off of channel events
|
|
138
|
+
*
|
|
139
|
+
* Use the ref returned from a channel.on() to unsubscribe one
|
|
140
|
+
* handler, or pass nothing for the ref to unsubscribe all
|
|
141
|
+
* handlers for the given event.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* // Unsubscribe the do_stuff handler
|
|
145
|
+
* const ref1 = channel.on("event", do_stuff)
|
|
146
|
+
* channel.off("event", ref1)
|
|
147
|
+
*
|
|
148
|
+
* // Unsubscribe all handlers from event
|
|
149
|
+
* channel.off("event")
|
|
150
|
+
*
|
|
151
|
+
* @param {string} event
|
|
152
|
+
* @param {integer} ref
|
|
153
|
+
*/
|
|
154
|
+
off(event, ref) {
|
|
155
|
+
this.bindings = this.bindings.filter((bind) => {
|
|
156
|
+
return !(bind.event === event && (typeof ref === "undefined" || ref === bind.ref));
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* @private
|
|
161
|
+
*/
|
|
162
|
+
canPush() { return this.socket.isConnected() && this.isJoined(); }
|
|
163
|
+
/**
|
|
164
|
+
* Sends a message `event` to phoenix with the payload `payload`.
|
|
165
|
+
* Phoenix receives this in the `handle_in(event, payload, socket)`
|
|
166
|
+
* function. if phoenix replies or it times out (default 10000ms),
|
|
167
|
+
* then optionally the reply can be received.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* channel.push("event")
|
|
171
|
+
* .receive("ok", payload => console.log("phoenix replied:", payload))
|
|
172
|
+
* .receive("error", err => console.log("phoenix errored", err))
|
|
173
|
+
* .receive("timeout", () => console.log("timed out pushing"))
|
|
174
|
+
* @param {string} event
|
|
175
|
+
* @param {Object} payload
|
|
176
|
+
* @param {number} [timeout]
|
|
177
|
+
* @returns {Push}
|
|
178
|
+
*/
|
|
179
|
+
push(event, payload, timeout = this.timeout) {
|
|
180
|
+
payload = payload || {};
|
|
181
|
+
if (!this.joinedOnce) {
|
|
182
|
+
throw new Error(`tried to push '${event}' to '${this.topic}' before joining. Use channel.join() before pushing events`);
|
|
183
|
+
}
|
|
184
|
+
let pushEvent = new push_1.default(this, event, function () { return payload; }, timeout);
|
|
185
|
+
if (this.canPush()) {
|
|
186
|
+
pushEvent.send();
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
pushEvent.startTimeout();
|
|
190
|
+
this.pushBuffer.push(pushEvent);
|
|
191
|
+
}
|
|
192
|
+
return pushEvent;
|
|
193
|
+
}
|
|
194
|
+
/** Leaves the channel
|
|
195
|
+
*
|
|
196
|
+
* Unsubscribes from server events, and
|
|
197
|
+
* instructs channel to terminate on server
|
|
198
|
+
*
|
|
199
|
+
* Triggers onClose() hooks
|
|
200
|
+
*
|
|
201
|
+
* To receive leave acknowledgements, use the `receive`
|
|
202
|
+
* hook to bind to the server ack, ie:
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* channel.leave().receive("ok", () => alert("left!") )
|
|
206
|
+
*
|
|
207
|
+
* @param {integer} timeout
|
|
208
|
+
* @returns {Push}
|
|
209
|
+
*/
|
|
210
|
+
leave(timeout = this.timeout) {
|
|
211
|
+
this.rejoinTimer.reset();
|
|
212
|
+
this.joinPush.cancelTimeout();
|
|
213
|
+
this.state = constants_1.CHANNEL_STATES.leaving;
|
|
214
|
+
let onClose = () => {
|
|
215
|
+
if (this.socket.hasLogger())
|
|
216
|
+
this.socket.log("channel", `leave ${this.topic}`);
|
|
217
|
+
this.trigger(constants_1.CHANNEL_EVENTS.close, "leave");
|
|
218
|
+
};
|
|
219
|
+
let leavePush = new push_1.default(this, constants_1.CHANNEL_EVENTS.leave, (0, utils_1.closure)({}), timeout);
|
|
220
|
+
leavePush.receive("ok", () => onClose())
|
|
221
|
+
.receive("timeout", () => onClose());
|
|
222
|
+
leavePush.send();
|
|
223
|
+
if (!this.canPush()) {
|
|
224
|
+
leavePush.trigger("ok", {});
|
|
225
|
+
}
|
|
226
|
+
return leavePush;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Overridable message hook
|
|
230
|
+
*
|
|
231
|
+
* Receives all events for specialized message handling
|
|
232
|
+
* before dispatching to the channel callbacks.
|
|
233
|
+
*
|
|
234
|
+
* Must return the payload, modified or unmodified
|
|
235
|
+
* @param {string} event
|
|
236
|
+
* @param {Object} payload
|
|
237
|
+
* @param {integer} ref
|
|
238
|
+
* @returns {Object}
|
|
239
|
+
*/
|
|
240
|
+
onMessage(_event, payload, _ref) { return payload; }
|
|
241
|
+
/**
|
|
242
|
+
* @private
|
|
243
|
+
*/
|
|
244
|
+
isMember(topic, event, payload, joinRef) {
|
|
245
|
+
if (this.topic !== topic) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
if (joinRef && joinRef !== this.joinRef()) {
|
|
249
|
+
if (this.socket.hasLogger())
|
|
250
|
+
this.socket.log("channel", "dropping outdated message", { topic, event, payload, joinRef });
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @private
|
|
259
|
+
*/
|
|
260
|
+
joinRef() { return this.joinPush.ref; }
|
|
261
|
+
/**
|
|
262
|
+
* @private
|
|
263
|
+
*/
|
|
264
|
+
rejoin(timeout = this.timeout) {
|
|
265
|
+
if (this.isLeaving()) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
this.socket.leaveOpenTopic(this.topic);
|
|
269
|
+
this.state = constants_1.CHANNEL_STATES.joining;
|
|
270
|
+
this.joinPush.resend(timeout);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* @private
|
|
274
|
+
*/
|
|
275
|
+
trigger(event, payload, ref, joinRef) {
|
|
276
|
+
let handledPayload = this.onMessage(event, payload, ref, joinRef);
|
|
277
|
+
if (payload && !handledPayload) {
|
|
278
|
+
throw new Error("channel onMessage callbacks must return the payload, modified or unmodified");
|
|
279
|
+
}
|
|
280
|
+
let eventBindings = this.bindings.filter(bind => bind.event === event);
|
|
281
|
+
for (let i = 0; i < eventBindings.length; i++) {
|
|
282
|
+
let bind = eventBindings[i];
|
|
283
|
+
bind.callback(handledPayload, ref, joinRef || this.joinRef());
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* @private
|
|
288
|
+
*/
|
|
289
|
+
replyEventName(ref) { return `chan_reply_${ref}`; }
|
|
290
|
+
/**
|
|
291
|
+
* @private
|
|
292
|
+
*/
|
|
293
|
+
isClosed() { return this.state === constants_1.CHANNEL_STATES.closed; }
|
|
294
|
+
/**
|
|
295
|
+
* @private
|
|
296
|
+
*/
|
|
297
|
+
isErrored() { return this.state === constants_1.CHANNEL_STATES.errored; }
|
|
298
|
+
/**
|
|
299
|
+
* @private
|
|
300
|
+
*/
|
|
301
|
+
isJoined() { return this.state === constants_1.CHANNEL_STATES.joined; }
|
|
302
|
+
/**
|
|
303
|
+
* @private
|
|
304
|
+
*/
|
|
305
|
+
isJoining() { return this.state === constants_1.CHANNEL_STATES.joining; }
|
|
306
|
+
/**
|
|
307
|
+
* @private
|
|
308
|
+
*/
|
|
309
|
+
isLeaving() { return this.state === constants_1.CHANNEL_STATES.leaving; }
|
|
310
|
+
}
|
|
311
|
+
exports.default = Channel;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const globalSelf: any;
|
|
2
|
+
export declare const phxWindow: any;
|
|
3
|
+
export declare const global: any;
|
|
4
|
+
export declare const DEFAULT_VSN = "2.0.0";
|
|
5
|
+
export declare const SOCKET_STATES: {
|
|
6
|
+
connecting: number;
|
|
7
|
+
open: number;
|
|
8
|
+
closing: number;
|
|
9
|
+
closed: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const DEFAULT_TIMEOUT = 10000;
|
|
12
|
+
export declare const WS_CLOSE_NORMAL = 1000;
|
|
13
|
+
export declare const CHANNEL_STATES: {
|
|
14
|
+
closed: string;
|
|
15
|
+
errored: string;
|
|
16
|
+
joined: string;
|
|
17
|
+
joining: string;
|
|
18
|
+
leaving: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const CHANNEL_EVENTS: {
|
|
21
|
+
close: string;
|
|
22
|
+
error: string;
|
|
23
|
+
join: string;
|
|
24
|
+
reply: string;
|
|
25
|
+
leave: string;
|
|
26
|
+
};
|
|
27
|
+
export declare const TRANSPORTS: {
|
|
28
|
+
longpoll: string;
|
|
29
|
+
websocket: string;
|
|
30
|
+
};
|
|
31
|
+
export declare const XHR_STATES: {
|
|
32
|
+
complete: number;
|
|
33
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XHR_STATES = exports.TRANSPORTS = exports.CHANNEL_EVENTS = exports.CHANNEL_STATES = exports.WS_CLOSE_NORMAL = exports.DEFAULT_TIMEOUT = exports.SOCKET_STATES = exports.DEFAULT_VSN = exports.global = exports.phxWindow = exports.globalSelf = void 0;
|
|
4
|
+
// @ts-nocheck
|
|
5
|
+
exports.globalSelf = typeof self !== "undefined" ? self : null;
|
|
6
|
+
exports.phxWindow = typeof window !== "undefined" ? window : null;
|
|
7
|
+
exports.global = exports.globalSelf || exports.phxWindow || {};
|
|
8
|
+
exports.DEFAULT_VSN = "2.0.0";
|
|
9
|
+
exports.SOCKET_STATES = { connecting: 0, open: 1, closing: 2, closed: 3 };
|
|
10
|
+
exports.DEFAULT_TIMEOUT = 10000;
|
|
11
|
+
exports.WS_CLOSE_NORMAL = 1000;
|
|
12
|
+
exports.CHANNEL_STATES = {
|
|
13
|
+
closed: "closed",
|
|
14
|
+
errored: "errored",
|
|
15
|
+
joined: "joined",
|
|
16
|
+
joining: "joining",
|
|
17
|
+
leaving: "leaving",
|
|
18
|
+
};
|
|
19
|
+
exports.CHANNEL_EVENTS = {
|
|
20
|
+
close: "phx_close",
|
|
21
|
+
error: "phx_error",
|
|
22
|
+
join: "phx_join",
|
|
23
|
+
reply: "phx_reply",
|
|
24
|
+
leave: "phx_leave"
|
|
25
|
+
};
|
|
26
|
+
exports.TRANSPORTS = {
|
|
27
|
+
longpoll: "longpoll",
|
|
28
|
+
websocket: "websocket"
|
|
29
|
+
};
|
|
30
|
+
exports.XHR_STATES = {
|
|
31
|
+
complete: 4
|
|
32
|
+
};
|