-
Notifications
You must be signed in to change notification settings - Fork 13
/
state.js
33 lines (25 loc) · 694 Bytes
/
state.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
/* Ejemplo base */
const OfflineState = require('./offlineState');
const OnlineState = require('./onlineState');
const FailsafeSocket =(options)=>{
this.options = options;
this.queue = [];
this.currentState = null;
this.socket = null;
this.states = {
offline: new OfflineState(this),
online: new OnlineState(this)
}
this.changeState('offline');
}
FailsafeSocket.prototype.changeState = (state)=>{
console.log('Activating state: ' + state);
this.currentState = this.states[state];
this.currentState.activate();
}
FailsafeSocket.prototype.send = (data)=>{
this.currentState.send(data);
}
exports default (options)=>{
return new FailsafeSocket(options);
}