Migrate to EventBus

This commit is contained in:
redphx
2024-12-08 21:06:42 +07:00
parent e1ba2344b7
commit b11d465804
10 changed files with 77 additions and 73 deletions

View File

@@ -20,7 +20,11 @@ type ScriptEvents = {
deviceVibrationUpdated: {};
// GH pages
listForcedNativeMkbUpdated: {};
listForcedNativeMkbUpdated: {
data: {
data: any;
};
};
};
type StreamEvents = {
@@ -29,6 +33,8 @@ type StreamEvents = {
statePlaying: { $video?: HTMLVideoElement };
stateStopped: {};
stateError: {};
dataChannelCreated: { dataChannel: RTCDataChannel };
};
export class BxEventBus<TEvents extends Record<string, any>> {

View File

@@ -16,8 +16,6 @@ export namespace BxEvent {
export const REMOTE_PLAY_READY = 'bx-remote-play-ready';
export const REMOTE_PLAY_FAILED = 'bx-remote-play-failed';
export const DATA_CHANNEL_CREATED = 'bx-data-channel-created';
export const GAME_BAR_ACTION_ACTIVATED = 'bx-game-bar-action-activated';
export const MICROPHONE_STATE_CHANGED = 'bx-microphone-state-changed';
export const SPEAKER_STATE_CHANGED = 'bx-speaker-state-changed';

View File

@@ -53,7 +53,9 @@ export class GhPagesUtils {
if (json.$schemaVersion === supportedSchema) {
// Save to storage
window.localStorage.setItem(key, JSON.stringify(json));
BxEventBus.Script.emit('listForcedNativeMkbUpdated', {});
BxEventBus.Script.emit('listForcedNativeMkbUpdated', {
data: json,
});
}
});

View File

@@ -76,10 +76,7 @@ export function patchRtcPeerConnection() {
// @ts-ignore
const dataChannel = nativeCreateDataChannel.apply(this, arguments);
BxEvent.dispatch(window, BxEvent.DATA_CHANNEL_CREATED, {
dataChannel: dataChannel,
});
BxEventBus.Stream.emit('dataChannelCreated', { dataChannel });
return dataChannel;
}

View File

@@ -432,8 +432,8 @@ export class GlobalSettingsStorage extends BaseSettingsStorage {
if (!setting.unsupported) {
(setting as any).multipleOptions = GhPagesUtils.getNativeMkbCustomList(true);
BxEventBus.Script.on('listForcedNativeMkbUpdated', () => {
(setting as any).multipleOptions = GhPagesUtils.getNativeMkbCustomList();
BxEventBus.Script.on('listForcedNativeMkbUpdated', payload => {
(setting as any).multipleOptions = payload.data.data;
});
}
},