Handle session updates properly

This commit is contained in:
hensm
2022-08-24 23:19:25 +01:00
parent d71d564f91
commit 04c3dbf397

View File

@@ -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);