-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplay.js
More file actions
34 lines (32 loc) · 1.06 KB
/
play.js
File metadata and controls
34 lines (32 loc) · 1.06 KB
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
import eventManager from 'src/utils/eventManager.js';
import { global, globalSet } from 'src/utils/global.js';
import wrap from 'src/utils/2.pokemon.js';
import { window } from 'src/utils/1.variables.js';
eventManager.on(':preload:Play', function hook() {
if (undefined !== window.bypassQueueEvents) {
location.href = '/Game';
return;
}
function opened(socket) {
eventManager.emit('socketOpen', socket);
}
globalSet('onOpen', function onOpen(event) {
this.super(event);
opened(global('socketQueue'));
});
globalSet('onMessage', function onMessage(event) {
const data = JSON.parse(event.data);
eventManager.emit(`pre:${data.action}`, data);
wrap(() => this.super(event));
eventManager.emit('Play:Message', data);
eventManager.emit(data.action, data);
});
const socketQueue = global('socketQueue', { throws: false });
if (socketQueue) {
if (socketQueue.readyState === WebSocket.OPEN) {
opened(socketQueue);
}
socketQueue.onopen = global('onOpen');
socketQueue.onmessage = global('onMessage');
}
});