-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote-connection-hub.js
36 lines (27 loc) · 1017 Bytes
/
remote-connection-hub.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
var Readable = require('stream').Readable;
var path = require('path');
var url = require('url');
var SOCKET_PATH = '/write';
// TODO: Serve this directly instead of relying on global webpack config.
var SCRIPT_PATH = '/remote.bundle.js';
function RemoteConnectionHub() {}
RemoteConnectionHub.prototype.listen = function(
app, httpListener, debugViewCallback) {
app.ws(SOCKET_PATH, function(ws, req) {
var logStream = Readable();
logStream._read = function() {};
debugViewCallback(logStream);
ws.on('message', function(msg) { logStream.push(JSON.parse(msg).data); });
ws.on('close', function() { logStream.push(null); });
}.bind(this));
console.log(
'Add this script tag to the page you want to debug, ABOVE any other scripts:');
var addr = httpListener.address();
console.log('<script src="' + url.format({
protocol: 'http',
hostname: addr.address,
port: addr.port,
pathname: SCRIPT_PATH
}) + '"></script>');
};
module.exports = RemoteConnectionHub;