@@ -14,9 +14,17 @@ import TextModal from "../../components/TextModal";
1414import { useSettings } from "../../context/userContext" ;
1515import { getStaticPaths , makeStaticProperties } from "../../lib/get-static" ;
1616import Ipc from "../../lib/ipc" ;
17+ import { DISPLAY_KEY } from "../../common/constans" ;
1718
1819const XCLOUD_PREFIX = "xcloud_" ;
1920
21+ const DEFAULT_OPTIONS = {
22+ sharpness : 5 ,
23+ saturation : 100 ,
24+ contrast : 100 ,
25+ brightness : 100 ,
26+ } ;
27+
2028function format ( source : string , ...args : string [ ] ) : string {
2129 let n = 0
2230 return source . replace ( / % ( s ) / , function ( ) {
@@ -42,6 +50,7 @@ function Stream() {
4250 const [ showTextModal , setShowTextModal ] = useState ( false ) ;
4351 const [ showActionbar , setShowActionbar ] = useState ( false ) ;
4452 const [ volume , setVolume ] = useState ( 1 ) ;
53+ const [ openMicro , setOpenMicro ] = useState ( false ) ;
4554 const [ streamingType , setStreamingType ] = useState ( '' ) ;
4655 const [ consoleId , setConsoleId ] = useState ( '' ) ;
4756 const connectStateRef = useRef ( "" ) ;
@@ -251,6 +260,12 @@ function Stream() {
251260
252261 xPlayer . getEventBus ( ) . on ( "connectionstate" , ( event ) => {
253262 console . log ( "connectionstate changed:" , event ) ;
263+
264+ // Toggle microphone
265+ if ( connectStateRef . current === "connected" && ( event . state === "new" || event . state === "connecting" ) ) {
266+ return ;
267+ }
268+
254269 setConnectState ( event . state ) ;
255270 connectStateRef . current = event . state ;
256271
@@ -284,9 +299,32 @@ function Stream() {
284299 }
285300
286301 // Refresh video player
287- if ( settings . display_options ) {
288- refreshPlayer ( settings . display_options )
289- }
302+ setTimeout ( ( ) => {
303+ const _displayOptions = window . localStorage . getItem ( DISPLAY_KEY ) ;
304+
305+ let displayOptions : any = DEFAULT_OPTIONS ;
306+ if ( _displayOptions ) {
307+ try {
308+ displayOptions = JSON . parse ( _displayOptions ) ;
309+ } catch {
310+ displayOptions = DEFAULT_OPTIONS ;
311+ }
312+ }
313+
314+ const videoStyle = document . getElementById ( "video-css" ) ;
315+ console . log ( 'Refresh video player:' , displayOptions )
316+ const filters = getVideoPlayerFilterStyle ( displayOptions ) ;
317+ let videoCss = "" ;
318+ if ( filters ) {
319+ videoCss += `filter: ${ filters } !important;` ;
320+ }
321+ let css = "" ;
322+ if ( videoCss ) {
323+ css = `#videoHolder video { ${ videoCss } }` ;
324+ }
325+
326+ videoStyle ! . textContent = css ;
327+ } , 1000 ) ;
290328
291329 // const xboxTitleId = window._xboxTitleId || ''
292330 // // inputConfigs
@@ -554,16 +592,23 @@ function Stream() {
554592
555593 setTimeout ( ( ) => {
556594 console . log ( "stopStream:" , sessionId ) ;
595+ const timer = setTimeout ( ( ) => {
596+ setLoading ( false ) ;
597+ router . back ( ) ;
598+ } , 20 * 1000 ) ;
599+
557600 Ipc . send ( "streaming" , "stopStream" , {
558601 sessionId : sessionId ,
559602 } )
560603 . then ( ( result ) => {
561604 console . log ( "Stream stopped:" , result ) ;
605+ clearTimeout ( timer )
562606 setLoading ( false ) ;
563607 router . back ( ) ;
564608 } )
565609 . catch ( ( e ) => {
566610 console . log ( e ) ;
611+ clearTimeout ( timer )
567612 setLoading ( false ) ;
568613 router . back ( ) ;
569614 } ) ;
@@ -591,9 +636,11 @@ function Stream() {
591636 const handleToggleMic = ( ) => {
592637 if ( ! xPlayer ) return
593638 if ( xPlayer . getChannelProcessor ( 'chat' ) . isPaused === true ) {
594- xPlayer . getChannelProcessor ( 'chat' ) . startMic ( )
639+ xPlayer . getChannelProcessor ( 'chat' ) . startMic ( ) ;
640+ setOpenMicro ( true ) ;
595641 } else {
596- xPlayer . getChannelProcessor ( 'chat' ) . stopMic ( )
642+ xPlayer . getChannelProcessor ( 'chat' ) . stopMic ( ) ;
643+ setOpenMicro ( false ) ;
597644 }
598645 } ;
599646
@@ -616,6 +663,7 @@ function Stream() {
616663 < ActionBar
617664 connectState = { connectState }
618665 type = { streamingType }
666+ openMicro = { openMicro }
619667 onDisconnect = { onDisconnect }
620668 onDisconnectPowerOff = { onDisconnectPowerOff }
621669 onTogglePerformance = { ( ) => {
@@ -668,16 +716,16 @@ function Stream() {
668716 showTextModal && (
669717 < TextModal
670718 onClose = { ( ) => {
671- setShowTextModal ( false )
672- xPlayer . setKeyboardInput ( true )
719+ setShowTextModal ( false ) ;
720+ xPlayer . setKeyboardInput ( true ) ;
673721 } }
674722 onConfirm = { value => {
675- let text = value . trim ( )
723+ let text = value . trim ( ) ;
676724 if ( ! text ) return
677725 if ( text . length > 150 ) {
678726 text = text . substring ( 0 , 150 ) ;
679727 }
680- handleSendText ( text )
728+ handleSendText ( text ) ;
681729 } }
682730 />
683731 )
0 commit comments