Skip to content

Commit

Permalink
Added quit functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
KeyserSoze1 committed Apr 14, 2017
1 parent 9e26959 commit 566345f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 8 additions & 1 deletion lib/ipcInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ var ipcInterface = function(options) {
// intialize the event emitter
eventEmitter.call(this);

// initiliaze flag for checking exit status
this.exiting = false;

// socket object
this.socket = new net.Socket();

Expand All @@ -44,7 +47,11 @@ var ipcInterface = function(options) {
console.log("Lost connection to socket. Atemping to reconnect");
}
// properly close the connection
this.socket.end()
this.socket.end();
// if exiting then do not reconnect socket
if (this.exiting) {
return;
}
// reconnect
this.socket.connect({path: this.options.socket}, function() {
if(this.options.verbose || this.options.debug){
Expand Down
7 changes: 7 additions & 0 deletions lib/mpv/_controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ var controls = {
stop: function() {
this.socket.command("stop", []);
},
// quit
quit: function() {
// set exiting flags when quit is called
this.exiting = true;
this.socket.exiting = true;
this.socket.command("quit", []);
},
// volume control values 0-100
volume: function(value) {
this.socket.setProperty("volume", value);
Expand Down
8 changes: 7 additions & 1 deletion lib/mpv/mpv.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function mpv(options, mpv_args){

// intialize the event emitter
eventEmitter.call(this);

// initiliaze flag for checking exit status
this.exiting = false;

// set the ipc command according to the mpv version
var ipcCommand = "";
Expand Down Expand Up @@ -197,6 +198,11 @@ function mpv(options, mpv_args){

// if mpv crashes restart it again
this.mpvPlayer.on('close', function respawn() {
// if exiting then no need to respawn
if (this.exiting) {
return;
}

if(this.options.debug){
console.log("MPV Player seems to have died. Restarting...");
}
Expand Down

0 comments on commit 566345f

Please sign in to comment.