Skip to content

Commit

Permalink
fix(stop): use start/stop interface on mDNS to correctly stop servers (
Browse files Browse the repository at this point in the history
  • Loading branch information
npwalker committed Aug 6, 2016
1 parent a2a8ef9 commit 9d55d17
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
15 changes: 15 additions & 0 deletions lib/rtsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ function RtspServer(options, external) {
}

RtspServer.prototype.connectHandler = function(socket) {

if (this.handling && !this.clientConnected) {
socket.end();
return;
}

this.socket = socket;
this.handling = this.socket;

socket.id = new Date().getTime();

const parser = new ServerParser(socket, {
protocol: 'RTSP/1.0',
statusMessages: {
Expand Down Expand Up @@ -135,4 +146,8 @@ RtspServer.prototype.disconnectHandler = function(socket) {
}
};

RtspServer.prototype.stop = function() {
this.rtp.stop()
}

module.exports = RtspServer;
27 changes: 22 additions & 5 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,34 @@ NodeTunes.prototype.start = function(callback) {
} else {
debug('server running without broadcast (on port %s)', port);
}
callback(null,{
port,
macAddress: this.options.macAddress,
}

this.netServer = net.createServer(this.rtspServer.connectHandler.bind(this.rtspServer)).listen(port, function() {
this.advertisement = mdns.createAdvertisement(mdns.tcp('raop'), port, {
name: this.options.macAddress + '@' + this.options.serverName,
txtRecord: this.txtSetup,
});
});
});
this.advertisement.start()

if (callback) {
callback(null, {
port: port,
macAddress: this.options.macAddress,
});

}

debug('broadcasting mdns advertisement (for port %s)', port);

}.bind(this));
}.bind(this));
};

NodeTunes.prototype.stop = function() {
debug('stopping nodetunes server');
this.netServer.close();
this.rtspServer.stop();
this.advertisement.stop();
};

module.exports = NodeTunes;

0 comments on commit 9d55d17

Please sign in to comment.