mirror of
https://github.com/redphx/better-xcloud.git
synced 2025-08-01 10:56:42 +02:00
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import { BxEvent } from "@utils/bx-event";
|
|
import { BxIcon } from "@utils/bx-icon";
|
|
import { createButton, ButtonStyle, CE } from "@utils/html";
|
|
import { BaseGameBarAction } from "./action-base";
|
|
import { MicrophoneShortcut, MicrophoneState } from "../shortcuts/shortcut-microphone";
|
|
|
|
|
|
export class MicrophoneAction extends BaseGameBarAction {
|
|
$content: HTMLElement;
|
|
|
|
constructor() {
|
|
super();
|
|
|
|
const $btnDefault = createButton({
|
|
style: ButtonStyle.GHOST,
|
|
icon: BxIcon.MICROPHONE,
|
|
onClick: this.onClick.bind(this),
|
|
classes: ['bx-activated'],
|
|
});
|
|
|
|
const $btnMuted = createButton({
|
|
style: ButtonStyle.GHOST,
|
|
icon: BxIcon.MICROPHONE_MUTED,
|
|
onClick: this.onClick.bind(this),
|
|
});
|
|
|
|
this.$content = CE('div', {}, $btnMuted, $btnDefault);
|
|
|
|
window.addEventListener(BxEvent.MICROPHONE_STATE_CHANGED, e => {
|
|
const microphoneState = (e as any).microphoneState;
|
|
const enabled = microphoneState === MicrophoneState.ENABLED;
|
|
this.$content.dataset.activated = enabled.toString();
|
|
|
|
// Show the button in Game Bar if the mic is enabled
|
|
this.$content.classList.remove('bx-gone');
|
|
});
|
|
}
|
|
|
|
onClick(e: Event) {
|
|
super.onClick(e);
|
|
const enabled = MicrophoneShortcut.toggle(false);
|
|
this.$content.dataset.activated = enabled.toString();
|
|
}
|
|
|
|
reset(): void {
|
|
this.$content.classList.add('bx-gone');
|
|
this.$content.dataset.activated = 'false';
|
|
}
|
|
}
|