feat(websocket): IOS14 compatibility due to unsupported BroadcastChannel

This commit is contained in:
kerms 2025-04-25 10:01:26 +02:00
parent e96037a073
commit b06b040e5c
2 changed files with 18 additions and 5 deletions

View File

@ -1,4 +1,17 @@
export const toServer = new BroadcastChannel("toServer");
export const toClient = new BroadcastChannel("toClient");
export const toWebsocketCtrl = new BroadcastChannel("toWebsocketCtrl");
export const toClientCtrl = new BroadcastChannel("toClientCtrl");
// Define a fallback mock class only if BroadcastChannel is undefined
const BC: typeof BroadcastChannel = typeof BroadcastChannel !== 'undefined'
? BroadcastChannel
: class {
constructor(name: string) {
// no-op
}
postMessage(_: any) {}
close() {}
addEventListener(_: string, __: any) {}
removeEventListener(_: string, __: any) {}
} as unknown as typeof BroadcastChannel;
export const toServer = new BC("toServer");
export const toClient = new BC("toClient");
export const toWebsocketCtrl = new BC("toWebsocketCtrl");
export const toClientCtrl = new BC("toClientCtrl");

View File

@ -127,7 +127,7 @@ class WebsocketClassic implements IWebsocketService{
}
export function getWebsocketService(): IWebsocketService {
if (typeof SharedWorker !== 'undefined') {
if (typeof SharedWorker !== 'undefined' && typeof localStorage !== 'undefined') {
return WebsocketShared.getInstance();
} else {
return WebsocketClassic.getInstance();