Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added quit functionality #13

Merged
merged 1 commit into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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