@@ -330,7 +330,7 @@ class RTCUtils extends Listenable {
330330 * @param {Object } options
331331 * @returns {void }
332332 */
333- init ( options : IInitOptions = { } ) : void {
333+ private _init ( options : IInitOptions = { } ) : void {
334334 if ( typeof options . disableAEC === 'boolean' ) {
335335 disableAEC = options . disableAEC ;
336336 logger . info ( `Disable AEC: ${ disableAEC } ` ) ;
@@ -388,59 +388,6 @@ class RTCUtils extends Listenable {
388388 } ) ;
389389 }
390390
391- /**
392- * Attaches the given media stream to the given element.
393- *
394- * @param {* } element DOM element.
395- * @param {* } stream MediaStream.
396- * @returns Promise<void>
397- */
398- attachMediaStream ( element : Nullable < HTMLMediaElement > , stream : Nullable < MediaStream > ) : Promise < void > {
399- if ( element ) {
400- element . srcObject = stream ;
401- }
402-
403- if ( element && stream
404- && this . isDeviceChangeAvailable ( 'output' )
405- && stream . getAudioTracks ( ) . length
406-
407- // we skip setting audio output if there was no explicit change
408- && audioOutputChanged ) {
409- return ( element as HTMLAudioElement ) . setSinkId ( this . getAudioOutputDevice ( ) ) . catch ( ( ex : Error ) => {
410- const err
411- = new JitsiTrackError ( ex , null , [ 'audiooutput' ] ) ;
412-
413- logger . warn (
414- 'Failed to set audio output device for the element.'
415- + ' Default audio output device will be used'
416- + ' instead' ,
417- element ?. id ,
418- err ) ;
419-
420- throw err ;
421- } ) ;
422- }
423-
424- return Promise . resolve ( ) ;
425- }
426-
427- /**
428- *
429- * @param {Function } callback
430- */
431- enumerateDevices ( callback : ( devices : MediaDeviceInfo [ ] ) => void ) : void {
432- navigator . mediaDevices . enumerateDevices ( )
433- . then ( ( devices : MediaDeviceInfo [ ] ) => {
434- this . _updateKnownDevices ( devices ) ;
435- callback ( devices ) ;
436- } )
437- . catch ( ( error : Error ) => {
438- logger . warn ( `Failed to enumerate devices. ${ error } ` ) ;
439- this . _updateKnownDevices ( [ ] ) ;
440- callback ( [ ] ) ;
441- } ) ;
442- }
443-
444391 /**
445392 * Acquires a media stream via getUserMedia that
446393 * matches the given constraints
@@ -450,7 +397,7 @@ class RTCUtils extends Listenable {
450397 * @param {number } timeout - The timeout in ms for GUM.
451398 * @returns {Promise }
452399 */
453- _getUserMedia ( umDevices : string [ ] , constraints : MediaStreamConstraints = { } , timeout : number = 0 ) : Promise < MediaStream > {
400+ private _getUserMedia ( umDevices : string [ ] , constraints : MediaStreamConstraints = { } , timeout : number = 0 ) : Promise < MediaStream > {
454401 return new Promise ( ( resolve , reject ) => {
455402 let gumTimeout : ReturnType < typeof setTimeout > , timeoutExpired : boolean = false ;
456403
@@ -501,7 +448,7 @@ class RTCUtils extends Listenable {
501448 * contains the acquired display stream. If desktop sharing is not supported
502449 * then a rejected promise will be returned.
503450 */
504- _getDesktopMedia ( options : IDesktopSharingOptions ) : Promise < IDesktopStreamInfo > {
451+ private _getDesktopMedia ( options : IDesktopSharingOptions ) : Promise < IDesktopStreamInfo > {
505452 if ( ! screenObtainer . isSupported ( ) ) {
506453 return Promise . reject ( new Error ( 'Desktop sharing is not supported!' ) ) ;
507454 }
@@ -529,7 +476,7 @@ class RTCUtils extends Listenable {
529476 * @returns {string[] } An array of string with the missing track types. The
530477 * array will be empty if all requestedDevices are found in the stream.
531478 */
532- _getMissingTracks ( requestedDevices : string [ ] = [ ] , stream : MediaStream ) : string [ ] {
479+ private _getMissingTracks ( requestedDevices : string [ ] = [ ] , stream : MediaStream ) : string [ ] {
533480 const missingDevices : string [ ] = [ ] ;
534481
535482 const audioDeviceRequested = requestedDevices . includes ( 'audio' ) ;
@@ -557,7 +504,7 @@ class RTCUtils extends Listenable {
557504 * @param {MediaDeviceInfo[] } devices - list of media devices.
558505 * @emits RTCEvents.DEVICE_LIST_CHANGED
559506 */
560- _onMediaDevicesListChanged ( devicesReceived : MediaDeviceInfo [ ] ) : void {
507+ private _onMediaDevicesListChanged ( devicesReceived : MediaDeviceInfo [ ] ) : void {
561508 availableDevices = devicesReceived . slice ( 0 ) ;
562509 logger . info ( 'list of media devices has changed:' , availableDevices ) ;
563510
@@ -581,7 +528,7 @@ class RTCUtils extends Listenable {
581528 * This prevents duplication and works around a chrome bug (verified to occur on 68) where devicechange
582529 * fires twice in a row, which can cause async post devicechange processing to collide.
583530 */
584- _updateKnownDevices ( pds : MediaDeviceInfo [ ] ) : void {
531+ private _updateKnownDevices ( pds : MediaDeviceInfo [ ] ) : void {
585532 if ( compareAvailableMediaDevices ( pds ) ) {
586533 this . _onMediaDevicesListChanged ( pds ) ;
587534 }
@@ -593,7 +540,7 @@ class RTCUtils extends Listenable {
593540 * @param um the options we requested to getUserMedia.
594541 * @param stream the stream we received from calling getUserMedia.
595542 */
596- _updateGrantedPermissions ( um : string [ ] , stream : MediaStream ) : void {
543+ private _updateGrantedPermissions ( um : string [ ] , stream : MediaStream ) : void {
597544 const audioTracksReceived : boolean
598545 = Boolean ( stream ) && stream ! . getAudioTracks ( ) . length > 0 ;
599546 const videoTracksReceived : boolean
@@ -610,6 +557,59 @@ class RTCUtils extends Listenable {
610557 this . eventEmitter . emit ( RTCEvents . PERMISSIONS_CHANGED , grantedPermissions ) ;
611558 }
612559
560+ /**
561+ * Attaches the given media stream to the given element.
562+ *
563+ * @param {* } element DOM element.
564+ * @param {* } stream MediaStream.
565+ * @returns Promise<void>
566+ */
567+ public attachMediaStream ( element : Nullable < HTMLMediaElement > , stream : Nullable < MediaStream > ) : Promise < void > {
568+ if ( element ) {
569+ element . srcObject = stream ;
570+ }
571+
572+ if ( element && stream
573+ && this . isDeviceChangeAvailable ( 'output' )
574+ && stream . getAudioTracks ( ) . length
575+
576+ // we skip setting audio output if there was no explicit change
577+ && audioOutputChanged ) {
578+ return ( element as HTMLAudioElement ) . setSinkId ( this . getAudioOutputDevice ( ) ) . catch ( ( ex : Error ) => {
579+ const err
580+ = new JitsiTrackError ( ex , null , [ 'audiooutput' ] ) ;
581+
582+ logger . warn (
583+ 'Failed to set audio output device for the element.'
584+ + ' Default audio output device will be used'
585+ + ' instead' ,
586+ element ?. id ,
587+ err ) ;
588+
589+ throw err ;
590+ } ) ;
591+ }
592+
593+ return Promise . resolve ( ) ;
594+ }
595+
596+ /**
597+ *
598+ * @param {Function } callback
599+ */
600+ public enumerateDevices ( callback : ( devices : MediaDeviceInfo [ ] ) => void ) : void {
601+ navigator . mediaDevices . enumerateDevices ( )
602+ . then ( ( devices : MediaDeviceInfo [ ] ) => {
603+ this . _updateKnownDevices ( devices ) ;
604+ callback ( devices ) ;
605+ } )
606+ . catch ( ( error : Error ) => {
607+ logger . warn ( `Failed to enumerate devices. ${ error } ` ) ;
608+ this . _updateKnownDevices ( [ ] ) ;
609+ callback ( [ ] ) ;
610+ } ) ;
611+ }
612+
613613 /**
614614 * Gets streams from specified device types. This function intentionally
615615 * ignores errors for upstream to catch and handle instead.
@@ -636,7 +636,7 @@ class RTCUtils extends Listenable {
636636 * track. If an error occurs, it will be deferred to the caller for
637637 * handling.
638638 */
639- obtainAudioAndVideoPermissions ( options : IObtainAudioAndVideoOptions ) : Promise < IStreamInfo [ ] > {
639+ public obtainAudioAndVideoPermissions ( options : IObtainAudioAndVideoOptions ) : Promise < IStreamInfo [ ] > {
640640 const {
641641 timeout,
642642 ...otherOptions
@@ -839,7 +839,7 @@ class RTCUtils extends Listenable {
839839 * undefined or 'input', 'output' - for audio output device change.
840840 * @returns {boolean } true if available, false otherwise.
841841 */
842- isDeviceChangeAvailable ( deviceType ?: string ) : boolean {
842+ public isDeviceChangeAvailable ( deviceType ?: string ) : boolean {
843843 if ( deviceType === 'output' || deviceType === 'audiooutput' ) {
844844 return isAudioOutputDeviceChangeAvailable ;
845845 }
@@ -852,7 +852,7 @@ class RTCUtils extends Listenable {
852852 * One point to handle the differences in various implementations.
853853 * @param mediaStream MediaStream object to stop.
854854 */
855- stopMediaStream ( mediaStream : MediaStream ) : void {
855+ public stopMediaStream ( mediaStream : MediaStream ) : void {
856856 if ( ! mediaStream ) {
857857 return ;
858858 }
@@ -880,7 +880,7 @@ class RTCUtils extends Listenable {
880880 * Returns whether the desktop sharing is enabled or not.
881881 * @returns {boolean }
882882 */
883- isDesktopSharingEnabled ( ) : boolean {
883+ public isDesktopSharingEnabled ( ) : boolean {
884884 return screenObtainer . isSupported ( ) ;
885885 }
886886
@@ -892,7 +892,7 @@ class RTCUtils extends Listenable {
892892 * @returns {Promise } - resolves when audio output is changed, is rejected
893893 * otherwise
894894 */
895- setAudioOutputDevice ( deviceId : string ) : Promise < void > {
895+ public setAudioOutputDevice ( deviceId : string ) : Promise < void > {
896896 if ( ! this . isDeviceChangeAvailable ( 'output' ) ) {
897897 return Promise . reject (
898898 new Error ( 'Audio output device change is not supported' ) ) ;
@@ -916,7 +916,7 @@ class RTCUtils extends Listenable {
916916 * @param {number } maxFps - max fps to be used as the capture frame rate.
917917 * @returns {void }
918918 */
919- setDesktopSharingFrameRate ( maxFps : number ) : void {
919+ public setDesktopSharingFrameRate ( maxFps : number ) : void {
920920 screenObtainer . setDesktopSharingFrameRate ( maxFps ) ;
921921 }
922922
@@ -925,7 +925,7 @@ class RTCUtils extends Listenable {
925925 * device
926926 * @returns {string }
927927 */
928- getAudioOutputDevice ( ) : string {
928+ public getAudioOutputDevice ( ) : string {
929929 return audioOutputDeviceId ;
930930 }
931931
@@ -934,15 +934,15 @@ class RTCUtils extends Listenable {
934934 * empty array is returned/
935935 * @returns {Array } list of available media devices.
936936 */
937- getCurrentlyAvailableMediaDevices ( ) : MediaDeviceInfo [ ] {
937+ public getCurrentlyAvailableMediaDevices ( ) : MediaDeviceInfo [ ] {
938938 return availableDevices ;
939939 }
940940
941941 /**
942942 * Returns event data for device to be reported to stats.
943943 * @returns {MediaDeviceInfo } device.
944944 */
945- getEventDataForActiveDevice ( device : MediaDeviceInfo ) : { deviceList : MediaDeviceInfo [ ] ; } {
945+ public getEventDataForActiveDevice ( device : MediaDeviceInfo ) : { deviceList : MediaDeviceInfo [ ] ; } {
946946 const deviceList : MediaDeviceInfo [ ] = [ ] ;
947947 const deviceData = {
948948 deviceId : device . deviceId ,
@@ -968,7 +968,7 @@ class RTCUtils extends Listenable {
968968 * @param {string } streamId The id of WebRTC MediaStream.
969969 * @returns {boolean }
970970 */
971- isUserStreamById ( streamId : string ) : boolean {
971+ public isUserStreamById ( streamId : string ) : boolean {
972972 return Boolean ( streamId ) && streamId !== 'mixedmslabel' && streamId !== 'default' ;
973973 }
974974}
0 commit comments