forked from SocketCluster/socketcluster-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.js
40 lines (33 loc) · 1.31 KB
/
action.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const scErrors = require('sc-errors');
const InvalidActionError = scErrors.InvalidActionError;
function AGAction() {
this.outcome = null;
this.promise = new Promise((resolve, reject) => {
this._resolve = resolve;
this._reject = reject;
});
this.allow = (packet) => {
if (this.outcome) {
throw new InvalidActionError(`AGAction ${this.type} has already been ${this.outcome}; cannot allow`);
}
this.outcome = 'allowed';
this._resolve(packet);
};
this.block = (error) => {
if (this.outcome) {
throw new InvalidActionError(`AGAction ${this.type} has already been ${this.outcome}; cannot block`);
}
this.outcome = 'blocked';
this._reject(error);
};
}
AGAction.prototype.HANDSHAKE_WS = AGAction.HANDSHAKE_WS = 'handshakeWS';
AGAction.prototype.HANDSHAKE_SC = AGAction.HANDSHAKE_SC = 'handshakeSC';
AGAction.prototype.MESSAGE = AGAction.MESSAGE = 'message';
AGAction.prototype.TRANSMIT = AGAction.TRANSMIT = 'transmit';
AGAction.prototype.INVOKE = AGAction.INVOKE = 'invoke';
AGAction.prototype.SUBSCRIBE = AGAction.SUBSCRIBE = 'subscribe';
AGAction.prototype.PUBLISH_IN = AGAction.PUBLISH_IN = 'publishIn';
AGAction.prototype.PUBLISH_OUT = AGAction.PUBLISH_OUT = 'publishOut';
AGAction.prototype.AUTHENTICATE = AGAction.AUTHENTICATE = 'authenticate';
module.exports = AGAction;