@@ -6,6 +6,7 @@ import ReactJoyride, { STATUS } from 'react-joyride';
66import { CSSTransition , SwitchTransition } from 'react-transition-group' ;
77import { useMachine } from '@xstate/react' ;
88
9+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' ;
910import GameWidget from './GameWidget' ;
1011import GameContext from './GameContext' ;
1112import InfoWidget from './InfoWidget' ;
@@ -21,6 +22,7 @@ import GamePreview from '../components/Game/GamePreview';
2122import { replayerMachineStates } from '../machines/game' ;
2223import AnimationModal from '../components/AnimationModal' ;
2324import NetworkAlert from './NetworkAlert' ;
25+ import sound from '../lib/sound' ;
2426
2527const steps = [
2628 {
@@ -182,8 +184,10 @@ const RootContainer = ({
182184 setCurrentUser,
183185 gameMachine,
184186 editorMachine,
187+ toggleMuteSound,
185188} ) => {
186189 const [ modalShowing , setModalShowing ] = useState ( false ) ;
190+ const mute = useSelector ( state => state . userSettings . mute ) ;
187191 const [ current , send , service ] = useMachine ( gameMachine , {
188192 devTools : true ,
189193 actions : {
@@ -201,6 +205,23 @@ const RootContainer = ({
201205 // eslint-disable-next-line react-hooks/exhaustive-deps
202206 } , [ ] ) ;
203207
208+ useEffect ( ( ) => {
209+ const muteSound = e => {
210+ if ( ( e . ctrlKey || e . metaKey ) && e . key === 'm' ) {
211+ e . preventDefault ( ) ;
212+ // eslint-disable-next-line no-unused-expressions
213+ mute ? sound . toggle ( ) : sound . toggle ( 0 ) ;
214+ toggleMuteSound ( ) ;
215+ }
216+ } ;
217+
218+ window . addEventListener ( 'keydown' , muteSound ) ;
219+
220+ return ( ) => {
221+ window . removeEventListener ( 'keydown' , muteSound ) ;
222+ } ;
223+ } , [ mute , toggleMuteSound ] ) ;
224+
204225 if ( current . matches ( { game : 'waiting' } ) ) {
205226 const gameUrl = window . location . href ;
206227 return < WaitingOpponentInfo gameUrl = { gameUrl } /> ;
@@ -242,6 +263,12 @@ const RootContainer = ({
242263 < AnimationModal setModalShowing = { setModalShowing } modalShowing = { modalShowing } />
243264 < InfoWidget />
244265 < GameWidget editorMachine = { editorMachine } />
266+ { mute
267+ && (
268+ < div className = "rounded p-2 bg-dark cb-mute-icon" >
269+ < FontAwesomeIcon size = "lg" color = "white" icon = { [ 'fas' , 'volume-mute' ] } />
270+ </ div >
271+ ) }
245272 < FeedBackWidget />
246273 </ div >
247274 </ div >
@@ -265,6 +292,7 @@ const mapDispatchToProps = {
265292 setCurrentUser : actions . setCurrentUser ,
266293 connectToGame : GameActions . connectToGame ,
267294 connectToChat : ChatActions . connectToChat ,
295+ toggleMuteSound : actions . toggleMuteSound ,
268296} ;
269297
270298export default connect ( null , mapDispatchToProps ) ( RootContainer ) ;
0 commit comments