-
-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathconnectServer.ts
More file actions
42 lines (37 loc) · 973 Bytes
/
connectServer.ts
File metadata and controls
42 lines (37 loc) · 973 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
34
35
36
37
38
39
40
41
42
import Socket from 'licia/Socket';
import query from 'licia/query';
import chobitsu from 'chobitsu';
import { serverUrl, id, secret } from './config';
import { getFavicon } from './util';
let isInit = false;
export default function () {
const proxy = `${serverUrl}proxy`;
chobitsu.domain('Page').setProxy({
proxy,
});
chobitsu.domain('Debugger').setProxy({
proxy,
});
chobitsu.domain('CSS').setProxy({
proxy,
});
const ws = new Socket(
`${serverUrl.replace(/^http/, 'ws')}target/${id}?${query.stringify({
url: location.href,
title: (window as any).ChiiTitle || document.title,
favicon: getFavicon(),
'__chobitsu-hide__': true,
...(secret ? { secret } : {}),
})}`
);
ws.on('open', () => {
isInit = true;
ws.on('message', event => {
chobitsu.sendRawMessage(event.data);
});
});
chobitsu.setOnMessage((message: string) => {
if (!isInit) return;
ws.send(message);
});
}