declare let ECHotkeys ; import * as audio from "./audio" ; import * as net from "./net" ; import * as util from "./util" ; const ptt = { hotkey : < null | string > null } ; function loadPTT ( ) { configurePTT ( localStorage . getItem ( "ec-ptt" ) ) ; } util . events . addEventListener ( "usermediaready" , loadPTT , { once : true } ) ; function configurePTT ( hotkey ) { ptt . hotkey = hotkey ; document . body . removeEventListener ( "keydown" , pttDown ) ; document . body . removeEventListener ( "keyup" , pttUp ) ; if ( hotkey ) { audio . toggleMute ( false ) ; document . body . addEventListener ( "keydown" , pttDown ) ; document . body . addEventListener ( "keyup" , pttUp ) ; localStorage . setItem ( "ec-ptt" , hotkey ) ; } else { audio . toggleMute ( true ) ; localStorage . removeItem ( "ec-ptt" ) ; } } export function userConfigurePTT ( ) { if ( typeof ECHotkeys === "undefined" ) return ; return ECHotkeys . getUserKey ( ) . then ( function ( key ) { if ( key ) { if ( /^eb:/ . test ( key . key ) ) configurePTT ( key . key ) ; else return userConfigurePTT ( ) ; } else { configurePTT ( null ) ; } } ) . catch ( net . promiseFail ( ) ) ; } function pttDown ( ev ) { if ( ev . key !== ptt . hotkey ) return ; audio . toggleMute ( true ) ; } function pttUp ( ev ) { if ( ev . key !== ptt . hotkey ) return ; audio . toggleMute ( false ) ; }