-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Conversation
Sorry for the late reply. Yes I have a similar functionality in a local branch, with the similar, somewhat "dirty" approach you have. I was actually working on the module about a week ago. As discussed in #11 I am using the After that is done I try to add a quit / restart feature based on that. I will have a closer look at your code and see if it can be merged, to give the functionality until I have implemented it properly. I have a university project to hand in on May 3rd, so I don't know if I can work much on it before that, but I'm definitely on it. Thank you very much :) |
No problem. This was just something to quickly get the issue I was seeing resolved. It may not necessarily be the best way to deal with the specific issue considering all things involved. Thanks for the work you've done so far! |
Just a quick update. I'm on it. I already implemented the promise to detect wether MPV was able to connect to the IPC Socket or, which got already rid of all the Problem is though, since the resolving of the promise is asynchronous,
if you call some commands right after creating the mpv object, it will fail because that asynchronous part setting up stuff has not yet finished. I could solve this by making the constructor return another promise, but that would break the API for everyone using it so far. I'm trying to find some way to make the constructor only return when everything is finished, but I didn't get that working yet. Once that works, stoping and restarting mpv should not be that hard to implement :) Just wanted to let you know, that I'm working on it. |
Thanks for the update! |
Sorry development is going slowly. The thing is I probably can't make this without breaking changes, that's why I'm very careful about it. The constructor now takes some time to complete, since it waits until mpv created the socket, checks if that was successful and then connects to it. Thus any code like for example I thought about a few options 1Wait for the stuff to be finished before returning. That would make the constructor blocking. That's why I don't like this idea 2Give the constructor some 3Make the constructor return a promise. Slightly more modern than version 2 but it yields the same problem: the constructor does not return an instance but a promise. 4Take the Socket thing out of the constructor and introduce new methods called
to
So far I like this idea the best. 5 Get up my lazy ass and read into async and awaitKinda like 4 but maybe more modern? @KeyserSoze1, @iamale, @pussinboot what do you guys think? (If you're even still using my library :D ) Again sorry for the slow development. I'm eager to here your opinions :) Cheers |
async/await isn't actually something really new, it's all about Promises. I. e.: mpvAPI.create().then((mpv) => {
...
}); becomes:
I think |
Another possible solution is emitting a |
Exactly, the constructor should return an instance. I though about the ready event as well, it's similar to the ready callback I think. As for the initialization. The constructor would still initialize mpv, set everything up and so on. It just wouldn't start the actual player yet. Maybe something that is even desired for some applications? The goal is to include a start and stop (quit) functionality anyways. This would nicely blend with it. I kind of like it more than letting the constructor return a promise, since it should return an instance. So either making start/stop return a promise or using async (which results in returning a promise I think) could be a good choice. Either way I don't think this change can be done in an unbreaking way =/ Thanks for your thoughts :) |
i like 4 the most. adding asynchronous code to starting an instance of mpv will break things either way, with |
I don't like let mpv = new mpvAPI();
mpv.start() ... because |
Good point, the thing that the user might be forgetting the start thing, (For the quit functionality there will be a quit and start functionality anyway though). Is it common in JS to have constructors returning a promise or having something like a callback? Because that would be the alternative to the start / quit thing... kinda don't like it too much I have to say. This is the part within the constructor that causes the asychronity
This could also be a point to tackle in order the keep the original API functionality to the outside. Any suggetions there? |
TBH I'm not even sure why do we need this explicit |
Yeah I'm coming from an object oriented background, like C++ and Java. So it felt natural to me when I was creating this library. How would you go about it in a different way? Without the new keyword? Of course I could run the asynchronous part inside synchronously, it's matter of a few milliseconds, but making things blocking should never be the solution I think. |
I've been thinking about it and discussing about it with a friend who's really good with JavaScript here at my University. I kinda came to the conclusion, that waiting for the asynchronous part inside of the constructor, making it synchronous isn't all that bad. We're talking about mere milliseconds here (it's actually already happening with all the With the planned start and stop method's in mind I could go on and offer two ways to initialize node-mpv. The way it used to be with
And that being synchronous / blocking. And another version were it only initializes the player but does not start it. The player can then be started with something like a start method, which is asynchronous aka returning a Promise. Anyhow, this will require some big code reorganization, been already doing that yesterday, might as well go on. Again sorry you guys have to wait so long for this :( |
I've just committed the first Version with Promises in a local branch. I went for the version
This immediately gets rid of all the After thinking a lot about it I had to break the API unfortunately. I like this way the best and I will look into, if I can start the MPV player internally when calling loadFile() and the player is not yet started. Because this breaks the API I will work towards a 2.0.0 release, with possibly a little more features. |
In the end I decided to merge this PR anyway. While working on the start and quit functionality I learned more about NodeJs, Sockets and all that stuff. I broke the API, changed quite a few things and decided to safe that for a Version 2.0.0, since it breaks the API, you know. But I still don't wanna make you wait any long (Again if you're still using this, somehow I doubt it :D). That's why I put a quit function inside version 1 anyways. I'm afraid there's not too much left of your code @KeyserSoze1 , very sorry about that :( . But I decided to merge this and work from it anyways, because you gave me the initial idea and kind of as a Thank You (well if you actually give a sh*t about being mentioned as a contributor, that is of course :) ). Once again my apologies that this took so many month, especially because I ended up merging it anyway. I didn't wanna rush it and I am really happy with how Version 2 turned out so far. If anybody's interested I push a new branch with it, you can see it here. Again, thank you all for your help :) |
Not sure if this is honestly the best way to handle this.
Added quit function and added settings so the socket won't reconnect and the mpv process won't respawn.
The Mpv instance is no longer valid and can no longer be used after quit is called.
This was brought on because I've had issues with the mpv process hanging my app and not exiting properly. I'm hoping that if this isn't merged, similar functionality will be brought in to handle this issue.