diff --git a/client/mobile/android/app/src/main/AndroidManifest.xml b/client/mobile/android/app/src/main/AndroidManifest.xml index d285b06b845..9f2a4d5ed6d 100644 --- a/client/mobile/android/app/src/main/AndroidManifest.xml +++ b/client/mobile/android/app/src/main/AndroidManifest.xml @@ -1,8 +1,12 @@ + + + = React.memo((props) => { { if (!webviewRef.current) { diff --git a/client/mobile/src/lib/permissions/index.ts b/client/mobile/src/lib/permissions/index.ts new file mode 100644 index 00000000000..3123ce9f4d0 --- /dev/null +++ b/client/mobile/src/lib/permissions/index.ts @@ -0,0 +1,22 @@ +import { request, check, PERMISSIONS } from 'react-native-permissions'; +import { Platform } from 'react-native'; + +export async function ensureWebRTCPermission() { + const cameraPermission = + Platform.OS === 'ios' ? PERMISSIONS.IOS.CAMERA : PERMISSIONS.ANDROID.CAMERA; + const microphonePermission = + Platform.OS === 'ios' + ? PERMISSIONS.IOS.MICROPHONE + : PERMISSIONS.ANDROID.RECORD_AUDIO; + + const [cameraPermissionStatus, microphonePermissionStatus] = + await Promise.all([check(cameraPermission), check(microphonePermission)]); + + if (microphonePermissionStatus !== 'granted') { + await request(microphonePermission); + } + + if (cameraPermissionStatus !== 'granted') { + await request(cameraPermission); + } +} diff --git a/client/mobile/src/lib/utils/index.ts b/client/mobile/src/lib/utils/index.ts index 23ce823ece9..a959b3c36f1 100644 --- a/client/mobile/src/lib/utils/index.ts +++ b/client/mobile/src/lib/utils/index.ts @@ -33,3 +33,7 @@ export function urlResolve(...str: string[]) { }); return normalize(flatten); } + +export function isDev(): boolean { + return !!__DEV__; +} diff --git a/client/mobile/src/types.ts b/client/mobile/src/types.ts index d43662e0aed..9a6a67c219d 100644 --- a/client/mobile/src/types.ts +++ b/client/mobile/src/types.ts @@ -1 +1 @@ -export * from '../../../packages/types/index'; +export * from '../../../packages/types'; diff --git a/client/shared/event/index.ts b/client/shared/event/index.ts index 95e2cf8d443..a205079519b 100644 --- a/client/shared/event/index.ts +++ b/client/shared/event/index.ts @@ -23,6 +23,12 @@ export interface SharedEventMap { */ loadColorScheme: (schemeName: string) => void; + /** + * 请求webrtc相关权限 + * 目前用于视频会议 + */ + ensureWebRTCPermission: () => void; + /** * 网络状态更新 */ diff --git a/client/web/plugins/com.msgbyte.env.rn/src/index.tsx b/client/web/plugins/com.msgbyte.env.rn/src/index.tsx index 1a4a5502d64..fa08a133062 100644 --- a/client/web/plugins/com.msgbyte.env.rn/src/index.tsx +++ b/client/web/plugins/com.msgbyte.env.rn/src/index.tsx @@ -23,6 +23,7 @@ regCustomPanel({ }); forwardSharedEvent('loadColorScheme'); +forwardSharedEvent('ensureWebRTCPermission'); forwardSharedEvent('loginSuccess', async (payload) => { let token = window.localStorage.getItem('jsonwebtoken'); try { diff --git a/server/plugins/com.msgbyte.livekit/web/plugins/com.msgbyte.livekit/src/components/LivekitView.tsx b/server/plugins/com.msgbyte.livekit/web/plugins/com.msgbyte.livekit/src/components/LivekitView.tsx index bf3ff3b4b6e..86db624785b 100644 --- a/server/plugins/com.msgbyte.livekit/web/plugins/com.msgbyte.livekit/src/components/LivekitView.tsx +++ b/server/plugins/com.msgbyte.livekit/web/plugins/com.msgbyte.livekit/src/components/LivekitView.tsx @@ -1,6 +1,6 @@ -import { showErrorToasts, useEvent } from '@capital/common'; +import { sharedEvent, showErrorToasts, useEvent } from '@capital/common'; import { withKeepAliveOverlay } from '@capital/component'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import type { LocalUserChoices } from '@livekit/components-react'; import { PreJoinView } from './lib/PreJoinView'; import { LivekitContainer } from './LivekitContainer'; @@ -56,9 +56,13 @@ export const PureLivekitView: React.FC = React.memo( const handleError = useEvent((err: Error) => { showErrorToasts('error while setting up prejoin'); - console.log('error while setting up prejoin', err); + console.error('error while setting up prejoin', err); }); + useEffect(() => { + sharedEvent.emit('ensureWebRTCPermission'); + }, []); + const handleJoin = useEvent(async (userChoices: LocalUserChoices) => { await props.onJoin?.();