-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHighlightManager.js
More file actions
33 lines (29 loc) · 942 Bytes
/
HighlightManager.js
File metadata and controls
33 lines (29 loc) · 942 Bytes
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
import { throttle } from 'throttle-debounce';
import {WebSocket} from 'ws';
export default class HighlightManager {
constructor() {
this.ws = new WebSocket('wss://autosumo.techchrism.me/code/upload/');
this.highlight = throttle(100, fullID => {
const split = fullID.split('-');
const id = split.shift();
const statement = split.join('');
this.ws.send(JSON.stringify({
type: 'highlight',
codeID: id,
statement
}));
});
}
async waitForReady(id) {
return new Promise((resolve, reject) => {
this.ws.once('open', () => {
this.ws.send(JSON.stringify({
type: 'register',
id
}));
console.log('⏺️ Opened highlight websocket!');
resolve();
});
});
}
}