dhleong / ps4-waker

Wake your PS4 over LAN (with help from the Playstation App)
MIT License
451 stars 40 forks source link

Scripting API showing "A companion app has connected/disconnected" message #124

Closed noaboa97 closed 5 years ago

noaboa97 commented 5 years ago

Hello,

I used to use the command ps4-waker to start the PS4 because I didn't understand the scripting API but since I started to learn a bit of programming (javascript). I understand a little so I tried to rewrite my code. Also the messages "A companion app has connected/disconnected" annoyed me.

Unfortunatly I wrote a script which uses the scripting API but the messages still appear.

I also had a look at the device.js and if I understood it right everywhere where async is written before is a function I can use? like .startTitle()? There are not that much why didn't you just make a list of them and put them in the docu? Also can I do that if you allow me to do so?

I absolutly love this adapter! It's so great! I use it everyday with ioBroker. I could not live without it. Great work keep it up! I also hope it will work with PS5 (I hope Sony doesn't change anything how the app interacts with the PS4 then the PS5.

:)

Thanks best

Noah

dhleong commented 5 years ago

Thanks, glad you like it!

The "companion app" messages are unavoidable. The way ps4-waker works is by emulating the Playstation app, which is a "companion app" so whenever it connects or disconnects to the device, you'll get that message.

What you can do with the scripting API, however, is to keep your script running as a background process, thereby keeping the connection open. This way you only see one initial "connect" and one "disconnect" whenever the script exits. When using the ps4-waker command, it has to connect to do the action then disconnect when the command is complete, so there's no way to avoid the messages for each action.

Anything not prefixed by _ in the Device class should be considered a public API. They mostly are all async in this case, but that just means it returns a Promise; look up async/await tutorials for how to use those in Javascript. The get before it means it is used like a property, instead of a function (eg: device.isConnected).

I didn't make a list of them because they are all nicely documented in the JS file for anybody that understands JS and I didn't want to be redundant; the README file is hefty enough as-is. There are plenty of javascript tutorials out there, and I don't want to reinvent the wheel there.

Good luck!

GuccW6 commented 4 years ago

As I am a complete invalid when it comes to JS can I simply replace the device.js file in npm/node_modules/ps4-waker/dist with the code you posted or is there a lot more to it? I am just trying to avoid constant connection messages when launching apps or games after the initial switching on of the machine message.