Phoenix.js (client) reconnect()?

After some searching found this:

Code from Phoenix.js reconnect params

socket.onOpen(() => { socket.params = () => ({ reconnect: true, … }) })

I think this piece can be used with some if statements for each case you mentioned.

So

if (token!=null){
  socket.onOpen(() => {
  socket.params = () => ({ reconnect: true, … })
  })
}

I think this should work, this is from the top of my head.