@100mslive/react-native-video-plugin 0.1.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 +20 -0
- package/README.md +179 -0
- package/android/build.gradle +103 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/hms/reactnativevideoplugin/ReactNativeVideoPluginModule.kt +203 -0
- package/android/src/main/java/com/hms/reactnativevideoplugin/ReactNativeVideoPluginPackage.kt +16 -0
- package/lib/commonjs/HMSVideoFilterPlugin.js +47 -0
- package/lib/commonjs/HMSVideoFilterPlugin.js.map +1 -0
- package/lib/commonjs/HMSVideoPlugin.js +56 -0
- package/lib/commonjs/HMSVideoPlugin.js.map +1 -0
- package/lib/commonjs/HMSVirtualBackgroundPlugin.js +63 -0
- package/lib/commonjs/HMSVirtualBackgroundPlugin.js.map +1 -0
- package/lib/commonjs/index.js +28 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/modules/ReactNativeVideoPluginModule.js +25 -0
- package/lib/commonjs/modules/ReactNativeVideoPluginModule.js.map +1 -0
- package/lib/module/HMSVideoFilterPlugin.js +40 -0
- package/lib/module/HMSVideoFilterPlugin.js.map +1 -0
- package/lib/module/HMSVideoPlugin.js +49 -0
- package/lib/module/HMSVideoPlugin.js.map +1 -0
- package/lib/module/HMSVirtualBackgroundPlugin.js +56 -0
- package/lib/module/HMSVirtualBackgroundPlugin.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/modules/ReactNativeVideoPluginModule.js +19 -0
- package/lib/module/modules/ReactNativeVideoPluginModule.js.map +1 -0
- package/lib/typescript/HMSVideoFilterPlugin.d.ts +15 -0
- package/lib/typescript/HMSVideoFilterPlugin.d.ts.map +1 -0
- package/lib/typescript/HMSVideoPlugin.d.ts +16 -0
- package/lib/typescript/HMSVideoPlugin.d.ts.map +1 -0
- package/lib/typescript/HMSVirtualBackgroundPlugin.d.ts +30 -0
- package/lib/typescript/HMSVirtualBackgroundPlugin.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/modules/ReactNativeVideoPluginModule.d.ts +4 -0
- package/lib/typescript/modules/ReactNativeVideoPluginModule.d.ts.map +1 -0
- package/package.json +235 -0
- package/sdk-versions.json +3 -0
- package/src/HMSVideoFilterPlugin.ts +52 -0
- package/src/HMSVideoPlugin.ts +63 -0
- package/src/HMSVirtualBackgroundPlugin.ts +66 -0
- package/src/index.ts +2 -0
- package/src/modules/ReactNativeVideoPluginModule.ts +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 100ms
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# @100mslive/react-native-video-plugin
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Virtual Background plugin helps in customising one's background that replacing the background with a static image or blurring the background.
|
|
5
|
+
This guide provides an overview of usage of the Virtual Background plugin of 100ms.
|
|
6
|
+
|
|
7
|
+
## Minimum Requirements
|
|
8
|
+
|
|
9
|
+
- Minimum [`@100mslive/react-native-hms`](https://github.com/100mslive/100ms-react-native) SDK version is `^1.10.6`
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Limitations
|
|
13
|
+
|
|
14
|
+
### Android
|
|
15
|
+
- Has poor FPS on older Android phones
|
|
16
|
+
|
|
17
|
+
### iOS
|
|
18
|
+
- Minimum iOS version required to support Virtual Background plugin is `iOS 15`
|
|
19
|
+
- Virtual background plugin is in beta stage and may have performance issues on iPhone X, 8, 7, 6 and other older devices. We recommend that you use this feature on a high performance device for smooth experience.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Step 1: Add required dependency
|
|
25
|
+
|
|
26
|
+
Install `@100mslive/react-native-video-plugin` library
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @100mslive/react-native-video-plugin
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Step 2: Create instance of HMSVirtualBackgroundPlugin
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
// Import from `@100mslive/react-native-video-plugin` library
|
|
36
|
+
import { HMSVirtualBackgroundPlugin } from '@100mslive/react-native-video-plugin';
|
|
37
|
+
|
|
38
|
+
...
|
|
39
|
+
|
|
40
|
+
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Step 3: Create instance of HMSVideoTrackSettings
|
|
44
|
+
|
|
45
|
+
```js
|
|
46
|
+
let videoSettings = new HMSVideoTrackSettings({
|
|
47
|
+
initialState: HMSTrackSettingsInitState.MUTED
|
|
48
|
+
// The virtual background plugin to use for the video track. @type {HMSVirtualBackgroundPlugin}
|
|
49
|
+
videoPlugin: virtualBackgroundPlugin,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
let trackSettings = new HMSTrackSettings({
|
|
53
|
+
video: videoSettings,
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Step 4: Pass the Track Settings to the HMSSDK
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
const hmsInstance = await HMSSDK.build({
|
|
61
|
+
trackSettings,
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Step 5: How to enable and disable virtual background
|
|
66
|
+
|
|
67
|
+
Hold on to a reference to the instance of HMSVirtualBackgroundPlugin and use `enable` and `disable` methods on it to enable/disable the virtual background.
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
|
|
71
|
+
|
|
72
|
+
...
|
|
73
|
+
|
|
74
|
+
let isVBEnabled = false;
|
|
75
|
+
|
|
76
|
+
// Enable VB
|
|
77
|
+
await virtualBackgroundPlugin.enable();
|
|
78
|
+
isVBEnabled = true;
|
|
79
|
+
|
|
80
|
+
// Disable VB
|
|
81
|
+
await virtualBackgroundPlugin.disable();
|
|
82
|
+
isVBEnabled = false;
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
> Always call `enable` method after `ON_JOIN` and `ON_PREVIEW` event
|
|
86
|
+
|
|
87
|
+
> Enabling Virtual Background and applying effect can take some time, you should add a loader in UI.
|
|
88
|
+
|
|
89
|
+
### Step 6: How to apply Blur as virtual background
|
|
90
|
+
|
|
91
|
+
Enable the blur background using the `setBlur` method. You should pass blur percentage ranging from 0-100
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
|
|
95
|
+
|
|
96
|
+
...
|
|
97
|
+
// state for tracking if VB is enabled
|
|
98
|
+
let isVBEnabled = false;
|
|
99
|
+
|
|
100
|
+
// If VB is disabled, first enable it before calling `setBlur` method
|
|
101
|
+
if (isVBEnabled === false) {
|
|
102
|
+
await virtualBackgroundPlugin.enable();
|
|
103
|
+
isVBEnabled = true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
await virtualBackgroundPlugin.setBlur(100);
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
> You should only call `setBlur` method only after enabling the virtual background
|
|
110
|
+
|
|
111
|
+
### Step 7: How to apply Image as virtual background
|
|
112
|
+
|
|
113
|
+
Enable the background image using the `setBackground` method. It accepts image source (either a object with height, width and uri properties or a static image file).
|
|
114
|
+
|
|
115
|
+
Here is how to use a static image file -
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
const virtualBackgroundPlugin = new HMSVirtualBackgroundPlugin();
|
|
119
|
+
|
|
120
|
+
...
|
|
121
|
+
// state for tracking if VB is enabled
|
|
122
|
+
let isVBEnabled = false;
|
|
123
|
+
|
|
124
|
+
// If VB is disabled, first enable it before calling `setBlur` method
|
|
125
|
+
if (isVBEnabled === false) {
|
|
126
|
+
await virtualBackgroundPlugin.enable();
|
|
127
|
+
isVBEnabled = true;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const image = require('<PATH_TO_IMAGE_HERE>'); // ex: require('../assets/VB-1.jpg')
|
|
131
|
+
await virtualBackgroundPlugin.setBackground(image);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Here is how to use remote image file, `setBackground` method accepts object of following type -
|
|
135
|
+
|
|
136
|
+
```js
|
|
137
|
+
export interface ImageURISource {
|
|
138
|
+
width: number;
|
|
139
|
+
|
|
140
|
+
height: number;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* `uri` is a string representing the resource identifier for the image, which
|
|
144
|
+
* could be an http address, a local file path, or the name of a static image
|
|
145
|
+
* resource (which should be wrapped in the `require('./path/to/image.png')`
|
|
146
|
+
* function).
|
|
147
|
+
*/
|
|
148
|
+
uri:
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
...
|
|
152
|
+
|
|
153
|
+
await virtualBackgroundPlugin.setBackground({
|
|
154
|
+
width,
|
|
155
|
+
height,
|
|
156
|
+
uri: 'file://...', // path of image stored in device
|
|
157
|
+
});
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Using library like [react-native-image-picker](https://www.npmjs.com/package/react-native-image-picker) -
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
import { launchImageLibrary } from 'react-native-image-picker';
|
|
164
|
+
|
|
165
|
+
...
|
|
166
|
+
|
|
167
|
+
// You can use result from library like `react-native-image-picker` to use images from photo library
|
|
168
|
+
const result = await launchImageLibrary({ mediaType: 'photo', selectionLimit: 1 });
|
|
169
|
+
|
|
170
|
+
// getting first image
|
|
171
|
+
const imageObject = response.assets?.[0];
|
|
172
|
+
|
|
173
|
+
// If image is selected, use it as background
|
|
174
|
+
if (imageObject) {
|
|
175
|
+
await virtualBackgroundPlugin.setBackground(imageObject);
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
> You should only call `setBackground` method only after enabling the virtual background
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import groovy.json.JsonSlurper
|
|
2
|
+
|
|
3
|
+
def sdkVersions = new JsonSlurper().parse file("../sdk-versions.json")
|
|
4
|
+
|
|
5
|
+
buildscript {
|
|
6
|
+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
|
|
7
|
+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["ReactNativeVideoPlugin_kotlinVersion"]
|
|
8
|
+
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
dependencies {
|
|
15
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
16
|
+
// noinspection DifferentKotlinGradleVersion
|
|
17
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
def isNewArchitectureEnabled() {
|
|
22
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
apply plugin: "com.android.library"
|
|
26
|
+
apply plugin: "kotlin-android"
|
|
27
|
+
|
|
28
|
+
if (isNewArchitectureEnabled()) {
|
|
29
|
+
apply plugin: "com.facebook.react"
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
def getExtOrDefault(name) {
|
|
33
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ReactNativeVideoPlugin_" + name]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
def getExtOrIntegerDefault(name) {
|
|
37
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ReactNativeVideoPlugin_" + name]).toInteger()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
def supportsNamespace() {
|
|
41
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
42
|
+
def major = parsed[0].toInteger()
|
|
43
|
+
def minor = parsed[1].toInteger()
|
|
44
|
+
|
|
45
|
+
// Namespace support was added in 7.3.0
|
|
46
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
android {
|
|
50
|
+
if (supportsNamespace()) {
|
|
51
|
+
namespace "com.hms.reactnativevideoplugin"
|
|
52
|
+
|
|
53
|
+
sourceSets {
|
|
54
|
+
main {
|
|
55
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
61
|
+
|
|
62
|
+
defaultConfig {
|
|
63
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
64
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
buildTypes {
|
|
69
|
+
release {
|
|
70
|
+
minifyEnabled false
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
lintOptions {
|
|
75
|
+
disable "GradleCompatible"
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
compileOptions {
|
|
79
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
80
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
repositories {
|
|
85
|
+
mavenCentral()
|
|
86
|
+
google()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
90
|
+
|
|
91
|
+
dependencies {
|
|
92
|
+
// For < 0.71, this will be from the local maven repo
|
|
93
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
94
|
+
//noinspection GradleDynamicVersion
|
|
95
|
+
implementation "com.facebook.react:react-native:+"
|
|
96
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
97
|
+
|
|
98
|
+
// implementation project(":reactnativehmssdk")
|
|
99
|
+
implementation project(":100mslive_react-native-hms")
|
|
100
|
+
implementation "live.100ms:virtual-background:${sdkVersions["android"]}"
|
|
101
|
+
implementation "live.100ms:android-sdk:${sdkVersions["android"]}"
|
|
102
|
+
}
|
|
103
|
+
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
package com.hms.reactnativevideoplugin
|
|
2
|
+
|
|
3
|
+
import android.graphics.Bitmap
|
|
4
|
+
import android.graphics.BitmapFactory
|
|
5
|
+
import android.net.Uri
|
|
6
|
+
import com.facebook.react.bridge.Promise
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
9
|
+
import com.facebook.react.bridge.ReactMethod
|
|
10
|
+
import com.facebook.react.bridge.ReadableMap
|
|
11
|
+
import com.reactnativehmssdk.HMSManager
|
|
12
|
+
import com.reactnativehmssdk.HMSRNSDK
|
|
13
|
+
import live.hms.video.error.HMSException
|
|
14
|
+
import live.hms.video.sdk.HMSActionResultListener
|
|
15
|
+
import live.hms.video.virtualbackground.HMSVirtualBackground
|
|
16
|
+
import java.net.URL
|
|
17
|
+
|
|
18
|
+
class ReactNativeVideoPluginModule(reactContext: ReactApplicationContext) :
|
|
19
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
20
|
+
private var virtualBackgroundPlugin: HMSVirtualBackground? = null
|
|
21
|
+
|
|
22
|
+
@ReactMethod
|
|
23
|
+
fun changeVirtualBackground(
|
|
24
|
+
data: ReadableMap,
|
|
25
|
+
promise: Promise?,
|
|
26
|
+
) {
|
|
27
|
+
val hmsRnSDK = getHmsRNSdk(data)
|
|
28
|
+
if (hmsRnSDK == null) {
|
|
29
|
+
promise?.reject("6004", "HMSRNSDK not initialized")
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
val hmsSDK = hmsRnSDK.hmsSDK
|
|
33
|
+
if (hmsSDK == null) {
|
|
34
|
+
promise?.reject("6004", "HMSSDK not initialized")
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
val virtualBackgroundPlugin = virtualBackgroundPlugin
|
|
38
|
+
if (virtualBackgroundPlugin == null) {
|
|
39
|
+
promise?.reject(
|
|
40
|
+
"6004",
|
|
41
|
+
"`virtualBackgroundPlugin` is `nil`, Make sure you are passing `HMSVirtualBackground` instance to `videoTrackSettings` in `HMSSDK.build`",
|
|
42
|
+
)
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
val backgroundMap = data.getMap("background")
|
|
46
|
+
if (backgroundMap == null) {
|
|
47
|
+
promise?.reject("6004", "`background` object not passed")
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
val backgroundType = backgroundMap.getString("type")
|
|
51
|
+
if (backgroundType == null) {
|
|
52
|
+
promise?.reject("6004", "`type` property in `background` object not passed")
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
when (backgroundType) {
|
|
56
|
+
"blur" -> {
|
|
57
|
+
val blurRadius = backgroundMap.getDouble("blurRadius")
|
|
58
|
+
virtualBackgroundPlugin.enableBlur(blurRadius.toInt())
|
|
59
|
+
promise?.resolve(true)
|
|
60
|
+
}
|
|
61
|
+
"image" -> {
|
|
62
|
+
val backgroundSource = backgroundMap.getMap("source")
|
|
63
|
+
if (backgroundSource == null) {
|
|
64
|
+
promise?.reject("6004", "`source` property in background object not passed")
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
val bgImageUri = backgroundSource.getString("uri")
|
|
68
|
+
if (bgImageUri == null) {
|
|
69
|
+
promise?.reject("6004", "`source.uri` property in background object not passed")
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
val bitmap: Bitmap? =
|
|
74
|
+
if (bgImageUri.startsWith("http://")) {
|
|
75
|
+
val url = URL(bgImageUri)
|
|
76
|
+
BitmapFactory.decodeStream(url.openConnection().getInputStream())
|
|
77
|
+
} else if (bgImageUri.startsWith("file://")) {
|
|
78
|
+
val fileUri = Uri.parse(bgImageUri) ?: return
|
|
79
|
+
if (fileUri.scheme != "file") {
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
BitmapFactory.decodeFile(fileUri.path)
|
|
83
|
+
} else {
|
|
84
|
+
val context = reactApplicationContext.applicationContext
|
|
85
|
+
val resourceId = context.resources.getIdentifier(bgImageUri, "drawable", context.packageName)
|
|
86
|
+
BitmapFactory.decodeResource(context.resources, resourceId)
|
|
87
|
+
}
|
|
88
|
+
if (bitmap == null) {
|
|
89
|
+
promise?.reject("6004", "Image Bitmap cannot be converted from passed `source.uri` in background data!")
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
virtualBackgroundPlugin.enableBackground(bitmap)
|
|
93
|
+
promise?.resolve(true)
|
|
94
|
+
} catch (e: Exception) {
|
|
95
|
+
promise?.reject("6004", e.message)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
else -> {
|
|
99
|
+
promise?.reject("6004", "Unknown `type` property passed in background object")
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@ReactMethod
|
|
105
|
+
fun disableVideoPlugin(
|
|
106
|
+
data: ReadableMap,
|
|
107
|
+
promise: Promise?,
|
|
108
|
+
) {
|
|
109
|
+
val hmsRnSDK = getHmsRNSdk(data)
|
|
110
|
+
if (hmsRnSDK == null) {
|
|
111
|
+
promise?.reject("6004", "HMSRNSDK not initialized")
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
val hmsSDK = hmsRnSDK.hmsSDK
|
|
115
|
+
if (hmsSDK == null) {
|
|
116
|
+
promise?.reject("6004", "HMSSDK not initialized")
|
|
117
|
+
return
|
|
118
|
+
}
|
|
119
|
+
val virtualBackgroundPlugin = virtualBackgroundPlugin
|
|
120
|
+
if (virtualBackgroundPlugin == null) {
|
|
121
|
+
promise?.reject("6004", "HMSVirtualBackground is already disabled!")
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
val pluginType = data.getString("type")
|
|
125
|
+
if (pluginType == null) {
|
|
126
|
+
promise?.reject("6004", "`type` not passed")
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
when (pluginType) {
|
|
130
|
+
"HMSVirtualBackgroundPlugin" -> {
|
|
131
|
+
val moduleInstance = this
|
|
132
|
+
hmsSDK.removePlugin(
|
|
133
|
+
virtualBackgroundPlugin,
|
|
134
|
+
object : HMSActionResultListener {
|
|
135
|
+
override fun onError(error: HMSException) {
|
|
136
|
+
promise?.reject(error.code.toString(), error.message)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
override fun onSuccess() {
|
|
140
|
+
promise?.resolve(true)
|
|
141
|
+
moduleInstance.virtualBackgroundPlugin = null
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
else -> {
|
|
147
|
+
promise?.reject("6004", "Unknown `type` passed")
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@ReactMethod
|
|
153
|
+
fun enableVideoPlugin(
|
|
154
|
+
data: ReadableMap,
|
|
155
|
+
promise: Promise?,
|
|
156
|
+
) {
|
|
157
|
+
val hmsSDK = getHmsRNSdk(data)?.hmsSDK ?: return promise?.reject("6004", "SDK not initialized").let { }
|
|
158
|
+
val pluginType = data.getString("type") ?: return promise?.reject("6004", "`type` not passed").let { }
|
|
159
|
+
|
|
160
|
+
if (pluginType == "HMSVirtualBackgroundPlugin") {
|
|
161
|
+
val addPluginListener =
|
|
162
|
+
object : HMSActionResultListener {
|
|
163
|
+
override fun onError(error: HMSException) {
|
|
164
|
+
promise?.reject(error.code.toString(), error.message)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
override fun onSuccess() {
|
|
168
|
+
promise?.resolve(true)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
virtualBackgroundPlugin?.let {
|
|
173
|
+
hmsSDK.addPlugin(it, addPluginListener)
|
|
174
|
+
} ?: run {
|
|
175
|
+
HMSVirtualBackground(hmsSDK).apply {
|
|
176
|
+
enableBlur(75)
|
|
177
|
+
virtualBackgroundPlugin = this
|
|
178
|
+
hmsSDK.addPlugin(this, addPluginListener)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
promise?.reject("6004", "Unknown `type` passed")
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
override fun getName(): String {
|
|
187
|
+
return NAME
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private fun getHmsRNSdk(data: ReadableMap): HMSRNSDK? {
|
|
191
|
+
val id = data.getString("id")
|
|
192
|
+
|
|
193
|
+
return if (id != null) {
|
|
194
|
+
HMSManager.hmsCollection[id]
|
|
195
|
+
} else {
|
|
196
|
+
null
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
companion object {
|
|
201
|
+
const val NAME = "ReactNativeVideoPlugin"
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
package com.hms.reactnativevideoplugin
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager
|
|
7
|
+
|
|
8
|
+
class ReactNativeVideoPluginPackage : ReactPackage {
|
|
9
|
+
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
10
|
+
return listOf(ReactNativeVideoPluginModule(reactContext))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
14
|
+
return emptyList()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.HMSVideoFilterPlugin = void 0;
|
|
7
|
+
var _HMSVideoPlugin = require("./HMSVideoPlugin");
|
|
8
|
+
class HMSVideoFilterPlugin extends _HMSVideoPlugin.HMSVideoPlugin {
|
|
9
|
+
static NAME = 'HMSVideoFilterPlugin';
|
|
10
|
+
constructor() {
|
|
11
|
+
super(HMSVideoFilterPlugin.NAME);
|
|
12
|
+
}
|
|
13
|
+
setHue(val) {
|
|
14
|
+
return this.setFilter('hue', val);
|
|
15
|
+
}
|
|
16
|
+
setSaturation(val) {
|
|
17
|
+
return this.setFilter('saturation', val);
|
|
18
|
+
}
|
|
19
|
+
setBrightness(val) {
|
|
20
|
+
return this.setFilter('brightness', val);
|
|
21
|
+
}
|
|
22
|
+
setContrast(val) {
|
|
23
|
+
return this.setFilter('contrast', val);
|
|
24
|
+
}
|
|
25
|
+
setSmoothness(val) {
|
|
26
|
+
return this.setFilter('smoothness', val);
|
|
27
|
+
}
|
|
28
|
+
setRedness(val) {
|
|
29
|
+
return this.setFilter('redness', val);
|
|
30
|
+
}
|
|
31
|
+
setSharpness(val) {
|
|
32
|
+
return this.setFilter('sharpness', val);
|
|
33
|
+
}
|
|
34
|
+
setExposure(val) {
|
|
35
|
+
return this.setFilter('exposure', val);
|
|
36
|
+
}
|
|
37
|
+
setFilter(filter, value) {
|
|
38
|
+
const data = {
|
|
39
|
+
id: '12345',
|
|
40
|
+
filter,
|
|
41
|
+
value
|
|
42
|
+
};
|
|
43
|
+
return this.nativeModule.setVideoFilterParameter(data);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.HMSVideoFilterPlugin = HMSVideoFilterPlugin;
|
|
47
|
+
//# sourceMappingURL=HMSVideoFilterPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_HMSVideoPlugin","require","HMSVideoFilterPlugin","HMSVideoPlugin","NAME","constructor","setHue","val","setFilter","setSaturation","setBrightness","setContrast","setSmoothness","setRedness","setSharpness","setExposure","filter","value","data","id","nativeModule","setVideoFilterParameter","exports"],"sourceRoot":"../../src","sources":["HMSVideoFilterPlugin.ts"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAYO,MAAMC,oBAAoB,SAASC,8BAAc,CAAC;EACvD,OAAOC,IAAI,GAAG,sBAAsB;EAEpCC,WAAWA,CAAA,EAAG;IACZ,KAAK,CAACH,oBAAoB,CAACE,IAAI,CAAC;EAClC;EAEAE,MAAMA,CAACC,GAAW,EAAE;IAClB,OAAO,IAAI,CAACC,SAAS,CAAC,KAAK,EAAED,GAAG,CAAC;EACnC;EACAE,aAAaA,CAACF,GAAW,EAAE;IACzB,OAAO,IAAI,CAACC,SAAS,CAAC,YAAY,EAAED,GAAG,CAAC;EAC1C;EACAG,aAAaA,CAACH,GAAW,EAAE;IACzB,OAAO,IAAI,CAACC,SAAS,CAAC,YAAY,EAAED,GAAG,CAAC;EAC1C;EACAI,WAAWA,CAACJ,GAAW,EAAE;IACvB,OAAO,IAAI,CAACC,SAAS,CAAC,UAAU,EAAED,GAAG,CAAC;EACxC;EACAK,aAAaA,CAACL,GAAW,EAAE;IACzB,OAAO,IAAI,CAACC,SAAS,CAAC,YAAY,EAAED,GAAG,CAAC;EAC1C;EACAM,UAAUA,CAACN,GAAW,EAAE;IACtB,OAAO,IAAI,CAACC,SAAS,CAAC,SAAS,EAAED,GAAG,CAAC;EACvC;EACAO,YAAYA,CAACP,GAAW,EAAE;IACxB,OAAO,IAAI,CAACC,SAAS,CAAC,WAAW,EAAED,GAAG,CAAC;EACzC;EACAQ,WAAWA,CAACR,GAAW,EAAE;IACvB,OAAO,IAAI,CAACC,SAAS,CAAC,UAAU,EAAED,GAAG,CAAC;EACxC;EACQC,SAASA,CAACQ,MAAwB,EAAEC,KAAa,EAAoB;IAC3E,MAAMC,IAAI,GAAG;MACXC,EAAE,EAAE,OAAO;MACXH,MAAM;MACNC;IACF,CAAC;IACD,OAAO,IAAI,CAACG,YAAY,CAACC,uBAAuB,CAACH,IAAI,CAAC;EACxD;AACF;AAACI,OAAA,CAAApB,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.HMSVideoPlugin = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _reactNativeHms = require("@100mslive/react-native-hms");
|
|
9
|
+
var _ReactNativeVideoPluginModule = require("./modules/ReactNativeVideoPluginModule");
|
|
10
|
+
const _nativeModule = _reactNative.Platform.OS === 'android' ? _ReactNativeVideoPluginModule.ReactNativeVideoPlugin.nativeModule : _reactNativeHms.HMSManagerModule;
|
|
11
|
+
class HMSVideoPlugin {
|
|
12
|
+
constructor(pluginType) {
|
|
13
|
+
this.type = pluginType;
|
|
14
|
+
}
|
|
15
|
+
get nativeModule() {
|
|
16
|
+
return _nativeModule;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Enables video plugin.
|
|
21
|
+
* @returns {Promise<boolean>} A promise that resolves to true when video plugin is enabled, otherwise, rejected promise is returned
|
|
22
|
+
*/
|
|
23
|
+
async enable() {
|
|
24
|
+
const data = {
|
|
25
|
+
id: '12345',
|
|
26
|
+
type: this.type
|
|
27
|
+
};
|
|
28
|
+
if (__DEV__) console.log('#Function HMSVirtualBackgroundPlugin#enable', data);
|
|
29
|
+
try {
|
|
30
|
+
return this.nativeModule.enableVideoPlugin(data);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (__DEV__) console.warn('#Error in #Function HMSVirtualBackgroundPlugin#enable ', e);
|
|
33
|
+
return Promise.reject(e);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Disable video plugin.
|
|
39
|
+
* @returns {Promise<boolean>} A promise that resolves to true when video plugin is disabled, otherwise, rejected promise is returned
|
|
40
|
+
*/
|
|
41
|
+
async disable() {
|
|
42
|
+
const data = {
|
|
43
|
+
id: '12345',
|
|
44
|
+
type: this.type
|
|
45
|
+
};
|
|
46
|
+
if (__DEV__) console.log('#Function HMSVirtualBackgroundPlugin#disable', data);
|
|
47
|
+
try {
|
|
48
|
+
return this.nativeModule.disableVideoPlugin(data);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
if (__DEV__) console.warn('#Error in #Function HMSVirtualBackgroundPlugin#disable ', e);
|
|
51
|
+
return Promise.reject(e);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.HMSVideoPlugin = HMSVideoPlugin;
|
|
56
|
+
//# sourceMappingURL=HMSVideoPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_reactNativeHms","_ReactNativeVideoPluginModule","_nativeModule","Platform","OS","ReactNativeVideoPlugin","nativeModule","HMSManagerModule","HMSVideoPlugin","constructor","pluginType","type","enable","data","id","__DEV__","console","log","enableVideoPlugin","e","warn","Promise","reject","disable","disableVideoPlugin","exports"],"sourceRoot":"../../src","sources":["HMSVideoPlugin.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA,IAAAE,6BAAA,GAAAF,OAAA;AAEA,MAAMG,aAAa,GACjBC,qBAAQ,CAACC,EAAE,KAAK,SAAS,GACrBC,oDAAsB,CAACC,YAAY,GACnCC,gCAAgB;AAEf,MAAMC,cAAc,CAAC;EAG1BC,WAAWA,CAACC,UAAkB,EAAE;IAC9B,IAAI,CAACC,IAAI,GAAGD,UAAU;EACxB;EAEA,IAAcJ,YAAYA,CAAA,EAAG;IAC3B,OAAOJ,aAAa;EACtB;;EAEA;AACF;AACA;AACA;EACE,MAAMU,MAAMA,CAAA,EAAqB;IAC/B,MAAMC,IAAI,GAAG;MAAEC,EAAE,EAAE,OAAO;MAAEH,IAAI,EAAE,IAAI,CAACA;IAAK,CAAC;IAC7C,IAAII,OAAO,EACTC,OAAO,CAACC,GAAG,CAAC,6CAA6C,EAAEJ,IAAI,CAAC;IAElE,IAAI;MACF,OAAO,IAAI,CAACP,YAAY,CAACY,iBAAiB,CAACL,IAAI,CAAC;IAClD,CAAC,CAAC,OAAOM,CAAC,EAAE;MACV,IAAIJ,OAAO,EACTC,OAAO,CAACI,IAAI,CACV,wDAAwD,EACxDD,CACF,CAAC;MACH,OAAOE,OAAO,CAACC,MAAM,CAACH,CAAC,CAAC;IAC1B;EACF;;EAEA;AACF;AACA;AACA;EACE,MAAMI,OAAOA,CAAA,EAAqB;IAChC,MAAMV,IAAI,GAAG;MAAEC,EAAE,EAAE,OAAO;MAAEH,IAAI,EAAE,IAAI,CAACA;IAAK,CAAC;IAC7C,IAAII,OAAO,EACTC,OAAO,CAACC,GAAG,CAAC,8CAA8C,EAAEJ,IAAI,CAAC;IAEnE,IAAI;MACF,OAAO,IAAI,CAACP,YAAY,CAACkB,kBAAkB,CAACX,IAAI,CAAC;IACnD,CAAC,CAAC,OAAOM,CAAC,EAAE;MACV,IAAIJ,OAAO,EACTC,OAAO,CAACI,IAAI,CACV,yDAAyD,EACzDD,CACF,CAAC;MACH,OAAOE,OAAO,CAACC,MAAM,CAACH,CAAC,CAAC;IAC1B;EACF;AACF;AAACM,OAAA,CAAAjB,cAAA,GAAAA,cAAA","ignoreList":[]}
|