@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.
Files changed (45) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +179 -0
  3. package/android/build.gradle +103 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +3 -0
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/com/hms/reactnativevideoplugin/ReactNativeVideoPluginModule.kt +203 -0
  8. package/android/src/main/java/com/hms/reactnativevideoplugin/ReactNativeVideoPluginPackage.kt +16 -0
  9. package/lib/commonjs/HMSVideoFilterPlugin.js +47 -0
  10. package/lib/commonjs/HMSVideoFilterPlugin.js.map +1 -0
  11. package/lib/commonjs/HMSVideoPlugin.js +56 -0
  12. package/lib/commonjs/HMSVideoPlugin.js.map +1 -0
  13. package/lib/commonjs/HMSVirtualBackgroundPlugin.js +63 -0
  14. package/lib/commonjs/HMSVirtualBackgroundPlugin.js.map +1 -0
  15. package/lib/commonjs/index.js +28 -0
  16. package/lib/commonjs/index.js.map +1 -0
  17. package/lib/commonjs/modules/ReactNativeVideoPluginModule.js +25 -0
  18. package/lib/commonjs/modules/ReactNativeVideoPluginModule.js.map +1 -0
  19. package/lib/module/HMSVideoFilterPlugin.js +40 -0
  20. package/lib/module/HMSVideoFilterPlugin.js.map +1 -0
  21. package/lib/module/HMSVideoPlugin.js +49 -0
  22. package/lib/module/HMSVideoPlugin.js.map +1 -0
  23. package/lib/module/HMSVirtualBackgroundPlugin.js +56 -0
  24. package/lib/module/HMSVirtualBackgroundPlugin.js.map +1 -0
  25. package/lib/module/index.js +3 -0
  26. package/lib/module/index.js.map +1 -0
  27. package/lib/module/modules/ReactNativeVideoPluginModule.js +19 -0
  28. package/lib/module/modules/ReactNativeVideoPluginModule.js.map +1 -0
  29. package/lib/typescript/HMSVideoFilterPlugin.d.ts +15 -0
  30. package/lib/typescript/HMSVideoFilterPlugin.d.ts.map +1 -0
  31. package/lib/typescript/HMSVideoPlugin.d.ts +16 -0
  32. package/lib/typescript/HMSVideoPlugin.d.ts.map +1 -0
  33. package/lib/typescript/HMSVirtualBackgroundPlugin.d.ts +30 -0
  34. package/lib/typescript/HMSVirtualBackgroundPlugin.d.ts.map +1 -0
  35. package/lib/typescript/index.d.ts +3 -0
  36. package/lib/typescript/index.d.ts.map +1 -0
  37. package/lib/typescript/modules/ReactNativeVideoPluginModule.d.ts +4 -0
  38. package/lib/typescript/modules/ReactNativeVideoPluginModule.d.ts.map +1 -0
  39. package/package.json +235 -0
  40. package/sdk-versions.json +3 -0
  41. package/src/HMSVideoFilterPlugin.ts +52 -0
  42. package/src/HMSVideoPlugin.ts +63 -0
  43. package/src/HMSVirtualBackgroundPlugin.ts +66 -0
  44. package/src/index.ts +2 -0
  45. package/src/modules/ReactNativeVideoPluginModule.ts +33 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ "android": "2.9.59"
3
+ }
@@ -0,0 +1,52 @@
1
+ import { HMSVideoPlugin } from './HMSVideoPlugin';
2
+
3
+ type SupportedFilters =
4
+ | 'hue'
5
+ | 'saturation'
6
+ | 'brightness'
7
+ | 'contrast'
8
+ | 'smoothness'
9
+ | 'redness'
10
+ | 'sharpness'
11
+ | 'exposure';
12
+
13
+ export class HMSVideoFilterPlugin extends HMSVideoPlugin {
14
+ static NAME = 'HMSVideoFilterPlugin';
15
+
16
+ constructor() {
17
+ super(HMSVideoFilterPlugin.NAME);
18
+ }
19
+
20
+ setHue(val: number) {
21
+ return this.setFilter('hue', val);
22
+ }
23
+ setSaturation(val: number) {
24
+ return this.setFilter('saturation', val);
25
+ }
26
+ setBrightness(val: number) {
27
+ return this.setFilter('brightness', val);
28
+ }
29
+ setContrast(val: number) {
30
+ return this.setFilter('contrast', val);
31
+ }
32
+ setSmoothness(val: number) {
33
+ return this.setFilter('smoothness', val);
34
+ }
35
+ setRedness(val: number) {
36
+ return this.setFilter('redness', val);
37
+ }
38
+ setSharpness(val: number) {
39
+ return this.setFilter('sharpness', val);
40
+ }
41
+ setExposure(val: number) {
42
+ return this.setFilter('exposure', val);
43
+ }
44
+ private setFilter(filter: SupportedFilters, value: number): Promise<boolean> {
45
+ const data = {
46
+ id: '12345',
47
+ filter,
48
+ value,
49
+ };
50
+ return this.nativeModule.setVideoFilterParameter(data);
51
+ }
52
+ }
@@ -0,0 +1,63 @@
1
+ import { Platform } from 'react-native';
2
+ import { HMSManagerModule } from '@100mslive/react-native-hms';
3
+
4
+ import { ReactNativeVideoPlugin } from './modules/ReactNativeVideoPluginModule';
5
+
6
+ const _nativeModule =
7
+ Platform.OS === 'android'
8
+ ? ReactNativeVideoPlugin.nativeModule
9
+ : HMSManagerModule;
10
+
11
+ export class HMSVideoPlugin {
12
+ protected type: string;
13
+
14
+ constructor(pluginType: string) {
15
+ this.type = pluginType;
16
+ }
17
+
18
+ protected get nativeModule() {
19
+ return _nativeModule;
20
+ }
21
+
22
+ /**
23
+ * Enables video plugin.
24
+ * @returns {Promise<boolean>} A promise that resolves to true when video plugin is enabled, otherwise, rejected promise is returned
25
+ */
26
+ async enable(): Promise<boolean> {
27
+ const data = { id: '12345', type: this.type };
28
+ if (__DEV__)
29
+ console.log('#Function HMSVirtualBackgroundPlugin#enable', data);
30
+
31
+ try {
32
+ return this.nativeModule.enableVideoPlugin(data);
33
+ } catch (e) {
34
+ if (__DEV__)
35
+ console.warn(
36
+ '#Error in #Function HMSVirtualBackgroundPlugin#enable ',
37
+ e
38
+ );
39
+ return Promise.reject(e);
40
+ }
41
+ }
42
+
43
+ /**
44
+ * Disable video plugin.
45
+ * @returns {Promise<boolean>} A promise that resolves to true when video plugin is disabled, otherwise, rejected promise is returned
46
+ */
47
+ async disable(): Promise<boolean> {
48
+ const data = { id: '12345', type: this.type };
49
+ if (__DEV__)
50
+ console.log('#Function HMSVirtualBackgroundPlugin#disable', data);
51
+
52
+ try {
53
+ return this.nativeModule.disableVideoPlugin(data);
54
+ } catch (e) {
55
+ if (__DEV__)
56
+ console.warn(
57
+ '#Error in #Function HMSVirtualBackgroundPlugin#disable ',
58
+ e
59
+ );
60
+ return Promise.reject(e);
61
+ }
62
+ }
63
+ }
@@ -0,0 +1,66 @@
1
+ import { Image } from 'react-native';
2
+ import type {
3
+ ImageRequireSource,
4
+ ImageResolvedAssetSource,
5
+ ImageURISource,
6
+ } from 'react-native';
7
+
8
+ import { HMSVideoPlugin } from './HMSVideoPlugin';
9
+
10
+ export class HMSVirtualBackgroundPlugin extends HMSVideoPlugin {
11
+ static NAME = 'HMSVirtualBackgroundPlugin';
12
+
13
+ constructor() {
14
+ super(HMSVirtualBackgroundPlugin.NAME);
15
+ }
16
+
17
+ /**
18
+ * Sets Blur as background
19
+ * @returns {Promise<boolean>} A promise that resolves to true when blur effect has been applied as background, otherwise, rejected promise is returned
20
+ */
21
+ setBlur(blurRadius: number): Promise<boolean> {
22
+ const data = {
23
+ id: '12345',
24
+ background: { type: 'blur', blurRadius },
25
+ };
26
+ return this.nativeModule.changeVirtualBackground(data);
27
+ }
28
+
29
+ /**
30
+ * Sets provided image as background
31
+ * @param backgroundImage An image to apply as background on
32
+ * @returns {Promise<boolean>} A promise that resolves to true when provided background image has been applied as background, otherwise, rejected promise is returned
33
+ *
34
+ * Example Usage:
35
+ * ```
36
+ * // Create instance of `HMSVirtualBackgroundPlugin` class
37
+ * const hmsVirtualBackgroundPlugin = HMSVirtualBackgroundPlugin();
38
+ * ...
39
+ * // In ON_PREVIEW or ON_JOIN event callback method
40
+ * const image = require('path to image file');
41
+ * hmsVirtualBackgroundPlugin.setBackground(image);
42
+ *
43
+ *
44
+ * ```
45
+ */
46
+ setBackground(
47
+ backgroundImage: ImageURISource | ImageRequireSource
48
+ ): Promise<boolean> {
49
+ const background = resolveBackground(backgroundImage);
50
+ const data = {
51
+ id: '12345',
52
+ background,
53
+ };
54
+ return this.nativeModule.changeVirtualBackground(data);
55
+ }
56
+ }
57
+
58
+ function resolveBackground(background: ImageURISource | ImageRequireSource): {
59
+ type: 'image';
60
+ source: ImageResolvedAssetSource;
61
+ } {
62
+ return {
63
+ type: 'image',
64
+ source: Image.resolveAssetSource(background),
65
+ };
66
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './HMSVirtualBackgroundPlugin';
2
+ export * from './modules/ReactNativeVideoPluginModule';
@@ -0,0 +1,33 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ const LINKING_ERROR =
4
+ `The package '@100mslive/react-native-video-plugin' doesn't seem to be linked. Make sure: \n\n` +
5
+ // Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
6
+ '- You rebuilt the app after installing the package\n' +
7
+ '- You are not using Expo Go\n';
8
+
9
+ const IOS_PLATFORM_ERROR =
10
+ 'ReactNativeVideoPlugin native module is not available on iOS. Please add a `Platform.OS` check like: \n\n' +
11
+ '```\n' +
12
+ 'Platform.OS === "android" ? ReactNativeVideoPlugin.nativeModule : null\n' +
13
+ '```';
14
+
15
+ const ReactNativeVideoPluginModule = NativeModules.ReactNativeVideoPlugin;
16
+
17
+ export const ReactNativeVideoPlugin = {
18
+ get nativeModule() {
19
+ if (ReactNativeVideoPluginModule) {
20
+ return ReactNativeVideoPluginModule;
21
+ }
22
+ return new Proxy(
23
+ {},
24
+ {
25
+ get() {
26
+ throw new Error(
27
+ Platform.OS === 'android' ? LINKING_ERROR : IOS_PLATFORM_ERROR
28
+ );
29
+ },
30
+ }
31
+ );
32
+ },
33
+ };