@@ -5,53 +5,56 @@ import { showPopup } from '@hcengineering/ui'
5
5
import { Track , LocalTrack , LocalAudioTrack , LocalVideoTrack , ParticipantEvent , TrackInvalidError , ScreenShareCaptureOptions , DeviceUnsupportedError , ScreenSharePresets } from 'livekit-client'
6
6
7
7
import { IPCMainExposed } from './types'
8
- import { setMetadata } from '@hcengineering/platform'
9
- import recordPlugin from '@hcengineering/recorder'
10
8
11
- export async function getMediaStream ( opts ?: DisplayMediaStreamOptions ) : Promise < MediaStream > {
12
- if ( opts === undefined ) {
13
- throw new Error ( 'opts must be provided' )
14
- }
15
- const ipcMain = ( window as any ) . electron as IPCMainExposed
16
- const sources = await ipcMain . getScreenSources ( )
17
-
18
- const hasAccess = await ipcMain . getScreenAccess ( )
19
- if ( ! hasAccess ) {
20
- log . error ( 'No screen access granted' )
21
- throw new Error ( 'No screen access granted' )
9
+ export function defineGetDisplayMedia ( ) : void {
10
+ if ( navigator ?. mediaDevices === undefined ) {
11
+ console . warn ( 'mediaDevices API not available' )
12
+ return
22
13
}
23
14
24
15
if ( navigator . mediaDevices . getDisplayMedia === undefined ) {
25
16
throw new DeviceUnsupportedError ( 'getDisplayMedia not supported' )
26
17
}
27
- return await new Promise < MediaStream > ( ( resolve , reject ) => {
28
- showPopup (
29
- love . component . SelectScreenSourcePopup ,
30
- {
31
- sources
32
- } ,
33
- 'top' ,
34
- ( ) => {
35
- reject ( new Error ( 'No source selected' ) )
36
- } ,
37
- ( val ) => {
38
- if ( val != null ) {
39
- opts . video = {
40
- mandatory : {
41
- ...( typeof opts . video === 'boolean' ? { } : opts . video ) ,
42
- chromeMediaSource : 'desktop' ,
43
- chromeMediaSourceId : val
44
- }
45
- } as any
46
- resolve ( window . navigator . mediaDevices . getUserMedia ( opts ) )
47
- }
48
- }
49
- )
50
- } )
51
- }
52
18
53
- export function defineScreenRecorder ( ) : void {
54
- setMetadata ( recordPlugin . metadata . GetCustomMediaStream , getMediaStream )
19
+ navigator . mediaDevices . getDisplayMedia = async ( opts ?: DisplayMediaStreamOptions ) : Promise < MediaStream > => {
20
+ if ( opts === undefined ) {
21
+ throw new Error ( 'opts must be provided' )
22
+ }
23
+
24
+ const ipcMain = ( window as any ) . electron as IPCMainExposed
25
+ const sources = await ipcMain . getScreenSources ( )
26
+
27
+ const hasAccess = await ipcMain . getScreenAccess ( )
28
+ if ( ! hasAccess ) {
29
+ log . error ( 'No screen access granted' )
30
+ throw new Error ( 'No screen access granted' )
31
+ }
32
+
33
+ return await new Promise < MediaStream > ( ( resolve , reject ) => {
34
+ showPopup (
35
+ love . component . SelectScreenSourcePopup ,
36
+ {
37
+ sources
38
+ } ,
39
+ 'top' ,
40
+ ( ) => {
41
+ reject ( new Error ( 'No source selected' ) )
42
+ } ,
43
+ ( val ) => {
44
+ if ( val != null ) {
45
+ opts . video = {
46
+ mandatory : {
47
+ ...( typeof opts . video === 'boolean' ? { } : opts . video ) ,
48
+ chromeMediaSource : 'desktop' ,
49
+ chromeMediaSourceId : val
50
+ }
51
+ } as any
52
+ resolve ( window . navigator . mediaDevices . getUserMedia ( opts ) )
53
+ }
54
+ }
55
+ )
56
+ } )
57
+ }
55
58
}
56
59
57
60
export function defineScreenShare ( ) : void {
0 commit comments