@@ -132,7 +132,7 @@ export class WebCompat extends ContentFeature {
132
132
}
133
133
// if (this.getFeatureSettingEnabled('deviceEnumeration')) {
134
134
this . deviceEnumerationFix ( ) ;
135
- //}
135
+ // }
136
136
}
137
137
138
138
/** Shim Web Share API in Android WebView */
@@ -761,6 +761,9 @@ export class WebCompat extends ContentFeature {
761
761
}
762
762
}
763
763
764
+ /**
765
+ * Prevents device enumeration by returning an empty array when enabled
766
+ */
764
767
preventDeviceEnumeration ( ) {
765
768
if ( ! window . MediaDevices ) {
766
769
return ;
@@ -774,6 +777,9 @@ export class WebCompat extends ContentFeature {
774
777
}
775
778
if ( disableDeviceEnumeration ) {
776
779
const enumerateDevicesProxy = new DDGProxy ( this , MediaDevices . prototype , 'enumerateDevices' , {
780
+ /**
781
+ * @returns {Promise<MediaDeviceInfo[]> }
782
+ */
777
783
apply ( ) {
778
784
return Promise . resolve ( [ ] ) ;
779
785
} ,
@@ -782,49 +788,66 @@ export class WebCompat extends ContentFeature {
782
788
}
783
789
}
784
790
791
+ /**
792
+ * Creates a valid MediaDeviceInfo object with required toJSON method
793
+ * @param {'videoinput' | 'audioinput' | 'audiooutput' } kind - The device kind
794
+ * @returns {MediaDeviceInfo }
795
+ */
796
+ createMediaDeviceInfo ( kind ) {
797
+ return {
798
+ deviceId : 'default' ,
799
+ kind : kind ,
800
+ label : '' ,
801
+ groupId : 'default-group' ,
802
+ toJSON ( ) {
803
+ return {
804
+ deviceId : this . deviceId ,
805
+ kind : this . kind ,
806
+ label : this . label ,
807
+ groupId : this . groupId
808
+ } ;
809
+ }
810
+ } ;
811
+ }
812
+
813
+ /**
814
+ * Fixes device enumeration to handle permission prompts gracefully
815
+ */
785
816
deviceEnumerationFix ( ) {
786
817
if ( ! window . MediaDevices ) {
787
818
return ;
788
819
}
789
820
790
821
const enumerateDevicesProxy = new DDGProxy ( this , MediaDevices . prototype , 'enumerateDevices' , {
822
+ /**
823
+ * @param {MediaDevices['enumerateDevices'] } target
824
+ * @param {MediaDevices } thisArg
825
+ * @param {Parameters<MediaDevices['enumerateDevices']> } args
826
+ * @returns {Promise<MediaDeviceInfo[]> }
827
+ */
791
828
apply : async ( target , thisArg , args ) => {
792
829
try {
793
- debugger ;
794
830
// Request device enumeration information from native
831
+ /** @type {{willPrompt: boolean, videoInput: boolean, audioInput: boolean, audioOutput: boolean} } */
795
832
const response = await this . messaging . request ( MSG_DEVICE_ENUMERATION , { } ) ;
796
833
797
834
// Check if native indicates that prompts would be required
798
835
if ( response . willPrompt ) {
799
836
// If prompts would be required, return a manipulated response
800
837
// that includes the device types that are available
838
+ /** @type {MediaDeviceInfo[] } */
801
839
const devices = [ ] ;
802
840
803
841
if ( response . videoInput ) {
804
- devices . push ( {
805
- deviceId : 'default' ,
806
- kind : 'videoinput' ,
807
- label : '' ,
808
- groupId : 'default-group' ,
809
- } ) ;
842
+ devices . push ( this . createMediaDeviceInfo ( 'videoinput' ) ) ;
810
843
}
811
844
812
845
if ( response . audioInput ) {
813
- devices . push ( {
814
- deviceId : 'default' ,
815
- kind : 'audioinput' ,
816
- label : '' ,
817
- groupId : 'default-group' ,
818
- } ) ;
846
+ devices . push ( this . createMediaDeviceInfo ( 'audioinput' ) ) ;
819
847
}
820
848
821
849
if ( response . audioOutput ) {
822
- devices . push ( {
823
- deviceId : 'default' ,
824
- kind : 'audiooutput' ,
825
- label : '' ,
826
- groupId : 'default-group' ,
827
- } ) ;
850
+ devices . push ( this . createMediaDeviceInfo ( 'audiooutput' ) ) ;
828
851
}
829
852
830
853
return Promise . resolve ( devices ) ;
0 commit comments