Skip to content

Commit

Permalink
feat(mobile): add webrtc permission grant and allow webrtc service wo…
Browse files Browse the repository at this point in the history
…rk correct
  • Loading branch information
moonrailgun committed Dec 6, 2023
1 parent 5d39f92 commit 3de7fe2
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 4 deletions.
4 changes: 4 additions & 0 deletions client/mobile/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 这份不需要,应该是默认都有的。但是保留万一有的手机不行还可以手动添加 -->
<!-- <uses-feature android:name="android.hardware.audio.output" />
<uses-feature android:name="android.hardware.microphone" /> -->

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

<application
android:name=".MainApplication"
Expand Down
1 change: 1 addition & 0 deletions client/mobile/src/AppMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const AppMain: React.FC<Props> = React.memo((props) => {
<WebView
ref={webviewRef}
source={{ uri: props.host }}
mediaPlaybackRequiresUserAction={false}
injectedJavaScriptBeforeContentLoaded={generateInjectedScript()}
onMessage={(e) => {
if (!webviewRef.current) {
Expand Down
22 changes: 22 additions & 0 deletions client/mobile/src/lib/permissions/index.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 4 additions & 0 deletions client/mobile/src/lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ export function urlResolve(...str: string[]) {
});
return normalize(flatten);
}

export function isDev(): boolean {
return !!__DEV__;
}
2 changes: 1 addition & 1 deletion client/mobile/src/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from '../../../packages/types/index';
export * from '../../../packages/types';
6 changes: 6 additions & 0 deletions client/shared/event/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ export interface SharedEventMap {
*/
loadColorScheme: (schemeName: string) => void;

/**
* 请求webrtc相关权限
* 目前用于视频会议
*/
ensureWebRTCPermission: () => void;

/**
* 网络状态更新
*/
Expand Down
1 change: 1 addition & 0 deletions client/web/plugins/com.msgbyte.env.rn/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ regCustomPanel({
});

forwardSharedEvent('loadColorScheme');
forwardSharedEvent('ensureWebRTCPermission');
forwardSharedEvent('loginSuccess', async (payload) => {
let token = window.localStorage.getItem('jsonwebtoken');
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -56,9 +56,13 @@ export const PureLivekitView: React.FC<PureLivekitViewProps> = 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?.();

Expand Down

0 comments on commit 3de7fe2

Please sign in to comment.