Created
September 9, 2019 13:07
-
-
Save jamo/1cc7483e9687acca60db9ad27946ad39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const io = require('socket.io')(); | |
const middleware = require('socketio-wildcard')(); | |
io.use(middleware); | |
const client = require('socket.io-client'); | |
io.on('connection', function(socket) { | |
console.log(`connection`); | |
socket.upstream = client('http://127.0.0.1:8000'); | |
const patch = require('socketio-wildcard')(client.Manager); | |
patch(socket.upstream); | |
socket.on(`disconnect`, function() { | |
console.log(`disconnec`); | |
socket.upstream.disconnect(); | |
}); | |
socket.upstream.on('*', function(packet) { | |
const [msg, content] = packet.data; | |
socket.emit(msg, content); | |
console.log( | |
`replying`, | |
msg, | |
`content:`, | |
JSON.stringify(content).substring(0, 90), | |
); | |
}); | |
socket.on('*', function(packet) { | |
const [msg, content] = packet.data; | |
console.log(`sending`, msg, `content:`, JSON.stringify(content)); | |
socket.upstream.send(msg, content); | |
}); | |
}); | |
io.listen(8001); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment