Skip to content

Commit

Permalink
Further checks for user disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Rutland committed Feb 7, 2023
1 parent f6fee92 commit 9e13b18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lickdltd/chorus-dcl",
"version": "0.11.2",
"version": "0.11.3",
"description": "Lickd Chorus DCL library",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
14 changes: 9 additions & 5 deletions src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,22 @@ export class Player extends Entity {
this._token = await this.signIn(this._stream)

if (!this._connected) {
Logger.log('connect discarded - user has disconnected')
Logger.log('connection discarded - user has disconnected while retrieving token')
await this.disconnect(true)
return
}

this.addComponentOrReplace(new AudioStream(this._url + this._stream + '?token=' + this._token))
this.getComponent(AudioStream).volume = this._volume

this.addComponentOrReplace(
new utils.Interval(Player.HEARTBEAT_INTERVAL, async () => await this.heartbeat(this._token))
)
this.addComponentOrReplace(new utils.Interval(Player.HEARTBEAT_INTERVAL, () => this.heartbeat(this._token)))

Logger.log('connected successfully')

if (!this._connected) {
Logger.log('connection stream discarded - user has disconnected while connecting')
await this.disconnect(true)
}
} catch (e) {
Logger.log('connection failed', e.message)
}
Expand Down Expand Up @@ -347,6 +351,6 @@ export class Player extends Entity {
}

private isConnected(): boolean {
return this.hasComponent(AudioStream)
return this.hasComponent(AudioStream) || this._connected
}
}

0 comments on commit 9e13b18

Please sign in to comment.