mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-06-06 15:47:18 +02:00
Migrate to EventBus
This commit is contained in:
parent
e1ba2344b7
commit
b11d465804
23
dist/better-xcloud.lite.user.js
vendored
23
dist/better-xcloud.lite.user.js
vendored
@ -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,12 +6443,12 @@ 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) {
|
||||||
@ -6456,7 +6456,6 @@ window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, (e) => {
|
|||||||
if (productTitle) STATES.currentStream.titleSlug = productTitleToSlug(productTitle);
|
if (productTitle) STATES.currentStream.titleSlug = productTitleToSlug(productTitle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
function unload() {
|
function unload() {
|
||||||
|
37
dist/better-xcloud.user.js
vendored
37
dist/better-xcloud.user.js
vendored
@ -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,12 +9257,12 @@ 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) {
|
||||||
@ -9270,7 +9270,6 @@ window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, (e) => {
|
|||||||
if (productTitle) STATES.currentStream.titleSlug = productTitleToSlug(productTitle);
|
if (productTitle) STATES.currentStream.titleSlug = productTitleToSlug(productTitle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
function unload() {
|
function unload() {
|
||||||
|
13
src/index.ts
13
src/index.ts
@ -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,8 +288,11 @@ window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, e => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!msg.data.includes('/titleinfo')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Get xboxTitleId from message
|
// Get xboxTitleId from message
|
||||||
if (msg.data.includes('/titleinfo')) {
|
|
||||||
const json = JSON.parse(JSON.parse(msg.data).content);
|
const json = JSON.parse(JSON.parse(msg.data).content);
|
||||||
const xboxTitleId = parseInt(json.titleid, 16);
|
const xboxTitleId = parseInt(json.titleid, 16);
|
||||||
STATES.currentStream.xboxTitleId = xboxTitleId;
|
STATES.currentStream.xboxTitleId = xboxTitleId;
|
||||||
@ -304,10 +307,10 @@ window.addEventListener(BxEvent.DATA_CHANNEL_CREATED, e => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
function unload() {
|
function unload() {
|
||||||
if (!STATES.isPlaying) {
|
if (!STATES.isPlaying) {
|
||||||
return;
|
return;
|
||||||
|
@ -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();
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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>> {
|
||||||
|
@ -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';
|
||||||
|
@ -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,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user