Unsubscribe/Disconnect the real time update JS library

Viewed 247

We are dealing with a SPA (single page application) so when the user logs in the UI refreshes without a page refresh. We also initiate the stream socket connection through the library like below. Now when the user logs out we want to destroy this. We tried user1.unsubscribe() and client.disconnect() but doesn't seem to work eventhough method looks defined in the source.

What's the right way to handle this in an environment where the page never refreshes?

  client = Stream.connect('xxx', null, 'xxx')
  user1 = client.feed('notification', @user.get('id'), @user.get('streamToken'))

  callback = (data) =>
    return

  failCallback = (data) ->
    return

  user1.subscribe(callback).then (->
  ), failCallback

  @user.on 'logged:out', ->
    user1.unsubscribe()
    client.disconnect()
1 Answers
Related