Skip to content

Reconnect to channel #13

Description

@c2ofh

HI,

I have a subscription to get informed, when a channel subscription was disconnected.
The subscription is really importend, so I want to reconnect. But I cam't find a way, to reconnect.
The this.channel.connected()-Subscription is not getting fired.

init(token: string) {
  this.connect(token);
  this.subscribe(token)
}

connect(token) {
  this.channel = this.cableService.cable(environment.cable_url, {token: token}).channel('GuestappChannel')
  this.cable = this.channel.cable;
}

subscribe(token) {
  this.channel.connected().subscribe(() => {
    this.globals.log('Websocket connected', LogType.info, true)
  })
  
  this.channel.disconnected().subscribe(() => {
    this.globals.log('Websocket disconnected', LogType.error, true)
    this.connect(token);
  })
}

When I load the page I have the log.

[12:07:55-541]: Websocket connected

For testing, I peform this.cable?.disconnect(); after 20 seconds.

[12:08:07-896]: Websocket disconnected

But then I can't establish a new connection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions