From 04c3dbf3971af65d43382a82d8638cc750e77d7c Mon Sep 17 00:00:00 2001 From: hensm Date: Wed, 24 Aug 2022 23:19:25 +0100 Subject: [PATCH] Handle session updates properly --- ext/src/cast/sdk/index.ts | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/ext/src/cast/sdk/index.ts b/ext/src/cast/sdk/index.ts index 478634d..2d7fd25 100644 --- a/ext/src/cast/sdk/index.ts +++ b/ext/src/cast/sdk/index.ts @@ -185,23 +185,12 @@ export default class { receiver // receiver ); + session.namespaces = status.namespaces; session.senderApps = status.senderApps; + session.statusText = status.statusText; session.transportId = status.transportId; this.#sessions.set(session.sessionId, session); - } - // eslint-disable-next-line no-fallthrough - case "cast:sessionUpdated": { - const status = message.data; - const session = this.#sessions.get(status.sessionId); - if (!session) { - logger.error(`Session not found (${status.sessionId})`); - return; - } - - session.statusText = status.statusText; - session.namespaces = status.namespaces; - session.receiver.volume = status.volume; /** * If session created via requestSession, the success @@ -220,6 +209,28 @@ export default class { break; } + case "cast:sessionUpdated": { + const status = message.data; + const session = this.#sessions.get(status.sessionId); + if (!session) { + logger.error(`Session not found (${status.sessionId})`); + break; + } + + session.statusText = status.statusText; + session.namespaces = status.namespaces; + session.receiver.volume = status.volume; + + const updateListeners = session?._updateListeners; + if (updateListeners) { + for (const listener of updateListeners) { + listener(session.status !== SessionStatus.STOPPED); + } + } + + break; + } + case "cast:sessionStopped": { const { sessionId } = message.data; const session = this.#sessions.get(sessionId);