5
我使用socket.io創建了一個快速應用程序。現在我想要一個瀏覽器終端與我在節點中創建的repl連接。以下是我想出了將Socket.io流連接到節點repl流
var io = io.listen(server);
var sessionSockets = new SessionSockets(io, sessionStore, cookieParser);
sessionSockets.on('connection', function (err, socket, session) {
var stream = createStream(socket);
var replInstance = repl.start({
prompt: "> ",
input: stream,
output: stream
});
repls[socket.id] = replInstance;
});
var createStream = function(socket) {
var stream = new Stream();
stream.readable = true;
stream.resume = function() {};
stream.write = function(data) {
socket.emit('stdout', data);
};
socket.on('stdin', function(data) {
// emit data to repl stream - DOES NOT WORK
stream.emit('data', data);
});
return stream;
};
它所做的已經是推動控制檯輸出到socket.io連接,並將其顯示在前臺。它沒有在repl中輸入來自前端的數據。
想法?