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

@ -141,7 +141,7 @@ function deepClone(obj) {
} }
var BxEvent; var BxEvent;
((BxEvent) => { ((BxEvent) => {
BxEvent.JUMP_BACK_IN_READY = "bx-jump-back-in-ready", BxEvent.POPSTATE = "bx-popstate", BxEvent.STREAM_SESSION_READY = "bx-stream-session-ready", BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED = "bx-custom-touch-layouts-loaded", BxEvent.TOUCH_LAYOUT_MANAGER_READY = "bx-touch-layout-manager-ready", BxEvent.REMOTE_PLAY_READY = "bx-remote-play-ready", BxEvent.REMOTE_PLAY_FAILED = "bx-remote-play-failed", BxEvent.DATA_CHANNEL_CREATED = "bx-data-channel-created", BxEvent.GAME_BAR_ACTION_ACTIVATED = "bx-game-bar-action-activated", BxEvent.MICROPHONE_STATE_CHANGED = "bx-microphone-state-changed", BxEvent.SPEAKER_STATE_CHANGED = "bx-speaker-state-changed", BxEvent.VIDEO_VISIBILITY_CHANGED = "bx-video-visibility-changed", BxEvent.CAPTURE_SCREENSHOT = "bx-capture-screenshot", BxEvent.POINTER_LOCK_REQUESTED = "bx-pointer-lock-requested", BxEvent.POINTER_LOCK_EXITED = "bx-pointer-lock-exited", BxEvent.NAVIGATION_FOCUS_CHANGED = "bx-nav-focus-changed", BxEvent.XCLOUD_DIALOG_SHOWN = "bx-xcloud-dialog-shown", BxEvent.XCLOUD_DIALOG_DISMISSED = "bx-xcloud-dialog-dismissed", BxEvent.XCLOUD_GUIDE_MENU_SHOWN = "bx-xcloud-guide-menu-shown", BxEvent.XCLOUD_POLLING_MODE_CHANGED = "bx-xcloud-polling-mode-changed", BxEvent.XCLOUD_RENDERING_COMPONENT = "bx-xcloud-rendering-component", BxEvent.XCLOUD_ROUTER_HISTORY_READY = "bx-xcloud-router-history-ready"; BxEvent.JUMP_BACK_IN_READY = "bx-jump-back-in-ready", BxEvent.POPSTATE = "bx-popstate", BxEvent.STREAM_SESSION_READY = "bx-stream-session-ready", BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED = "bx-custom-touch-layouts-loaded", BxEvent.TOUCH_LAYOUT_MANAGER_READY = "bx-touch-layout-manager-ready", BxEvent.REMOTE_PLAY_READY = "bx-remote-play-ready", BxEvent.REMOTE_PLAY_FAILED = "bx-remote-play-failed", BxEvent.GAME_BAR_ACTION_ACTIVATED = "bx-game-bar-action-activated", BxEvent.MICROPHONE_STATE_CHANGED = "bx-microphone-state-changed", BxEvent.SPEAKER_STATE_CHANGED = "bx-speaker-state-changed", BxEvent.VIDEO_VISIBILITY_CHANGED = "bx-video-visibility-changed", BxEvent.CAPTURE_SCREENSHOT = "bx-capture-screenshot", BxEvent.POINTER_LOCK_REQUESTED = "bx-pointer-lock-requested", BxEvent.POINTER_LOCK_EXITED = "bx-pointer-lock-exited", BxEvent.NAVIGATION_FOCUS_CHANGED = "bx-nav-focus-changed", BxEvent.XCLOUD_DIALOG_SHOWN = "bx-xcloud-dialog-shown", BxEvent.XCLOUD_DIALOG_DISMISSED = "bx-xcloud-dialog-dismissed", BxEvent.XCLOUD_GUIDE_MENU_SHOWN = "bx-xcloud-guide-menu-shown", BxEvent.XCLOUD_POLLING_MODE_CHANGED = "bx-xcloud-polling-mode-changed", BxEvent.XCLOUD_RENDERING_COMPONENT = "bx-xcloud-rendering-component", BxEvent.XCLOUD_ROUTER_HISTORY_READY = "bx-xcloud-router-history-ready";
function dispatch(target, eventName, data) { function dispatch(target, eventName, data) {
if (!target) return; if (!target) return;
if (!eventName) { if (!eventName) {
@ -207,7 +207,9 @@ class GhPagesUtils {
static getNativeMkbCustomList(update = !1) { static getNativeMkbCustomList(update = !1) {
let key = "BetterXcloud.GhPages.ForceNativeMkb"; let key = "BetterXcloud.GhPages.ForceNativeMkb";
update && NATIVE_FETCH(GhPagesUtils.getUrl("native-mkb/ids.json")).then((response) => response.json()).then((json) => { update && NATIVE_FETCH(GhPagesUtils.getUrl("native-mkb/ids.json")).then((response) => response.json()).then((json) => {
if (json.$schemaVersion === 1) window.localStorage.setItem(key, JSON.stringify(json)), BxEventBus.Script.emit("listForcedNativeMkbUpdated", {}); if (json.$schemaVersion === 1) window.localStorage.setItem(key, JSON.stringify(json)), BxEventBus.Script.emit("listForcedNativeMkbUpdated", {
data: json
});
}); });
let info = JSON.parse(window.localStorage.getItem(key) || "{}"); let info = JSON.parse(window.localStorage.getItem(key) || "{}");
if (info.$schemaVersion !== 1) return window.localStorage.removeItem(key), {}; if (info.$schemaVersion !== 1) return window.localStorage.removeItem(key), {};
@ -1540,8 +1542,8 @@ class GlobalSettingsStorage extends BaseSettingsStore {
default: [], default: [],
unsupported: !AppInterface && UserAgent.isMobile(), unsupported: !AppInterface && UserAgent.isMobile(),
ready: (setting) => { ready: (setting) => {
if (!setting.unsupported) setting.multipleOptions = GhPagesUtils.getNativeMkbCustomList(!0), BxEventBus.Script.on("listForcedNativeMkbUpdated", () => { if (!setting.unsupported) setting.multipleOptions = GhPagesUtils.getNativeMkbCustomList(!0), BxEventBus.Script.on("listForcedNativeMkbUpdated", (payload) => {
setting.multipleOptions = GhPagesUtils.getNativeMkbCustomList(); setting.multipleOptions = payload.data.data;
}); });
}, },
params: { params: {
@ -6121,9 +6123,7 @@ function patchRtcPeerConnection() {
let nativeCreateDataChannel = RTCPeerConnection.prototype.createDataChannel; let nativeCreateDataChannel = RTCPeerConnection.prototype.createDataChannel;
RTCPeerConnection.prototype.createDataChannel = function() { RTCPeerConnection.prototype.createDataChannel = function() {
let dataChannel = nativeCreateDataChannel.apply(this, arguments); let dataChannel = nativeCreateDataChannel.apply(this, arguments);
return BxEvent.dispatch(window, BxEvent.DATA_CHANNEL_CREATED, { return BxEventBus.Stream.emit("dataChannelCreated", { dataChannel }), dataChannel;
dataChannel
}), dataChannel;
}; };
let maxVideoBitrateDef = getPrefDefinition("stream.video.maxBitrate"), maxVideoBitrate = getPref("stream.video.maxBitrate"), codec = getPref("stream.video.codecProfile"); let maxVideoBitrateDef = getPrefDefinition("stream.video.maxBitrate"), maxVideoBitrate = getPref("stream.video.maxBitrate"), codec = getPref("stream.video.codecProfile");
if (codec !== "default" || maxVideoBitrate < maxVideoBitrateDef.max) { if (codec !== "default" || maxVideoBitrate < maxVideoBitrateDef.max) {
@ -6443,18 +6443,17 @@ BxEventBus.Stream.on("statePlaying", (payload) => {
BxEventBus.Stream.on("stateError", () => { BxEventBus.Stream.on("stateError", () => {
BxEventBus.Stream.emit("stateStopped", {}); BxEventBus.Stream.emit("stateStopped", {});
}); });
window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, (e) => { BxEventBus.Stream.on("dataChannelCreated", (payload) => {
let dataChannel = e.dataChannel; let { dataChannel } = payload;
if (!dataChannel || dataChannel.label !== "message") return; if (dataChannel?.label !== "message") return;
dataChannel.addEventListener("message", async (msg) => { dataChannel.addEventListener("message", async (msg) => {
if (msg.origin === "better-xcloud" || typeof msg.data !== "string") return; if (msg.origin === "better-xcloud" || typeof msg.data !== "string") return;
if (msg.data.includes("/titleinfo")) { if (!msg.data.includes("/titleinfo")) return;
let json = JSON.parse(JSON.parse(msg.data).content), xboxTitleId = parseInt(json.titleid, 16); let json = JSON.parse(JSON.parse(msg.data).content), xboxTitleId = parseInt(json.titleid, 16);
if (STATES.currentStream.xboxTitleId = xboxTitleId, STATES.remotePlay.isPlaying) { if (STATES.currentStream.xboxTitleId = xboxTitleId, STATES.remotePlay.isPlaying) {
if (STATES.currentStream.titleSlug = "remote-play", json.focused) { if (STATES.currentStream.titleSlug = "remote-play", json.focused) {
let productTitle = await XboxApi.getProductTitle(xboxTitleId); let productTitle = await XboxApi.getProductTitle(xboxTitleId);
if (productTitle) STATES.currentStream.titleSlug = productTitleToSlug(productTitle); if (productTitle) STATES.currentStream.titleSlug = productTitleToSlug(productTitle);
}
} }
} }
}); });

View File

@ -143,7 +143,7 @@ function deepClone(obj) {
} }
var BxEvent; var BxEvent;
((BxEvent) => { ((BxEvent) => {
BxEvent.JUMP_BACK_IN_READY = "bx-jump-back-in-ready", BxEvent.POPSTATE = "bx-popstate", BxEvent.STREAM_SESSION_READY = "bx-stream-session-ready", BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED = "bx-custom-touch-layouts-loaded", BxEvent.TOUCH_LAYOUT_MANAGER_READY = "bx-touch-layout-manager-ready", BxEvent.REMOTE_PLAY_READY = "bx-remote-play-ready", BxEvent.REMOTE_PLAY_FAILED = "bx-remote-play-failed", BxEvent.DATA_CHANNEL_CREATED = "bx-data-channel-created", BxEvent.GAME_BAR_ACTION_ACTIVATED = "bx-game-bar-action-activated", BxEvent.MICROPHONE_STATE_CHANGED = "bx-microphone-state-changed", BxEvent.SPEAKER_STATE_CHANGED = "bx-speaker-state-changed", BxEvent.VIDEO_VISIBILITY_CHANGED = "bx-video-visibility-changed", BxEvent.CAPTURE_SCREENSHOT = "bx-capture-screenshot", BxEvent.POINTER_LOCK_REQUESTED = "bx-pointer-lock-requested", BxEvent.POINTER_LOCK_EXITED = "bx-pointer-lock-exited", BxEvent.NAVIGATION_FOCUS_CHANGED = "bx-nav-focus-changed", BxEvent.XCLOUD_DIALOG_SHOWN = "bx-xcloud-dialog-shown", BxEvent.XCLOUD_DIALOG_DISMISSED = "bx-xcloud-dialog-dismissed", BxEvent.XCLOUD_GUIDE_MENU_SHOWN = "bx-xcloud-guide-menu-shown", BxEvent.XCLOUD_POLLING_MODE_CHANGED = "bx-xcloud-polling-mode-changed", BxEvent.XCLOUD_RENDERING_COMPONENT = "bx-xcloud-rendering-component", BxEvent.XCLOUD_ROUTER_HISTORY_READY = "bx-xcloud-router-history-ready"; BxEvent.JUMP_BACK_IN_READY = "bx-jump-back-in-ready", BxEvent.POPSTATE = "bx-popstate", BxEvent.STREAM_SESSION_READY = "bx-stream-session-ready", BxEvent.CUSTOM_TOUCH_LAYOUTS_LOADED = "bx-custom-touch-layouts-loaded", BxEvent.TOUCH_LAYOUT_MANAGER_READY = "bx-touch-layout-manager-ready", BxEvent.REMOTE_PLAY_READY = "bx-remote-play-ready", BxEvent.REMOTE_PLAY_FAILED = "bx-remote-play-failed", BxEvent.GAME_BAR_ACTION_ACTIVATED = "bx-game-bar-action-activated", BxEvent.MICROPHONE_STATE_CHANGED = "bx-microphone-state-changed", BxEvent.SPEAKER_STATE_CHANGED = "bx-speaker-state-changed", BxEvent.VIDEO_VISIBILITY_CHANGED = "bx-video-visibility-changed", BxEvent.CAPTURE_SCREENSHOT = "bx-capture-screenshot", BxEvent.POINTER_LOCK_REQUESTED = "bx-pointer-lock-requested", BxEvent.POINTER_LOCK_EXITED = "bx-pointer-lock-exited", BxEvent.NAVIGATION_FOCUS_CHANGED = "bx-nav-focus-changed", BxEvent.XCLOUD_DIALOG_SHOWN = "bx-xcloud-dialog-shown", BxEvent.XCLOUD_DIALOG_DISMISSED = "bx-xcloud-dialog-dismissed", BxEvent.XCLOUD_GUIDE_MENU_SHOWN = "bx-xcloud-guide-menu-shown", BxEvent.XCLOUD_POLLING_MODE_CHANGED = "bx-xcloud-polling-mode-changed", BxEvent.XCLOUD_RENDERING_COMPONENT = "bx-xcloud-rendering-component", BxEvent.XCLOUD_ROUTER_HISTORY_READY = "bx-xcloud-router-history-ready";
function dispatch(target, eventName, data) { function dispatch(target, eventName, data) {
if (!target) return; if (!target) return;
if (!eventName) { if (!eventName) {
@ -236,7 +236,9 @@ class GhPagesUtils {
static getNativeMkbCustomList(update = !1) { static getNativeMkbCustomList(update = !1) {
let key = "BetterXcloud.GhPages.ForceNativeMkb"; let key = "BetterXcloud.GhPages.ForceNativeMkb";
update && NATIVE_FETCH(GhPagesUtils.getUrl("native-mkb/ids.json")).then((response) => response.json()).then((json) => { update && NATIVE_FETCH(GhPagesUtils.getUrl("native-mkb/ids.json")).then((response) => response.json()).then((json) => {
if (json.$schemaVersion === 1) window.localStorage.setItem(key, JSON.stringify(json)), BxEventBus.Script.emit("listForcedNativeMkbUpdated", {}); if (json.$schemaVersion === 1) window.localStorage.setItem(key, JSON.stringify(json)), BxEventBus.Script.emit("listForcedNativeMkbUpdated", {
data: json
});
}); });
let info = JSON.parse(window.localStorage.getItem(key) || "{}"); let info = JSON.parse(window.localStorage.getItem(key) || "{}");
if (info.$schemaVersion !== 1) return window.localStorage.removeItem(key), {}; if (info.$schemaVersion !== 1) return window.localStorage.removeItem(key), {};
@ -1615,8 +1617,8 @@ class GlobalSettingsStorage extends BaseSettingsStore {
default: [], default: [],
unsupported: !AppInterface && UserAgent.isMobile(), unsupported: !AppInterface && UserAgent.isMobile(),
ready: (setting) => { ready: (setting) => {
if (!setting.unsupported) setting.multipleOptions = GhPagesUtils.getNativeMkbCustomList(!0), BxEventBus.Script.on("listForcedNativeMkbUpdated", () => { if (!setting.unsupported) setting.multipleOptions = GhPagesUtils.getNativeMkbCustomList(!0), BxEventBus.Script.on("listForcedNativeMkbUpdated", (payload) => {
setting.multipleOptions = GhPagesUtils.getNativeMkbCustomList(); setting.multipleOptions = payload.data.data;
}); });
}, },
params: { params: {
@ -3720,9 +3722,9 @@ class TouchController {
let $style = document.createElement("style"); let $style = document.createElement("style");
document.documentElement.appendChild($style), TouchController.#$style = $style; document.documentElement.appendChild($style), TouchController.#$style = $style;
let PREF_STYLE_STANDARD = getPref("touchController.style.standard"), PREF_STYLE_CUSTOM = getPref("touchController.style.custom"); let PREF_STYLE_STANDARD = getPref("touchController.style.standard"), PREF_STYLE_CUSTOM = getPref("touchController.style.custom");
window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, (e) => { BxEventBus.Stream.on("dataChannelCreated", (payload) => {
let dataChannel = e.dataChannel; let { dataChannel } = payload;
if (!dataChannel || dataChannel.label !== "message") return; if (dataChannel?.label !== "message") return;
let filter = ""; let filter = "";
if (TouchController.#enabled) { if (TouchController.#enabled) {
if (PREF_STYLE_STANDARD === "white") filter = "grayscale(1) brightness(2)"; if (PREF_STYLE_STANDARD === "white") filter = "grayscale(1) brightness(2)";
@ -3747,8 +3749,8 @@ class TouchController {
if (focused = json.focused, !json.focused) TouchController.#show(); if (focused = json.focused, !json.focused) TouchController.#show();
TouchController.setXboxTitleId(parseInt(json.titleid, 16).toString()); TouchController.setXboxTitleId(parseInt(json.titleid, 16).toString());
} }
} catch (e2) { } catch (e) {
BxLogger.error(LOG_TAG, "Load custom layout", e2); BxLogger.error(LOG_TAG, "Load custom layout", e);
} }
}); });
}); });
@ -8466,9 +8468,7 @@ function patchRtcPeerConnection() {
let nativeCreateDataChannel = RTCPeerConnection.prototype.createDataChannel; let nativeCreateDataChannel = RTCPeerConnection.prototype.createDataChannel;
RTCPeerConnection.prototype.createDataChannel = function() { RTCPeerConnection.prototype.createDataChannel = function() {
let dataChannel = nativeCreateDataChannel.apply(this, arguments); let dataChannel = nativeCreateDataChannel.apply(this, arguments);
return BxEvent.dispatch(window, BxEvent.DATA_CHANNEL_CREATED, { return BxEventBus.Stream.emit("dataChannelCreated", { dataChannel }), dataChannel;
dataChannel
}), dataChannel;
}; };
let maxVideoBitrateDef = getPrefDefinition("stream.video.maxBitrate"), maxVideoBitrate = getPref("stream.video.maxBitrate"), codec = getPref("stream.video.codecProfile"); let maxVideoBitrateDef = getPrefDefinition("stream.video.maxBitrate"), maxVideoBitrate = getPref("stream.video.maxBitrate"), codec = getPref("stream.video.codecProfile");
if (codec !== "default" || maxVideoBitrate < maxVideoBitrateDef.max) { if (codec !== "default" || maxVideoBitrate < maxVideoBitrateDef.max) {
@ -9129,8 +9129,8 @@ class DeviceVibrationManager {
dataChannel = null; dataChannel = null;
boundOnMessage; boundOnMessage;
constructor() { constructor() {
this.boundOnMessage = this.onMessage.bind(this), window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, (e) => { this.boundOnMessage = this.onMessage.bind(this), BxEventBus.Stream.on("dataChannelCreated", (payload) => {
let dataChannel = e.dataChannel; let { dataChannel } = payload;
if (dataChannel?.label === "input") this.reset(), this.dataChannel = dataChannel, this.setupDataChannel(); if (dataChannel?.label === "input") this.reset(), this.dataChannel = dataChannel, this.setupDataChannel();
}), BxEventBus.Script.on("deviceVibrationUpdated", () => this.setupDataChannel()); }), BxEventBus.Script.on("deviceVibrationUpdated", () => this.setupDataChannel());
} }
@ -9257,18 +9257,17 @@ BxEventBus.Stream.on("stateError", () => {
window.addEventListener(BxEvent.XCLOUD_RENDERING_COMPONENT, (e) => { window.addEventListener(BxEvent.XCLOUD_RENDERING_COMPONENT, (e) => {
if (e.component === "product-detail") ProductDetailsPage.injectButtons(); if (e.component === "product-detail") ProductDetailsPage.injectButtons();
}); });
window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, (e) => { BxEventBus.Stream.on("dataChannelCreated", (payload) => {
let dataChannel = e.dataChannel; let { dataChannel } = payload;
if (!dataChannel || dataChannel.label !== "message") return; if (dataChannel?.label !== "message") return;
dataChannel.addEventListener("message", async (msg) => { dataChannel.addEventListener("message", async (msg) => {
if (msg.origin === "better-xcloud" || typeof msg.data !== "string") return; if (msg.origin === "better-xcloud" || typeof msg.data !== "string") return;
if (msg.data.includes("/titleinfo")) { if (!msg.data.includes("/titleinfo")) return;
let json = JSON.parse(JSON.parse(msg.data).content), xboxTitleId = parseInt(json.titleid, 16); let json = JSON.parse(JSON.parse(msg.data).content), xboxTitleId = parseInt(json.titleid, 16);
if (STATES.currentStream.xboxTitleId = xboxTitleId, STATES.remotePlay.isPlaying) { if (STATES.currentStream.xboxTitleId = xboxTitleId, STATES.remotePlay.isPlaying) {
if (STATES.currentStream.titleSlug = "remote-play", json.focused) { if (STATES.currentStream.titleSlug = "remote-play", json.focused) {
let productTitle = await XboxApi.getProductTitle(xboxTitleId); let productTitle = await XboxApi.getProductTitle(xboxTitleId);
if (productTitle) STATES.currentStream.titleSlug = productTitleToSlug(productTitle); if (productTitle) STATES.currentStream.titleSlug = productTitleToSlug(productTitle);
}
} }
} }
}); });

View File

@ -277,9 +277,9 @@ isFullVersion() && window.addEventListener(BxEvent.XCLOUD_RENDERING_COMPONENT, e
}); });
// Detect game change // Detect game change
window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, e => { BxEventBus.Stream.on('dataChannelCreated', payload => {
const dataChannel = (e as any).dataChannel; const { dataChannel } = payload;
if (!dataChannel || dataChannel.label !== 'message') { if (dataChannel?.label !== 'message') {
return; return;
} }
@ -288,26 +288,29 @@ window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, e => {
return; return;
} }
// Get xboxTitleId from message if (!msg.data.includes('/titleinfo')) {
if (msg.data.includes('/titleinfo')) { return;
const json = JSON.parse(JSON.parse(msg.data).content); }
const xboxTitleId = parseInt(json.titleid, 16);
STATES.currentStream.xboxTitleId = xboxTitleId;
// Get titleSlug for Remote Play // Get xboxTitleId from message
if (STATES.remotePlay.isPlaying) { const json = JSON.parse(JSON.parse(msg.data).content);
STATES.currentStream.titleSlug = 'remote-play'; const xboxTitleId = parseInt(json.titleid, 16);
if (json.focused) { STATES.currentStream.xboxTitleId = xboxTitleId;
const productTitle = await XboxApi.getProductTitle(xboxTitleId);
if (productTitle) { // Get titleSlug for Remote Play
STATES.currentStream.titleSlug = productTitleToSlug(productTitle); if (STATES.remotePlay.isPlaying) {
} STATES.currentStream.titleSlug = 'remote-play';
if (json.focused) {
const productTitle = await XboxApi.getProductTitle(xboxTitleId);
if (productTitle) {
STATES.currentStream.titleSlug = productTitleToSlug(productTitle);
} }
} }
} }
}); });
}); });
function unload() { function unload() {
if (!STATES.isPlaying) { if (!STATES.isPlaying) {
return; return;

View File

@ -1,5 +1,4 @@
import { AppInterface, STATES } from "@utils/global"; import { AppInterface, STATES } from "@utils/global";
import { BxEvent } from "@utils/bx-event";
import { StreamSettings } from "@/utils/stream-settings"; import { StreamSettings } from "@/utils/stream-settings";
import { BxEventBus } from "@/utils/bx-event-bus"; import { BxEventBus } from "@/utils/bx-event-bus";
@ -38,8 +37,8 @@ export class DeviceVibrationManager {
constructor() { constructor() {
this.boundOnMessage = this.onMessage.bind(this); this.boundOnMessage = this.onMessage.bind(this);
window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, e => { BxEventBus.Stream.on('dataChannelCreated', payload => {
const dataChannel = (e as any).dataChannel as RTCDataChannel; const { dataChannel } = payload;
if (dataChannel?.label === 'input') { if (dataChannel?.label === 'input') {
this.reset(); this.reset();

View File

@ -8,6 +8,7 @@ import { PrefKey } from "@/enums/pref-keys";
import { getPref } from "@/utils/settings-storages/global-settings-storage"; import { getPref } from "@/utils/settings-storages/global-settings-storage";
import { TouchControllerStyleCustom, TouchControllerStyleStandard } from "@/enums/pref-values"; import { TouchControllerStyleCustom, TouchControllerStyleStandard } from "@/enums/pref-values";
import { GhPagesUtils } from "@/utils/gh-pages"; import { GhPagesUtils } from "@/utils/gh-pages";
import { BxEventBus } from "@/utils/bx-event-bus";
const LOG_TAG = 'TouchController'; const LOG_TAG = 'TouchController';
@ -291,9 +292,9 @@ export class TouchController {
const PREF_STYLE_STANDARD = getPref<TouchControllerStyleStandard>(PrefKey.TOUCH_CONTROLLER_STYLE_STANDARD); const PREF_STYLE_STANDARD = getPref<TouchControllerStyleStandard>(PrefKey.TOUCH_CONTROLLER_STYLE_STANDARD);
const PREF_STYLE_CUSTOM = getPref<TouchControllerStyleCustom>(PrefKey.TOUCH_CONTROLLER_STYLE_CUSTOM); const PREF_STYLE_CUSTOM = getPref<TouchControllerStyleCustom>(PrefKey.TOUCH_CONTROLLER_STYLE_CUSTOM);
window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, e => { BxEventBus.Stream.on('dataChannelCreated', payload => {
const dataChannel = (e as any).dataChannel; const { dataChannel } = payload;
if (!dataChannel || dataChannel.label !== 'message') { if (dataChannel?.label !== 'message') {
return; return;
} }

View File

@ -20,7 +20,11 @@ type ScriptEvents = {
deviceVibrationUpdated: {}; deviceVibrationUpdated: {};
// GH pages // GH pages
listForcedNativeMkbUpdated: {}; listForcedNativeMkbUpdated: {
data: {
data: any;
};
};
}; };
type StreamEvents = { type StreamEvents = {
@ -29,6 +33,8 @@ type StreamEvents = {
statePlaying: { $video?: HTMLVideoElement }; statePlaying: { $video?: HTMLVideoElement };
stateStopped: {}; stateStopped: {};
stateError: {}; stateError: {};
dataChannelCreated: { dataChannel: RTCDataChannel };
}; };
export class BxEventBus<TEvents extends Record<string, any>> { 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_READY = 'bx-remote-play-ready';
export const REMOTE_PLAY_FAILED = 'bx-remote-play-failed'; 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 GAME_BAR_ACTION_ACTIVATED = 'bx-game-bar-action-activated';
export const MICROPHONE_STATE_CHANGED = 'bx-microphone-state-changed'; export const MICROPHONE_STATE_CHANGED = 'bx-microphone-state-changed';
export const SPEAKER_STATE_CHANGED = 'bx-speaker-state-changed'; export const SPEAKER_STATE_CHANGED = 'bx-speaker-state-changed';

View File

@ -53,7 +53,9 @@ export class GhPagesUtils {
if (json.$schemaVersion === supportedSchema) { if (json.$schemaVersion === supportedSchema) {
// Save to storage // Save to storage
window.localStorage.setItem(key, JSON.stringify(json)); 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 // @ts-ignore
const dataChannel = nativeCreateDataChannel.apply(this, arguments); const dataChannel = nativeCreateDataChannel.apply(this, arguments);
BxEvent.dispatch(window, BxEvent.DATA_CHANNEL_CREATED, { BxEventBus.Stream.emit('dataChannelCreated', { dataChannel });
dataChannel: dataChannel,
});
return dataChannel; return dataChannel;
} }

View File

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