-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (40 loc) · 1.23 KB
/
index.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
41
/**
* polyfill script for hippy live-reload on development environment
*/
(function () {
function initLiveReload() {
if (!global.WebSocket) return console.warn('websocket is unavailable for current hippy version');
const wsUrl = 'ws://127.0.0.1:38999/debugger-live-reload';
const ws = new global.WebSocket(wsUrl);
ws.onmessage = (evt) => {
console.info('[websocket onMessage]', evt);
try {
const data = JSON.parse(evt.data);
if (data.action === 'compileStart') {
console.info('[prepare reload bundle]');
} else if (data.action === 'compileSuccess') {
console.info('[start reload bundle]');
ws.close();
global.Hippy.bridge.callNative('DevMenu', 'reload');
}
} catch (err) {
console.error('live debug ws onmessage error', err);
}
};
global.Hippy.on('destroyInstance', () => {
ws.close();
});
}
if (!global.IS_LIVE_RELOAD_INIT) {
// initial only once
global.IS_LIVE_RELOAD_INIT = true;
try {
global.setTimeout(() => {
initLiveReload();
console.info('[Live Reload Start...]');
}, 3000)
} catch (e) {
console.error('Hippy initLiveReload error', e);
}
}
}());