Skip to content

Commit

Permalink
server: remember target info
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Jul 24, 2012
1 parent e3423a0 commit 0b71691
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/vock/server.js
Expand Up @@ -10,6 +10,7 @@ function Server() {
EventEmitter.call(this);

this.target = null;
this.rtarget = null;
this.protocol = vock.protocol.create();

// Create audio unit
Expand All @@ -26,10 +27,20 @@ server.create = function create() {
};

Server.prototype.init = function init() {
var self = this;
var self = this,
lastRinfo;

// Pass packets from other side to protocol parser
this.socket.on('message', function(raw) {
this.socket.on('message', function(raw, rinfo) {
if (!self.target) return;
if (self.rtarget &&
(self.rtarget.address !== rinfo.address ||
self.rtarget.port !== rinfo.port)) {
// Connection came from different address
return;
}
lastRinfo = rinfo;

try {
var packet = msgpack.decode(raw);
self.protocol.receive(packet);
Expand All @@ -51,6 +62,7 @@ Server.prototype.init = function init() {
});

this.protocol.on('connect', function() {
self.rtarget = lastRinfo;
self.audio.start();
});

Expand Down

0 comments on commit 0b71691

Please sign in to comment.