tcp: better client storing

This commit is contained in:
jean-emmanuel 2018-05-25 13:34:27 +02:00
parent b6e14b3ed5
commit 0119298480
2 changed files with 5 additions and 5 deletions

View file

@ -112,8 +112,8 @@ class OscServer {
args: data.args
}, data.host, data.port)
if (tcpInPort && oscTCPServer.clients[data.host + ':' + data.port]) {
oscTCPServer.clients[data.host + ':' + data.port].send({
if (tcpInPort && oscTCPServer.clients[data.host] && oscTCPServer.clients[data.host][data.port]) {
oscTCPServer.clients[data.host][data.port].send({
address: data.address,
args: data.args
})

View file

@ -15,7 +15,6 @@ class OscTCPClient extends EventEmitter {
this.options = options
this.remoteAddress = options.address
this.remotePort = options.port
this.name = this.remoteAddress + ':' + this.remotePort
this.open()
@ -86,14 +85,15 @@ class OscTCPServer extends EventEmitter {
addClient(client) {
this.clients[client.name] = client
this.clients[client.remoteAddress] = this.clients[client.remoteAddress] || {}
this.clients[client.remoteAddress][client.remotePort] = client
client.on('message', (msg, timetag, info)=>{
this.emit('message', msg, timetag, info)
})
client.on('die', (hadError)=>{
delete this.clients[client.name]
if (this.clients[client.remoteAddress]) delete this.clients[client.remoteAddress][client.remotePort]
})
}