@livekit/react-native 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +141 -0
- package/android/build.gradle +133 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +3 -0
- package/android/gradlew +185 -0
- package/android/gradlew.bat +89 -0
- package/android/local.properties +8 -0
- package/android/src/main/AndroidManifest.xml +13 -0
- package/android/src/main/java/com/livekit/reactnative/LivekitReactNativeModule.kt +50 -0
- package/android/src/main/java/com/livekit/reactnative/LivekitReactNativePackage.kt +17 -0
- package/android/src/main/java/com/livekit/reactnative/audio/AudioDeviceKind.java +40 -0
- package/android/src/main/java/com/livekit/reactnative/audio/AudioSwitchManager.java +140 -0
- package/ios/LivekitReactNative-Bridging-Header.h +2 -0
- package/ios/LivekitReactNative.h +11 -0
- package/ios/LivekitReactNative.m +111 -0
- package/ios/LivekitReactNative.xcodeproj/project.pbxproj +274 -0
- package/ios/LivekitReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/LivekitReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/LivekitReactNative.xcodeproj/project.xcworkspace/xcuserdata/davidliu.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/LivekitReactNative.xcodeproj/xcuserdata/davidliu.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/commonjs/audio/AudioSession.js +80 -0
- package/lib/commonjs/audio/AudioSession.js.map +1 -0
- package/lib/commonjs/components/VideoView.js +165 -0
- package/lib/commonjs/components/VideoView.js.map +1 -0
- package/lib/commonjs/components/ViewPortDetector.js +109 -0
- package/lib/commonjs/components/ViewPortDetector.js.map +1 -0
- package/lib/commonjs/index.js +103 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/useParticipant.js +100 -0
- package/lib/commonjs/useParticipant.js.map +1 -0
- package/lib/commonjs/useRoom.js +137 -0
- package/lib/commonjs/useRoom.js.map +1 -0
- package/lib/module/audio/AudioSession.js +70 -0
- package/lib/module/audio/AudioSession.js.map +1 -0
- package/lib/module/components/VideoView.js +144 -0
- package/lib/module/components/VideoView.js.map +1 -0
- package/lib/module/components/ViewPortDetector.js +97 -0
- package/lib/module/components/ViewPortDetector.js.map +1 -0
- package/lib/module/index.js +45 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/useParticipant.js +91 -0
- package/lib/module/useParticipant.js.map +1 -0
- package/lib/module/useRoom.js +126 -0
- package/lib/module/useRoom.js.map +1 -0
- package/lib/typescript/audio/AudioSession.d.ts +88 -0
- package/lib/typescript/components/VideoView.d.ts +10 -0
- package/lib/typescript/components/ViewPortDetector.d.ts +26 -0
- package/lib/typescript/index.d.ts +12 -0
- package/lib/typescript/useParticipant.d.ts +13 -0
- package/lib/typescript/useRoom.d.ts +20 -0
- package/livekit-react-native.podspec +22 -0
- package/package.json +157 -0
- package/src/audio/AudioSession.ts +132 -0
- package/src/components/VideoView.tsx +143 -0
- package/src/components/ViewPortDetector.tsx +93 -0
- package/src/index.tsx +37 -0
- package/src/useParticipant.ts +144 -0
- package/src/useRoom.ts +163 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for the underlying AudioSession.
|
|
3
|
+
*
|
|
4
|
+
* ----
|
|
5
|
+
* Android specific options:
|
|
6
|
+
*
|
|
7
|
+
* * preferredOutputList - The preferred order in which to automatically select an audio output.
|
|
8
|
+
* This is ignored when an output is manually selected with {@link AudioSession.selectAudioOutput}.
|
|
9
|
+
*
|
|
10
|
+
* By default, the order is set to:
|
|
11
|
+
* 1. `"speaker"`
|
|
12
|
+
* 2. `"earpiece"`
|
|
13
|
+
* 3. `"headset"`
|
|
14
|
+
* 4. `"bluetooth"`
|
|
15
|
+
*
|
|
16
|
+
* ----
|
|
17
|
+
* iOS
|
|
18
|
+
*
|
|
19
|
+
* * defaultOutput - The default preferred output to use when a wired headset or bluetooth output is unavailable.
|
|
20
|
+
*
|
|
21
|
+
* By default, this is set to `"speaker"`
|
|
22
|
+
*/
|
|
23
|
+
export declare type AudioConfiguration = {
|
|
24
|
+
android: {
|
|
25
|
+
preferredOutputList: ('speaker' | 'earpiece' | 'headset' | 'bluetooth')[];
|
|
26
|
+
};
|
|
27
|
+
ios: {
|
|
28
|
+
defaultOutput: 'speaker' | 'earpiece';
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export default class AudioSession {
|
|
32
|
+
/**
|
|
33
|
+
* Applies the provided audio configuration to the underlying AudioSession.
|
|
34
|
+
*
|
|
35
|
+
* Must be called prior to connecting to a Room for the configuration to apply correctly.
|
|
36
|
+
*/
|
|
37
|
+
static configureAudio: (config: AudioConfiguration) => Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Starts an AudioSession.
|
|
40
|
+
*/
|
|
41
|
+
static startAudioSession: () => Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Stops the existing AudioSession.
|
|
44
|
+
*/
|
|
45
|
+
static stopAudioSession: () => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Gets the available audio outputs for use with {@link selectAudioOutput}.
|
|
48
|
+
*
|
|
49
|
+
* {@link startAudioSession} must be called prior to using this method.
|
|
50
|
+
*
|
|
51
|
+
* For Android, will return if available:
|
|
52
|
+
* * "speaker"
|
|
53
|
+
* * "earpiece"
|
|
54
|
+
* * "headset"
|
|
55
|
+
* * "bluetooth"
|
|
56
|
+
*
|
|
57
|
+
* Note: For applications targeting SDK versions over 30, the runtime BLUETOOTH_CONNECT
|
|
58
|
+
* permission must be requested to send audio to bluetooth headsets.
|
|
59
|
+
*
|
|
60
|
+
* ----
|
|
61
|
+
*
|
|
62
|
+
* For iOS, due to OS limitations, the only available types are:
|
|
63
|
+
* * "default" - Use default iOS audio routing
|
|
64
|
+
* * "force_speaker" - Force audio output through speaker
|
|
65
|
+
*
|
|
66
|
+
* See also {@link showAudioRoutePicker} to display a route picker that
|
|
67
|
+
* can choose between other audio devices (i.e. headset/bluetooth/airplay),
|
|
68
|
+
* or use a library like `react-native-avroutepicker` for a native platform
|
|
69
|
+
* control.
|
|
70
|
+
*
|
|
71
|
+
* @returns the available audio output types
|
|
72
|
+
*/
|
|
73
|
+
static getAudioOutputs: () => Promise<string[]>;
|
|
74
|
+
/**
|
|
75
|
+
* Select the provided audio output if available.
|
|
76
|
+
*
|
|
77
|
+
* {@link startAudioSession} must be called prior to using this method.
|
|
78
|
+
*
|
|
79
|
+
* @param deviceId A deviceId retrieved from {@link getAudioOutputs}
|
|
80
|
+
*/
|
|
81
|
+
static selectAudioOutput: (deviceId: string) => Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* iOS only, requires iOS 11+.
|
|
84
|
+
*
|
|
85
|
+
* Displays an AVRoutePickerView for the user to choose their audio output.
|
|
86
|
+
*/
|
|
87
|
+
static showAudioRoutePicker: () => Promise<void>;
|
|
88
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ViewStyle } from 'react-native';
|
|
2
|
+
import { VideoTrack } from 'livekit-client';
|
|
3
|
+
export declare type Props = {
|
|
4
|
+
videoTrack?: VideoTrack | undefined;
|
|
5
|
+
style?: ViewStyle;
|
|
6
|
+
objectFit?: 'cover' | 'contain' | undefined;
|
|
7
|
+
mirror?: boolean;
|
|
8
|
+
zOrder?: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const VideoView: ({ style, videoTrack, objectFit, zOrder, mirror, }: Props) => JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
import { ViewStyle } from 'react-native';
|
|
3
|
+
export declare type Props = {
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
style?: ViewStyle;
|
|
6
|
+
onChange?: (isVisible: boolean) => void;
|
|
7
|
+
delay?: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Detects when this is in the viewport and visible.
|
|
11
|
+
*
|
|
12
|
+
* Will not fire visibility changes for zero width/height components.
|
|
13
|
+
*/
|
|
14
|
+
export default class ViewPortDetector extends Component<Props> {
|
|
15
|
+
private lastValue;
|
|
16
|
+
private interval;
|
|
17
|
+
private view;
|
|
18
|
+
constructor(props: Props);
|
|
19
|
+
componentDidMount(): void;
|
|
20
|
+
componentWillUnmount(): void;
|
|
21
|
+
UNSAFE_componentWillReceiveProps(nextProps: Props): void;
|
|
22
|
+
private startWatching;
|
|
23
|
+
private stopWatching;
|
|
24
|
+
private checkInViewPort;
|
|
25
|
+
render(): JSX.Element;
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import AudioSession from './audio/AudioSession';
|
|
2
|
+
import type { AudioConfiguration } from './audio/AudioSession';
|
|
3
|
+
/**
|
|
4
|
+
* Registers the required globals needed for LiveKit to work.
|
|
5
|
+
*
|
|
6
|
+
* Must be called before using LiveKit.
|
|
7
|
+
*/
|
|
8
|
+
export declare function registerGlobals(): void;
|
|
9
|
+
export * from './components/VideoView';
|
|
10
|
+
export * from './useParticipant';
|
|
11
|
+
export * from './useRoom';
|
|
12
|
+
export { AudioSession, AudioConfiguration };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ConnectionQuality, Participant, TrackPublication } from 'livekit-client';
|
|
2
|
+
export interface ParticipantState {
|
|
3
|
+
isSpeaking: boolean;
|
|
4
|
+
connectionQuality: ConnectionQuality;
|
|
5
|
+
isLocal: boolean;
|
|
6
|
+
metadata?: string;
|
|
7
|
+
publications: TrackPublication[];
|
|
8
|
+
subscribedTracks: TrackPublication[];
|
|
9
|
+
cameraPublication?: TrackPublication;
|
|
10
|
+
microphonePublication?: TrackPublication;
|
|
11
|
+
screenSharePublication?: TrackPublication;
|
|
12
|
+
}
|
|
13
|
+
export declare function useParticipant(participant: Participant): ParticipantState;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AudioTrack, LocalParticipant, Participant, Room } from 'livekit-client';
|
|
2
|
+
export interface RoomState {
|
|
3
|
+
room?: Room;
|
|
4
|
+
participants: Participant[];
|
|
5
|
+
audioTracks: AudioTrack[];
|
|
6
|
+
error?: Error;
|
|
7
|
+
}
|
|
8
|
+
export interface RoomOptions {
|
|
9
|
+
sortParticipants?: (participants: Participant[]) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function useRoom(room: Room, options?: RoomOptions): RoomState;
|
|
12
|
+
/**
|
|
13
|
+
* Default sort for participants, it'll order participants by:
|
|
14
|
+
* 1. dominant speaker (speaker with the loudest audio level)
|
|
15
|
+
* 2. local participant
|
|
16
|
+
* 3. other speakers that are recently active
|
|
17
|
+
* 4. participants with video on
|
|
18
|
+
* 5. by joinedAt
|
|
19
|
+
*/
|
|
20
|
+
export declare function sortParticipants(participants: Participant[], localParticipant?: LocalParticipant): void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "livekit-react-native"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => "10.0" }
|
|
14
|
+
s.source = { :git => "https://github.com/livekit/client-sdk-react-native.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm}"
|
|
17
|
+
|
|
18
|
+
s.framework = 'AVFAudio'
|
|
19
|
+
|
|
20
|
+
s.dependency "React-Core"
|
|
21
|
+
s.dependency "react-native-webrtc"
|
|
22
|
+
end
|
package/package.json
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@livekit/react-native",
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "LiveKit for React Native",
|
|
5
|
+
"main": "lib/commonjs/index",
|
|
6
|
+
"module": "lib/module/index",
|
|
7
|
+
"types": "lib/typescript/index.d.ts",
|
|
8
|
+
"react-native": "src/index",
|
|
9
|
+
"source": "src/index",
|
|
10
|
+
"files": [
|
|
11
|
+
"src",
|
|
12
|
+
"lib",
|
|
13
|
+
"android",
|
|
14
|
+
"ios",
|
|
15
|
+
"cpp",
|
|
16
|
+
"livekit-react-native.podspec",
|
|
17
|
+
"!lib/typescript/example",
|
|
18
|
+
"!android/build",
|
|
19
|
+
"!android/.gradle",
|
|
20
|
+
"!android/.idea",
|
|
21
|
+
"!ios/build",
|
|
22
|
+
"!**/__tests__",
|
|
23
|
+
"!**/__fixtures__",
|
|
24
|
+
"!**/__mocks__"
|
|
25
|
+
],
|
|
26
|
+
"repository": "https://github.com/livekit/client-sdk-react-native",
|
|
27
|
+
"author": "LiveKit <dl@livekit.io> (https://livekit.io/)",
|
|
28
|
+
"license": "Apache-2.0",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/livekit/client-sdk-react-native/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/livekit/client-sdk-react-native#readme",
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"registry": "https://registry.npmjs.org/"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"react-native",
|
|
38
|
+
"ios",
|
|
39
|
+
"android"
|
|
40
|
+
],
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"livekit-client": "^1.6.0",
|
|
43
|
+
"promise.allsettled": "^1.0.5",
|
|
44
|
+
"react-native-url-polyfill": "^1.3.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@babel/core": "^7.12.10",
|
|
48
|
+
"@babel/preset-env": "^7.1.6",
|
|
49
|
+
"@babel/runtime": "^7.12.5",
|
|
50
|
+
"@commitlint/config-conventional": "^16.2.1",
|
|
51
|
+
"@react-native-community/eslint-config": "^3.1.0",
|
|
52
|
+
"@release-it/conventional-changelog": "^4.2.0",
|
|
53
|
+
"@types/jest": "^26.0.0",
|
|
54
|
+
"@types/react": "^17.0.0",
|
|
55
|
+
"@types/react-native": "0.66.16",
|
|
56
|
+
"@types/react-native-webrtc": "^1.75.5",
|
|
57
|
+
"commitlint": "^16.2.1",
|
|
58
|
+
"eslint": "^8.23.0",
|
|
59
|
+
"eslint-config-prettier": "^8.5.0",
|
|
60
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
61
|
+
"husky": "^7.0.4",
|
|
62
|
+
"jest": "^27.5.1",
|
|
63
|
+
"pod-install": "^0.1.0",
|
|
64
|
+
"prettier": "^2.5.1",
|
|
65
|
+
"react": "18.0.0",
|
|
66
|
+
"react-native": "0.69.5",
|
|
67
|
+
"react-native-builder-bob": "^0.18.2",
|
|
68
|
+
"release-it": "^14.2.2",
|
|
69
|
+
"typedoc": "^0.23.14",
|
|
70
|
+
"typescript": "^4.8.2"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"react": "*",
|
|
74
|
+
"react-native": "*",
|
|
75
|
+
"react-native-webrtc": "^106.0.0"
|
|
76
|
+
},
|
|
77
|
+
"scripts": {
|
|
78
|
+
"test": "jest",
|
|
79
|
+
"build-docs": "typedoc",
|
|
80
|
+
"typescript": "tsc --noEmit",
|
|
81
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
82
|
+
"prepare": "bob build",
|
|
83
|
+
"release": "release-it",
|
|
84
|
+
"example": "yarn --cwd example",
|
|
85
|
+
"pods": "cd example && pod-install --quiet",
|
|
86
|
+
"bootstrap": "yarn example && yarn && yarn pods"
|
|
87
|
+
},
|
|
88
|
+
"jest": {
|
|
89
|
+
"preset": "react-native",
|
|
90
|
+
"modulePathIgnorePatterns": [
|
|
91
|
+
"<rootDir>/example/node_modules",
|
|
92
|
+
"<rootDir>/lib/"
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
"commitlint": {
|
|
96
|
+
"extends": [
|
|
97
|
+
"@commitlint/config-conventional"
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
"release-it": {
|
|
101
|
+
"git": {
|
|
102
|
+
"commitMessage": "chore: release ${version}",
|
|
103
|
+
"tagName": "v${version}"
|
|
104
|
+
},
|
|
105
|
+
"npm": {
|
|
106
|
+
"publish": true
|
|
107
|
+
},
|
|
108
|
+
"github": {
|
|
109
|
+
"release": true
|
|
110
|
+
},
|
|
111
|
+
"plugins": {
|
|
112
|
+
"@release-it/conventional-changelog": {
|
|
113
|
+
"preset": "angular"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"eslintConfig": {
|
|
118
|
+
"root": true,
|
|
119
|
+
"extends": [
|
|
120
|
+
"@react-native-community",
|
|
121
|
+
"prettier"
|
|
122
|
+
],
|
|
123
|
+
"rules": {
|
|
124
|
+
"prettier/prettier": [
|
|
125
|
+
"error",
|
|
126
|
+
{
|
|
127
|
+
"quoteProps": "consistent",
|
|
128
|
+
"singleQuote": true,
|
|
129
|
+
"tabWidth": 2,
|
|
130
|
+
"trailingComma": "es5",
|
|
131
|
+
"useTabs": false
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
"prettier": {
|
|
137
|
+
"quoteProps": "consistent",
|
|
138
|
+
"singleQuote": true,
|
|
139
|
+
"tabWidth": 2,
|
|
140
|
+
"trailingComma": "es5",
|
|
141
|
+
"useTabs": false
|
|
142
|
+
},
|
|
143
|
+
"react-native-builder-bob": {
|
|
144
|
+
"source": "src",
|
|
145
|
+
"output": "lib",
|
|
146
|
+
"targets": [
|
|
147
|
+
"commonjs",
|
|
148
|
+
"module",
|
|
149
|
+
[
|
|
150
|
+
"typescript",
|
|
151
|
+
{
|
|
152
|
+
"project": "tsconfig.build.json"
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
const LINKING_ERROR =
|
|
3
|
+
`The package 'livekit-react-native' doesn't seem to be linked. Make sure: \n\n` +
|
|
4
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
5
|
+
'- You rebuilt the app after installing the package\n' +
|
|
6
|
+
'- You are not using Expo managed workflow\n';
|
|
7
|
+
|
|
8
|
+
const LivekitReactNative = NativeModules.LivekitReactNative
|
|
9
|
+
? NativeModules.LivekitReactNative
|
|
10
|
+
: new Proxy(
|
|
11
|
+
{},
|
|
12
|
+
{
|
|
13
|
+
get() {
|
|
14
|
+
throw new Error(LINKING_ERROR);
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for the underlying AudioSession.
|
|
21
|
+
*
|
|
22
|
+
* ----
|
|
23
|
+
* Android specific options:
|
|
24
|
+
*
|
|
25
|
+
* * preferredOutputList - The preferred order in which to automatically select an audio output.
|
|
26
|
+
* This is ignored when an output is manually selected with {@link AudioSession.selectAudioOutput}.
|
|
27
|
+
*
|
|
28
|
+
* By default, the order is set to:
|
|
29
|
+
* 1. `"speaker"`
|
|
30
|
+
* 2. `"earpiece"`
|
|
31
|
+
* 3. `"headset"`
|
|
32
|
+
* 4. `"bluetooth"`
|
|
33
|
+
*
|
|
34
|
+
* ----
|
|
35
|
+
* iOS
|
|
36
|
+
*
|
|
37
|
+
* * defaultOutput - The default preferred output to use when a wired headset or bluetooth output is unavailable.
|
|
38
|
+
*
|
|
39
|
+
* By default, this is set to `"speaker"`
|
|
40
|
+
*/
|
|
41
|
+
export type AudioConfiguration = {
|
|
42
|
+
android: {
|
|
43
|
+
preferredOutputList: ('speaker' | 'earpiece' | 'headset' | 'bluetooth')[];
|
|
44
|
+
};
|
|
45
|
+
ios: {
|
|
46
|
+
defaultOutput: 'speaker' | 'earpiece';
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default class AudioSession {
|
|
51
|
+
/**
|
|
52
|
+
* Applies the provided audio configuration to the underlying AudioSession.
|
|
53
|
+
*
|
|
54
|
+
* Must be called prior to connecting to a Room for the configuration to apply correctly.
|
|
55
|
+
*/
|
|
56
|
+
static configureAudio = async (config: AudioConfiguration) => {
|
|
57
|
+
await LivekitReactNative.configureAudio(config);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Starts an AudioSession.
|
|
62
|
+
*/
|
|
63
|
+
static startAudioSession = async () => {
|
|
64
|
+
await LivekitReactNative.startAudioSession();
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Stops the existing AudioSession.
|
|
69
|
+
*/
|
|
70
|
+
static stopAudioSession = async () => {
|
|
71
|
+
await LivekitReactNative.stopAudioSession();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Gets the available audio outputs for use with {@link selectAudioOutput}.
|
|
76
|
+
*
|
|
77
|
+
* {@link startAudioSession} must be called prior to using this method.
|
|
78
|
+
*
|
|
79
|
+
* For Android, will return if available:
|
|
80
|
+
* * "speaker"
|
|
81
|
+
* * "earpiece"
|
|
82
|
+
* * "headset"
|
|
83
|
+
* * "bluetooth"
|
|
84
|
+
*
|
|
85
|
+
* Note: For applications targeting SDK versions over 30, the runtime BLUETOOTH_CONNECT
|
|
86
|
+
* permission must be requested to send audio to bluetooth headsets.
|
|
87
|
+
*
|
|
88
|
+
* ----
|
|
89
|
+
*
|
|
90
|
+
* For iOS, due to OS limitations, the only available types are:
|
|
91
|
+
* * "default" - Use default iOS audio routing
|
|
92
|
+
* * "force_speaker" - Force audio output through speaker
|
|
93
|
+
*
|
|
94
|
+
* See also {@link showAudioRoutePicker} to display a route picker that
|
|
95
|
+
* can choose between other audio devices (i.e. headset/bluetooth/airplay),
|
|
96
|
+
* or use a library like `react-native-avroutepicker` for a native platform
|
|
97
|
+
* control.
|
|
98
|
+
*
|
|
99
|
+
* @returns the available audio output types
|
|
100
|
+
*/
|
|
101
|
+
static getAudioOutputs = async (): Promise<string[]> => {
|
|
102
|
+
if (Platform.OS === 'ios') {
|
|
103
|
+
return ['default', 'force_speaker'];
|
|
104
|
+
} else if (Platform.OS === 'android') {
|
|
105
|
+
return (await LivekitReactNative.getAudioOutputs()) as string[];
|
|
106
|
+
} else {
|
|
107
|
+
return [];
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Select the provided audio output if available.
|
|
113
|
+
*
|
|
114
|
+
* {@link startAudioSession} must be called prior to using this method.
|
|
115
|
+
*
|
|
116
|
+
* @param deviceId A deviceId retrieved from {@link getAudioOutputs}
|
|
117
|
+
*/
|
|
118
|
+
static selectAudioOutput = async (deviceId: string) => {
|
|
119
|
+
await LivekitReactNative.selectAudioOutput(deviceId);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* iOS only, requires iOS 11+.
|
|
124
|
+
*
|
|
125
|
+
* Displays an AVRoutePickerView for the user to choose their audio output.
|
|
126
|
+
*/
|
|
127
|
+
static showAudioRoutePicker = async () => {
|
|
128
|
+
if (Platform.OS === 'ios') {
|
|
129
|
+
await LivekitReactNative.showAudioRoutePicker();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
LayoutChangeEvent,
|
|
5
|
+
PixelRatio,
|
|
6
|
+
StyleSheet,
|
|
7
|
+
View,
|
|
8
|
+
ViewStyle,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import {
|
|
11
|
+
ElementInfo,
|
|
12
|
+
LocalVideoTrack,
|
|
13
|
+
Track,
|
|
14
|
+
TrackEvent,
|
|
15
|
+
VideoTrack,
|
|
16
|
+
} from 'livekit-client';
|
|
17
|
+
import { RTCView } from 'react-native-webrtc';
|
|
18
|
+
import { useEffect, useState } from 'react';
|
|
19
|
+
import { RemoteVideoTrack } from 'livekit-client';
|
|
20
|
+
import ViewPortDetector from './ViewPortDetector';
|
|
21
|
+
|
|
22
|
+
export type Props = {
|
|
23
|
+
videoTrack?: VideoTrack | undefined;
|
|
24
|
+
style?: ViewStyle;
|
|
25
|
+
objectFit?: 'cover' | 'contain' | undefined;
|
|
26
|
+
mirror?: boolean;
|
|
27
|
+
zOrder?: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const VideoView = ({
|
|
31
|
+
style = {},
|
|
32
|
+
videoTrack,
|
|
33
|
+
objectFit = 'cover',
|
|
34
|
+
zOrder,
|
|
35
|
+
mirror,
|
|
36
|
+
}: Props) => {
|
|
37
|
+
const [elementInfo] = useState(() => {
|
|
38
|
+
let info = new VideoViewElementInfo();
|
|
39
|
+
info.id = videoTrack?.sid;
|
|
40
|
+
info.something = videoTrack;
|
|
41
|
+
return info;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const [mediaStream, setMediaStream] = useState(videoTrack?.mediaStream);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
setMediaStream(videoTrack?.mediaStream);
|
|
47
|
+
if (videoTrack instanceof LocalVideoTrack) {
|
|
48
|
+
const onRestarted = (track: Track | null) => {
|
|
49
|
+
setMediaStream(track?.mediaStream);
|
|
50
|
+
};
|
|
51
|
+
videoTrack.on(TrackEvent.Restarted, onRestarted);
|
|
52
|
+
|
|
53
|
+
return () => {
|
|
54
|
+
videoTrack.off(TrackEvent.Restarted, onRestarted);
|
|
55
|
+
};
|
|
56
|
+
} else {
|
|
57
|
+
return () => {};
|
|
58
|
+
}
|
|
59
|
+
}, [videoTrack]);
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (videoTrack instanceof RemoteVideoTrack && videoTrack.isAdaptiveStream) {
|
|
63
|
+
videoTrack?.observeElementInfo(elementInfo);
|
|
64
|
+
return () => {
|
|
65
|
+
videoTrack?.stopObservingElementInfo(elementInfo);
|
|
66
|
+
};
|
|
67
|
+
} else {
|
|
68
|
+
return () => {};
|
|
69
|
+
}
|
|
70
|
+
}, [videoTrack, elementInfo]);
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<View
|
|
74
|
+
style={{ ...style, ...styles.container }}
|
|
75
|
+
onLayout={(event) => {
|
|
76
|
+
elementInfo.onLayout(event);
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
<ViewPortDetector
|
|
80
|
+
onChange={(isVisible: boolean) => elementInfo.onVisibility(isVisible)}
|
|
81
|
+
style={styles.videoView}
|
|
82
|
+
>
|
|
83
|
+
<RTCView
|
|
84
|
+
style={styles.videoView}
|
|
85
|
+
streamURL={mediaStream?.toURL() ?? ''}
|
|
86
|
+
objectFit={objectFit}
|
|
87
|
+
zOrder={zOrder}
|
|
88
|
+
mirror={mirror}
|
|
89
|
+
/>
|
|
90
|
+
</ViewPortDetector>
|
|
91
|
+
</View>
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const styles = StyleSheet.create({
|
|
96
|
+
container: {},
|
|
97
|
+
videoView: {
|
|
98
|
+
flex: 1,
|
|
99
|
+
width: '100%',
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
class VideoViewElementInfo implements ElementInfo {
|
|
104
|
+
element: object = {};
|
|
105
|
+
something?: any;
|
|
106
|
+
id?: string;
|
|
107
|
+
_width = 0;
|
|
108
|
+
_height = 0;
|
|
109
|
+
_observing = false;
|
|
110
|
+
visible: boolean = true;
|
|
111
|
+
visibilityChangedAt: number | undefined;
|
|
112
|
+
handleResize?: (() => void) | undefined;
|
|
113
|
+
handleVisibilityChanged?: (() => void) | undefined;
|
|
114
|
+
width = () => this._width;
|
|
115
|
+
height = () => this._height;
|
|
116
|
+
|
|
117
|
+
observe(): void {
|
|
118
|
+
this._observing = true;
|
|
119
|
+
}
|
|
120
|
+
stopObserving(): void {
|
|
121
|
+
this._observing = false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
onLayout(event: LayoutChangeEvent) {
|
|
125
|
+
let { width, height } = event.nativeEvent.layout;
|
|
126
|
+
const pixelRatio = PixelRatio.get();
|
|
127
|
+
this._width = width * pixelRatio;
|
|
128
|
+
this._height = height * pixelRatio;
|
|
129
|
+
|
|
130
|
+
if (this._observing) {
|
|
131
|
+
this.handleResize?.();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
onVisibility(isVisible: boolean) {
|
|
135
|
+
if (this.visible !== isVisible) {
|
|
136
|
+
this.visible = isVisible;
|
|
137
|
+
this.visibilityChangedAt = Date.now();
|
|
138
|
+
if (this._observing) {
|
|
139
|
+
this.handleVisibilityChanged?.();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|