How to shutdown osjs remotely via websockets


#1

Hi! I’m thinking of making a sort of dashboard to control your osjs instance. Is there a way to make osjs shutdown via a button press on this dashboard?

Eg. Press button and it sends kill signal via websockets to the OS


#2

You can add an event listener on your server core instance to do this:

// server
core.on('shutdown-my-instance', () => core.destroy())

// client
core.ws.send(JSON.stringify({
  name: 'shutdown-my-instance',
  params: [] // Must be defined
})


#3

so would i link the server code to the os and the client code to the button? and i would like this to be remote like

  1. connect to instance via websocket address for osjs from external site
  2. send signal
  3. shutdown

#4

Then you’re probably better off creating a basic HTTP endpoint on the OS.js server. By default you can’t connect to the websocket without having a session on the same domain.


#5

okay, thanks!

issue has been solved