├── .husky ├── .npmignore ├── pre-commit └── commit-msg ├── src ├── __tests__ │ └── index.test.tsx └── index.tsx ├── example ├── ios │ ├── .xcode.env │ ├── ReactNativeAntMediaExample │ │ ├── Images.xcassets │ │ │ ├── Contents.json │ │ │ └── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ ├── AppDelegate.h │ │ ├── main.m │ │ ├── AppDelegate.mm │ │ ├── PrivacyInfo.xcprivacy │ │ ├── Info.plist │ │ └── LaunchScreen.storyboard │ ├── ReactNativeAntMediaExampleTests │ │ ├── Info.plist │ │ └── ReactNativeAntMediaExampleTests.m │ ├── Podfile │ └── ReactNativeAntMediaExample.xcodeproj │ │ ├── xcshareddata │ │ └── xcschemes │ │ │ └── ReactNativeAntMediaExample.xcscheme │ │ └── project.pbxproj ├── .eslintrc.js ├── app.json ├── android │ ├── app │ │ ├── debug.keystore │ │ ├── src │ │ │ ├── main │ │ │ │ ├── res │ │ │ │ │ ├── values │ │ │ │ │ │ ├── strings.xml │ │ │ │ │ │ └── styles.xml │ │ │ │ │ ├── mipmap-hdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-mdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ ├── mipmap-xxxhdpi │ │ │ │ │ │ ├── ic_launcher.png │ │ │ │ │ │ └── ic_launcher_round.png │ │ │ │ │ └── drawable │ │ │ │ │ │ └── rn_edit_text_material.xml │ │ │ │ ├── java │ │ │ │ │ └── com │ │ │ │ │ │ └── reactnativeantmediaexample │ │ │ │ │ │ ├── MainActivity.kt │ │ │ │ │ │ └── MainApplication.kt │ │ │ │ ├── AndroidManifest.xml │ │ │ │ └── jni │ │ │ │ │ └── Android.mk │ │ │ └── debug │ │ │ │ └── AndroidManifest.xml │ │ ├── proguard-rules.pro │ │ └── build.gradle │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── settings.gradle │ ├── build.gradle │ ├── gradle.properties │ ├── gradlew.bat │ └── gradlew ├── index.js ├── Gemfile ├── babel.config.js ├── src │ ├── StyleSheet.js │ ├── App.tsx │ ├── MainScreen.tsx │ ├── Play.tsx │ ├── Peer.tsx │ ├── Chat.tsx │ ├── Publish.tsx │ └── Conference.tsx ├── metro.config.js └── package.json ├── jest.config.js ├── .gitattributes ├── tsconfig.build.json ├── .eslintrc.js ├── babel.config.js ├── .yarnrc ├── .editorconfig ├── .github └── workflows │ ├── publish.yml │ ├── build-for-android.yml │ └── build-for-ios.yml ├── tsconfig.json ├── scripts └── bootstrap.js ├── LICENSE ├── README.md ├── .gitignore ├── .circleci └── config.yml ├── package.json └── CONTRIBUTING.md /.husky/.npmignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /src/__tests__/index.test.tsx: -------------------------------------------------------------------------------- 1 | it.todo('write a test'); 2 | -------------------------------------------------------------------------------- /example/ios/.xcode.env: -------------------------------------------------------------------------------- 1 | export NODE_BINARY=$(command -v node) 2 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: 'react-native', 3 | }; 4 | 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "extends": "./tsconfig", 4 | "exclude": ["example"] 5 | } 6 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: '@react-native', 4 | }; 5 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:@react-native/babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn lint && yarn typescript 5 | -------------------------------------------------------------------------------- /example/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: '@react-native', 4 | }; 5 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn commitlint -E HUSKY_GIT_PARAMS 5 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ReactNativeAntMediaExample", 3 | "displayName": "ReactNative AntMedia Example" 4 | } 5 | -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | # Override Yarn command so we can automatically setup the repo on running `yarn` 2 | 3 | yarn-path "scripts/bootstrap.js" 4 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ReactNativeAntMedia Example 3 | 4 | -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExample/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExample/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : RCTAppDelegate 5 | 6 | @end 7 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ant-media/WebRTC-React-Native-SDK/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import { name as appName } from './app.json'; 3 | import App from './src/App'; 4 | 5 | AppRegistry.registerComponent(appName, () => App); 6 | -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExample/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | @autoreleasepool { 8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version 4 | ruby ">= 2.6.10" 5 | 6 | # Exclude problematic versions of cocoapods and activesupport that causes build failures. 7 | gem 'cocoapods', '>= 1.13', '!= 1.15.0', '!= 1.15.1' 8 | gem 'activesupport', '>= 6.1.7.5', '!= 7.1.0' 9 | 10 | -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") } 2 | plugins { id("com.facebook.react.settings") } 3 | extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } 4 | rootProject.name = 'ReactNativeAntMediaExample' 5 | include ':app' 6 | includeBuild('../node_modules/@react-native/gradle-plugin') 7 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = { 5 | presets: ['module:@react-native/babel-preset'], 6 | plugins: [ 7 | [ 8 | 'module-resolver', // we need babel-plugin-module-resolver to make it work 9 | { 10 | extensions: ['.tsx', '.ts', '.js', '.json'], 11 | alias: { 12 | [pak.name]: path.join(__dirname, '..', pak.source), 13 | }, 14 | }, 15 | ], 16 | ], 17 | }; 18 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | buildscript { 3 | ext { 4 | minSdkVersion = 23 5 | compileSdkVersion = 34 6 | targetSdkVersion = 34 7 | 8 | ndkVersion = "26.1.10909125" 9 | kotlinVersion = "1.9.24" 10 | 11 | } 12 | repositories { 13 | google() 14 | mavenCentral() 15 | } 16 | dependencies { 17 | classpath("com.android.tools.build:gradle") 18 | classpath("com.facebook.react:react-native-gradle-plugin") 19 | classpath("org.jetbrains.kotlin:kotlin-gradle-plugin") 20 | 21 | } 22 | } 23 | 24 | apply plugin: "com.facebook.react.rootproject" 25 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: "publish" 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | 7 | jobs: 8 | publish: 9 | name: publishing 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: checkout 14 | uses: actions/checkout@v3.0.2 15 | - name: installation of node 16 | uses: actions/setup-node@v4 17 | with: 18 | node-version: 20 19 | registry-url: 'https://registry.npmjs.org' 20 | 21 | - name: publish 22 | run: | 23 | npm install 24 | npm publish 25 | env: 26 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 27 | 28 | -------------------------------------------------------------------------------- /example/src/StyleSheet.js: -------------------------------------------------------------------------------- 1 | import { StyleSheet } from 'react-native'; 2 | 3 | export default StyleSheet.create({ 4 | container: { 5 | flex: 1, 6 | justifyContent: 'center', 7 | alignItems: 'center', 8 | backgroundColor: '#f5f5f5', 9 | }, 10 | title: { 11 | fontSize: 24, 12 | fontWeight: 'bold', 13 | marginBottom: 20, 14 | color: 'black', 15 | }, 16 | box: { 17 | width: 200, 18 | height: 60, 19 | backgroundColor: '#6200ee', 20 | justifyContent: 'center', 21 | alignItems: 'center', 22 | borderRadius: 10, 23 | marginVertical: 10, 24 | }, 25 | text: { 26 | color: 'white', // Changed to white for better contrast 27 | fontSize: 18, 28 | }, 29 | }); 30 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "paths": { 5 | "@antmedia/react-native-ant-media": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "jsx": "react", 12 | "lib": ["esnext"], 13 | "module": "esnext", 14 | "moduleResolution": "node", 15 | "noFallthroughCasesInSwitch": true, 16 | "noImplicitReturns": true, 17 | "noImplicitUseStrict": false, 18 | "noStrictGenericChecks": false, 19 | "noUnusedLocals": false, 20 | "noUnusedParameters": false, 21 | "resolveJsonModule": true, 22 | "skipLibCheck": true, 23 | "strict": true, 24 | "target": "esnext" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /.github/workflows/build-for-android.yml: -------------------------------------------------------------------------------- 1 | name: Android Build 2 | 3 | on: push 4 | 5 | jobs: 6 | build-for-android: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v4 11 | - name: Setup node 12 | uses: actions/setup-node@v4 13 | with: 14 | node-version: 20 15 | registry-url: 'https://registry.npmjs.org' 16 | 17 | - name: Set up JDK 17 18 | uses: actions/setup-java@v4 19 | with: 20 | java-version: 17 21 | distribution: 'adopt' 22 | cache: 'gradle' 23 | 24 | 25 | - name: npm install for SDK 26 | run: npm install 27 | 28 | - name: npm install for example 29 | run: | 30 | cd example 31 | npm install 32 | cd .. 33 | 34 | - name: Build for Android 35 | run: | 36 | cd example 37 | npm run build:android 38 | cd .. 39 | -------------------------------------------------------------------------------- /scripts/bootstrap.js: -------------------------------------------------------------------------------- 1 | const os = require('os'); 2 | const path = require('path'); 3 | const child_process = require('child_process'); 4 | 5 | const root = path.resolve(__dirname, '..'); 6 | const args = process.argv.slice(2); 7 | const options = { 8 | cwd: process.cwd(), 9 | env: process.env, 10 | stdio: 'inherit', 11 | encoding: 'utf-8', 12 | }; 13 | 14 | if (os.type() === 'Windows_NT') { 15 | options.shell = true 16 | } 17 | 18 | let result; 19 | 20 | if (process.cwd() !== root || args.length) { 21 | // We're not in the root of the project, or additional arguments were passed 22 | // In this case, forward the command to `yarn` 23 | result = child_process.spawnSync('yarn', args, options); 24 | } else { 25 | // If `yarn` is run without arguments, perform bootstrap 26 | result = child_process.spawnSync('yarn', ['bootstrap'], options); 27 | } 28 | 29 | process.exitCode = result.status; 30 | -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExample/AppDelegate.mm: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #import 4 | 5 | @implementation AppDelegate 6 | 7 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 8 | { 9 | self.moduleName = @"ReactNativeAntMediaExample"; 10 | // You can add your custom initial props in the dictionary below. 11 | // They will be passed down to the ViewController used by React Native. 12 | self.initialProps = @{}; 13 | 14 | return [super application:application didFinishLaunchingWithOptions:launchOptions]; 15 | } 16 | 17 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 18 | { 19 | return [self bundleURL]; 20 | } 21 | 22 | - (NSURL *)bundleURL 23 | { 24 | #if DEBUG 25 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; 26 | #else 27 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 28 | #endif 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/reactnativeantmediaexample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativeantmediaexample 2 | 3 | import com.facebook.react.ReactActivity 4 | import com.facebook.react.ReactActivityDelegate 5 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled 6 | import com.facebook.react.defaults.DefaultReactActivityDelegate 7 | 8 | class MainActivity : ReactActivity() { 9 | 10 | /** 11 | * Returns the name of the main component registered from JavaScript. This is used to schedule 12 | * rendering of the component. 13 | */ 14 | override fun getMainComponentName(): String = "ReactNativeAntMediaExample" 15 | 16 | /** 17 | * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate] 18 | * which allows you to enable New Architecture with a single boolean flags [fabricEnabled] 19 | */ 20 | override fun createReactActivityDelegate(): ReactActivityDelegate = 21 | DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled) 22 | } 23 | 24 | -------------------------------------------------------------------------------- /.github/workflows/build-for-ios.yml: -------------------------------------------------------------------------------- 1 | name: iOS Build 2 | 3 | on: push 4 | 5 | jobs: 6 | build-for-ios: 7 | runs-on: macos-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v4 11 | - name: Set up Xcode 12 | uses: maxim-lobanov/setup-xcode@v1 13 | with: 14 | xcode-version: '15.4' 15 | - name: Setup node 16 | uses: actions/setup-node@v4 17 | with: 18 | node-version: 20 19 | registry-url: 'https://registry.npmjs.org' 20 | 21 | - name: Setup cocoapods 22 | uses: maxim-lobanov/setup-cocoapods@v1 23 | with: 24 | version: 1.15.2 25 | 26 | - name: npm install for SDK 27 | run: npm install 28 | 29 | - name: npm install for example 30 | run: | 31 | cd example 32 | npm install 33 | cd .. 34 | 35 | - name: Pod Install for iOS 36 | run: | 37 | cd example/ios 38 | pod install 39 | cd ../.. 40 | 41 | - name: Build for iOS Simulator 42 | run: | 43 | cd example 44 | npm run build:ios 45 | cd .. 46 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ant Media 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExample/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "scale" : "1x", 46 | "size" : "1024x1024" 47 | } 48 | ], 49 | "info" : { 50 | "author" : "xcode", 51 | "version" : 1 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExample/PrivacyInfo.xcprivacy: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSPrivacyAccessedAPITypes 6 | 7 | 8 | NSPrivacyAccessedAPIType 9 | NSPrivacyAccessedAPICategoryFileTimestamp 10 | NSPrivacyAccessedAPITypeReasons 11 | 12 | C617.1 13 | 14 | 15 | 16 | NSPrivacyAccessedAPIType 17 | NSPrivacyAccessedAPICategoryUserDefaults 18 | NSPrivacyAccessedAPITypeReasons 19 | 20 | CA92.1 21 | 22 | 23 | 24 | NSPrivacyAccessedAPIType 25 | NSPrivacyAccessedAPICategorySystemBootTime 26 | NSPrivacyAccessedAPITypeReasons 27 | 28 | 35F9.1 29 | 30 | 31 | 32 | NSPrivacyCollectedDataTypes 33 | 34 | NSPrivacyTracking 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![image](https://user-images.githubusercontent.com/54481799/95862105-16cb0e00-0d6b-11eb-9087-88888889825d.png) 2 | 3 | ## Basic overview 4 | 5 | Ant Media Server is a streaming engine software that provides adaptive, ultra low latency streaming by using 6 | WebRTC technology with ~0.5 seconds latency or low latency by using HLS or CMAF. Ant Media Server is highly scalable, 7 | running on-premises or on any cloud provider of your choice. 8 | 9 | ## About React Native SDK 10 | 11 | This repository includes Ant Media React Native SDK for WebRTC. 12 | 13 | If you have Ant Media Server Community Edition, you can only use WebRTC publishing feature. 14 | 15 | WebRTC play, Conference and Data Channel features are available in Ant Media Server Enterprise Edition. 16 | 17 | ## Integration 18 | 19 | In order to integrate React Native SDK to your project, please follow [this link](https://antmedia.io/docs/guides/developer-sdk-and-api/sdk-integration/react-native-sdk/). 20 | 21 | ## Support 22 | 23 | Have any questions about the React Native SDK? Visit our [Github Discussions](https://github.com/orgs/ant-media/discussions). 24 | 25 | ## Issues 26 | Create issues on the [Ant-Media-Server](https://github.com/ant-media/Ant-Media-Server/issues) 27 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Metro configuration 3 | * https://reactnative.dev/docs/metro 4 | * 5 | * @type {import('metro-config').MetroConfig} 6 | */ 7 | 8 | 9 | const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config'); 10 | 11 | const path = require('path'); 12 | const blacklist = require('metro-config/src/defaults/exclusionList'); 13 | const escape = require('escape-string-regexp'); 14 | const pak = require('../package.json'); 15 | 16 | const root = path.resolve(__dirname, '..'); 17 | 18 | const modules = Object.keys({ 19 | ...pak.peerDependencies, 20 | }); 21 | 22 | const config = { 23 | projectRoot: __dirname, 24 | watchFolders: [root], 25 | 26 | // We need to make sure that only one version is loaded for peerDependencies 27 | // So we blacklist them at the root, and alias them to the versions in example's node_modules 28 | resolver: { 29 | blacklistRE: blacklist( 30 | modules.map( 31 | (m) => 32 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) 33 | ) 34 | ), 35 | 36 | extraNodeModules: modules.reduce((acc, name) => { 37 | acc[name] = path.join(__dirname, 'node_modules', name); 38 | return acc; 39 | }, {}), 40 | }, 41 | }; 42 | 43 | module.exports = mergeConfig(getDefaultConfig(__dirname), config); -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | # Resolve react_native_pods.rb with node to allow for hoisting 2 | require Pod::Executable.execute_command('node', ['-p', 3 | 'require.resolve( 4 | "react-native/scripts/react_native_pods.rb", 5 | {paths: [process.argv[1]]}, 6 | )', __dir__]).strip 7 | 8 | platform :ios, min_ios_version_supported 9 | prepare_react_native_project! 10 | 11 | linkage = ENV['USE_FRAMEWORKS'] 12 | if linkage != nil 13 | Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green 14 | use_frameworks! :linkage => linkage.to_sym 15 | end 16 | 17 | target 'ReactNativeAntMediaExample' do 18 | config = use_native_modules! 19 | 20 | use_react_native!( 21 | :path => config[:reactNativePath], 22 | # An absolute path to your application root. 23 | :app_path => "#{Pod::Config.instance.installation_root}/.." 24 | ) 25 | 26 | target 'ReactNativeAntMediaExampleTests' do 27 | inherit! :complete 28 | # Pods for testing 29 | end 30 | 31 | post_install do |installer| 32 | # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202 33 | react_native_post_install( 34 | installer, 35 | config[:reactNativePath], 36 | :mac_catalyst_enabled => false, 37 | # :ccache_enabled => true 38 | ) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { NavigationContainer } from '@react-navigation/native'; 3 | import { createStackNavigator } from '@react-navigation/stack'; 4 | import MainScreen from './MainScreen'; 5 | import AppScreen from './App'; 6 | 7 | import Publish from './Publish'; 8 | import Chat from './Chat'; 9 | import Peer from './Peer'; 10 | import Conference from './Conference'; 11 | import Play from './Play'; 12 | 13 | export type RootStackParamList = { 14 | MainScreen: undefined; 15 | AppScreen: undefined; 16 | Play: undefined; 17 | Peer: undefined; 18 | Conference: undefined; 19 | }; 20 | 21 | const Stack = createStackNavigator(); 22 | 23 | const App: React.FC = () => { 24 | return ( 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | ); 37 | }; 38 | 39 | export default App; 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | **/.xcode.env.local 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | *.hprof 33 | .cxx/ 34 | *.keystore 35 | !debug.keystore 36 | 37 | # node.js 38 | # 39 | node_modules/ 40 | npm-debug.log 41 | yarn-error.log 42 | 43 | # fastlane 44 | # 45 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 46 | # screenshots whenever they are needed. 47 | # For more information about the recommended setup visit: 48 | # https://docs.fastlane.tools/best-practices/source-control/ 49 | 50 | **/fastlane/report.xml 51 | **/fastlane/Preview.html 52 | **/fastlane/screenshots 53 | **/fastlane/test_output 54 | 55 | # Bundle artifact 56 | *.jsbundle 57 | 58 | # Ruby / CocoaPods 59 | **/Pods/ 60 | /vendor/bundle/ 61 | 62 | # Temporary files created by Metro to check the health of the file watcher 63 | .metro-health-check* 64 | 65 | # testing 66 | /coverage 67 | 68 | # Yarn 69 | .yarn/* 70 | !.yarn/patches 71 | !.yarn/plugins 72 | !.yarn/releases 73 | !.yarn/sdks 74 | !.yarn/versions 75 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 22 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /example/android/app/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | THIS_DIR := $(call my-dir) 2 | 3 | include $(REACT_ANDROID_DIR)/Android-prebuilt.mk 4 | 5 | # If you wish to add a custom TurboModule or Fabric component in your app you 6 | # will have to include the following autogenerated makefile. 7 | # include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk 8 | include $(CLEAR_VARS) 9 | 10 | LOCAL_PATH := $(THIS_DIR) 11 | 12 | # You can customize the name of your application .so file here. 13 | LOCAL_MODULE := reactnativeantmediaexample_appmodules 14 | 15 | LOCAL_C_INCLUDES := $(LOCAL_PATH) 16 | LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) 17 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) 18 | 19 | # If you wish to add a custom TurboModule or Fabric component in your app you 20 | # will have to uncomment those lines to include the generated source 21 | # files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni) 22 | # 23 | # LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni 24 | # LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) 25 | # LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni 26 | 27 | # Here you should add any native library you wish to depend on. 28 | LOCAL_SHARED_LIBRARIES := \ 29 | libfabricjni \ 30 | libfbjni \ 31 | libfolly_futures \ 32 | libfolly_json \ 33 | libglog \ 34 | libjsi \ 35 | libreact_codegen_rncore \ 36 | libreact_debug \ 37 | libreact_nativemodule_core \ 38 | libreact_render_componentregistry \ 39 | libreact_render_core \ 40 | libreact_render_debug \ 41 | libreact_render_graphics \ 42 | librrc_view \ 43 | libruntimeexecutor \ 44 | libturbomodulejsijni \ 45 | libyoga 46 | 47 | LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall 48 | 49 | include $(BUILD_SHARED_LIBRARY) 50 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/reactnativeantmediaexample/MainApplication.kt: -------------------------------------------------------------------------------- 1 | package com.reactnativeantmediaexample 2 | 3 | import android.app.Application 4 | import com.facebook.react.PackageList 5 | import com.facebook.react.ReactApplication 6 | import com.facebook.react.ReactHost 7 | import com.facebook.react.ReactNativeHost 8 | import com.facebook.react.ReactPackage 9 | import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load 10 | import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost 11 | import com.facebook.react.defaults.DefaultReactNativeHost 12 | import com.facebook.soloader.SoLoader 13 | 14 | class MainApplication : Application(), ReactApplication { 15 | 16 | override val reactNativeHost: ReactNativeHost = 17 | object : DefaultReactNativeHost(this) { 18 | override fun getPackages(): List = 19 | PackageList(this).packages.apply { 20 | // Packages that cannot be autolinked yet can be added manually here, for example: 21 | // add(MyReactNativePackage()) 22 | } 23 | 24 | override fun getJSMainModuleName(): String = "index" 25 | 26 | override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG 27 | 28 | override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED 29 | override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED 30 | } 31 | 32 | override val reactHost: ReactHost 33 | get() = getDefaultReactHost(applicationContext, reactNativeHost) 34 | 35 | override fun onCreate() { 36 | super.onCreate() 37 | SoLoader.init(this, false) 38 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 39 | // If you opted-in for the New Architecture, we load the native entry point for this app. 40 | load() 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m 13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | 25 | # Use this property to specify which architecture you want to build. 26 | # You can also override it from the CLI using 27 | # ./gradlew -PreactNativeArchitectures=x86_64 28 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 29 | 30 | # Use this property to enable support to the new architecture. 31 | # This will allow you to use TurboModules and the Fabric render in 32 | # your application. You should enable this flag either if you want 33 | # to write custom TurboModules/Fabric components OR use libraries that 34 | # are providing them. 35 | newArchEnabled=false 36 | 37 | # Use this property to enable or disable the Hermes JS engine. 38 | # If set to false, you will be using JSC instead. 39 | hermesEnabled=true 40 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@antmedia/react-native-ant-media-example", 3 | "description": "Example app for @antmedia/react-native-ant-media", 4 | "version": "0.0.1", 5 | "private": true, 6 | "scripts": { 7 | "android": "react-native run-android", 8 | "ios": "react-native run-ios", 9 | "lint": "eslint .", 10 | "start": "react-native start", 11 | "build:android": "react-native build-android --mode Debug", 12 | "build:ios": "react-native build-ios --mode Debug", 13 | "clean:ios": "rm -rf ios/build ios/Pods ios/Podfile.lock && cd ios && pod deintegrate && pod install && cd ..", 14 | "clean:android": "cd android && ./gradlew clean && cd ..", 15 | "test": "jest" 16 | }, 17 | "dependencies": { 18 | "react": "18.3.1", 19 | "react-native": "0.75.2", 20 | "react-native-gesture-handler": "^2.24.0", 21 | "react-native-incall-manager": "^4.2.0", 22 | "react-native-safe-area-context": "^5.3.0", 23 | "react-native-screens": "^4.9.1", 24 | "react-native-vector-icons": "^10.1.0", 25 | "react-native-webrtc": "^124.0.4" 26 | }, 27 | "devDependencies": { 28 | "@babel/core": "^7.20.0", 29 | "@babel/preset-env": "^7.20.0", 30 | "@babel/runtime": "^7.20.0", 31 | "@react-native/babel-preset": "0.75.2", 32 | "@react-native/eslint-config": "0.75.2", 33 | "@react-native/metro-config": "0.75.2", 34 | "@react-native/typescript-config": "0.75.2", 35 | "@react-navigation/native": "^7.0.15", 36 | "@react-navigation/stack": "^7.1.2", 37 | "@types/react": "^18.3.18", 38 | "@types/react-native": "^0.73.0", 39 | "@types/react-native-vector-icons": "^6.4.18", 40 | "@types/react-test-renderer": "^18.0.0", 41 | "babel-jest": "^29.6.3", 42 | "babel-plugin-module-resolver": "^5.0.2", 43 | "eslint": "^8.19.0", 44 | "jest": "^29.6.3", 45 | "prettier": "2.8.8", 46 | "react-native-url-polyfill": "^2.0.0", 47 | "react-test-renderer": "18.3.1", 48 | "typescript": "5.0.4" 49 | }, 50 | "engines": { 51 | "node": ">=18" 52 | }, 53 | "packageManager": "yarn@3.6.4" 54 | } 55 | -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSCameraUsageDescription 6 | Allow Camera permission to publish WebRTC streams 7 | NSMicrophoneUsageDescription 8 | Allow Microphone permission to publish WebRTC streams 9 | 10 | CFBundleDevelopmentRegion 11 | en 12 | CFBundleDisplayName 13 | ReactNativeAntMediaExample 14 | CFBundleExecutable 15 | $(EXECUTABLE_NAME) 16 | CFBundleIdentifier 17 | $(PRODUCT_BUNDLE_IDENTIFIER) 18 | CFBundleInfoDictionaryVersion 19 | 6.0 20 | CFBundleName 21 | $(PRODUCT_NAME) 22 | CFBundlePackageType 23 | APPL 24 | CFBundleShortVersionString 25 | $(MARKETING_VERSION) 26 | CFBundleSignature 27 | ???? 28 | CFBundleVersion 29 | $(CURRENT_PROJECT_VERSION) 30 | LSRequiresIPhoneOS 31 | 32 | NSAppTransportSecurity 33 | 34 | 35 | NSAllowsArbitraryLoads 36 | 37 | NSAllowsLocalNetworking 38 | 39 | 40 | NSLocationWhenInUseUsageDescription 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | arm64 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | UIViewControllerBasedStatusBarAppearance 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /example/src/MainScreen.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { View, Text, TouchableOpacity, StyleSheet } from 'react-native'; 3 | import { StackNavigationProp } from '@react-navigation/stack'; 4 | 5 | type RootStackParamList = { 6 | MainScreen: undefined; 7 | Publish: undefined; 8 | Play: undefined; 9 | Peer: undefined; 10 | Conference: undefined; 11 | Chat: undefined; 12 | }; 13 | 14 | type MainScreenProps = { 15 | navigation: StackNavigationProp; 16 | }; 17 | 18 | const MainScreen: React.FC = ({ navigation }) => { 19 | return ( 20 | 21 | Sample Apps 22 | 23 | navigation.navigate('Publish')}> 24 | Publish 25 | 26 | 27 | navigation.navigate('Play')}> 28 | Play 29 | 30 | 31 | navigation.navigate('Peer')}> 32 | Peer 33 | 34 | 35 | navigation.navigate('Conference')}> 36 | Conference 37 | 38 | 39 | navigation.navigate('Chat')}> 40 | Chat 41 | 42 | 43 | 44 | ); 45 | }; 46 | 47 | const styles = StyleSheet.create({ 48 | container: { 49 | flex: 1, 50 | justifyContent: 'center', 51 | alignItems: 'center', 52 | backgroundColor: '#f5f5f5', 53 | }, 54 | title: { 55 | fontSize: 24, 56 | fontWeight: 'bold', 57 | marginBottom: 20, 58 | color: 'black', 59 | }, 60 | box: { 61 | width: 200, 62 | height: 60, 63 | backgroundColor: '#6200ee', 64 | justifyContent: 'center', 65 | alignItems: 'center', 66 | borderRadius: 10, 67 | marginVertical: 10, 68 | }, 69 | text: { 70 | color: 'white', 71 | fontSize: 18, 72 | }, 73 | }); 74 | 75 | export default MainScreen; 76 | -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExampleTests/ReactNativeAntMediaExampleTests.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import 6 | 7 | #define TIMEOUT_SECONDS 600 8 | #define TEXT_TO_LOOK_FOR @"Welcome to React" 9 | 10 | @interface ReactNativeAntMediaExampleTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation ReactNativeAntMediaExampleTests 15 | 16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL (^)(UIView *view))test 17 | { 18 | if (test(view)) { 19 | return YES; 20 | } 21 | for (UIView *subview in [view subviews]) { 22 | if ([self findSubviewInView:subview matching:test]) { 23 | return YES; 24 | } 25 | } 26 | return NO; 27 | } 28 | 29 | - (void)testRendersWelcomeScreen 30 | { 31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 33 | BOOL foundElement = NO; 34 | 35 | __block NSString *redboxError = nil; 36 | #ifdef DEBUG 37 | RCTSetLogFunction( 38 | ^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 39 | if (level >= RCTLogLevelError) { 40 | redboxError = message; 41 | } 42 | }); 43 | #endif 44 | 45 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 46 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 47 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 48 | 49 | foundElement = [self findSubviewInView:vc.view 50 | matching:^BOOL(UIView *view) { 51 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 52 | return YES; 53 | } 54 | return NO; 55 | }]; 56 | } 57 | 58 | #ifdef DEBUG 59 | RCTSetLogFunction(RCTDefaultLogFunction); 60 | #endif 61 | 62 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 63 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: circleci/node:10 7 | working_directory: ~/project 8 | 9 | commands: 10 | attach_project: 11 | steps: 12 | - attach_workspace: 13 | at: ~/project 14 | 15 | jobs: 16 | install-dependencies: 17 | executor: default 18 | steps: 19 | - checkout 20 | - attach_project 21 | - restore_cache: 22 | keys: 23 | - dependencies-{{ checksum "package.json" }} 24 | - dependencies- 25 | - restore_cache: 26 | keys: 27 | - dependencies-example-{{ checksum "example/package.json" }} 28 | - dependencies-example- 29 | - run: 30 | name: Install dependencies 31 | command: | 32 | yarn install --cwd example --frozen-lockfile 33 | yarn install --frozen-lockfile 34 | - save_cache: 35 | key: dependencies-{{ checksum "package.json" }} 36 | paths: node_modules 37 | - save_cache: 38 | key: dependencies-example-{{ checksum "example/package.json" }} 39 | paths: example/node_modules 40 | - persist_to_workspace: 41 | root: . 42 | paths: . 43 | 44 | lint: 45 | executor: default 46 | steps: 47 | - attach_project 48 | - run: 49 | name: Lint files 50 | command: | 51 | yarn lint 52 | 53 | typescript: 54 | executor: default 55 | steps: 56 | - attach_project 57 | - run: 58 | name: Typecheck files 59 | command: | 60 | yarn typescript 61 | 62 | unit-tests: 63 | executor: default 64 | steps: 65 | - attach_project 66 | - run: 67 | name: Run unit tests 68 | command: | 69 | yarn test --coverage 70 | - store_artifacts: 71 | path: coverage 72 | destination: coverage 73 | 74 | build-package: 75 | executor: default 76 | steps: 77 | - attach_project 78 | - run: 79 | name: Build package 80 | command: | 81 | yarn prepare 82 | 83 | workflows: 84 | build-and-test: 85 | jobs: 86 | - install-dependencies 87 | - lint: 88 | requires: 89 | - install-dependencies 90 | - typescript: 91 | requires: 92 | - install-dependencies 93 | - unit-tests: 94 | requires: 95 | - install-dependencies 96 | - build-package: 97 | requires: 98 | - install-dependencies 99 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 1>&2 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 48 | echo. 1>&2 49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 50 | echo location of your Java installation. 1>&2 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 1>&2 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 62 | echo. 1>&2 63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 64 | echo location of your Java installation. 1>&2 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExample.xcodeproj/xcshareddata/xcschemes/ReactNativeAntMediaExample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /example/src/Play.tsx: -------------------------------------------------------------------------------- 1 | import React, {useCallback, useRef, useState, useEffect} from 'react'; 2 | 3 | import { 4 | StyleSheet, 5 | View, 6 | SafeAreaView, 7 | TouchableOpacity, 8 | Text, 9 | } from 'react-native'; 10 | import {useAntMedia, rtc_view} from '@antmedia/react-native-ant-media'; 11 | 12 | export default function App() { 13 | var defaultStreamName = 'stream1'; 14 | const webSocketUrl = 'ws://test.antmedia.io:5080/WebRTCAppEE/websocket'; 15 | //or webSocketUrl: 'wss://server.com:5443/WebRTCAppEE/websocket', 16 | 17 | const streamNameRef = useRef(defaultStreamName); 18 | const [remoteMedia, setRemoteStream] = useState(''); 19 | const [isPlaying, setIsPlaying] = useState(false); 20 | 21 | const adaptor = useAntMedia({ 22 | url: webSocketUrl, 23 | mediaConstraints: { 24 | audio: true, 25 | video: { 26 | width: 640, 27 | height: 480, 28 | frameRate: 30, 29 | facingMode: 'front', 30 | }, 31 | }, 32 | callback(command: any, data: any) { 33 | switch (command) { 34 | case 'pong': 35 | break; 36 | case 'play_started': 37 | console.log('play_started'); 38 | setIsPlaying(true); 39 | break; 40 | case 'play_finished': 41 | console.log('play_finished'); 42 | 43 | setIsPlaying(false); 44 | setRemoteStream(''); 45 | break; 46 | case "newStreamAvailable": 47 | if(data.streamId == streamNameRef.current) 48 | setRemoteStream(data.stream.toURL()); 49 | break; 50 | default: 51 | console.log(command); 52 | break; 53 | } 54 | }, 55 | callbackError: (err: any, data: any) => { 56 | console.error('callbackError', err, data); 57 | }, 58 | peer_connection_config: { 59 | iceServers: [ 60 | { 61 | url: 'stun:stun.l.google.com:19302', 62 | }, 63 | ], 64 | }, 65 | debug: true, 66 | playMode: true, 67 | }); 68 | 69 | 70 | 71 | const handlePlay = useCallback(() => { 72 | if (!adaptor) { 73 | return; 74 | } 75 | 76 | adaptor.play(streamNameRef.current); 77 | }, [adaptor]); 78 | 79 | const handleStop = useCallback(() => { 80 | if (!adaptor) { 81 | return; 82 | } 83 | adaptor.stop(streamNameRef.current); 84 | }, [adaptor]); 85 | 86 | return ( 87 | 88 | 89 | Ant Media WebRTC Play 90 | {!isPlaying ? ( 91 | <> 92 | 93 | Start Playing 94 | 95 | 96 | ) : ( 97 | <> 98 | {remoteMedia ? ( 99 | <>{rtc_view(remoteMedia, styles.streamPlayer)} 100 | ) : ( 101 | <> 102 | )} 103 | 104 | Stop Playing 105 | 106 | 107 | )} 108 | 109 | 110 | ); 111 | } 112 | 113 | const styles = StyleSheet.create({ 114 | container: { 115 | flex: 1, 116 | alignItems: 'center', 117 | justifyContent: 'center', 118 | ackgroundColor: '#f5f5f5', 119 | }, 120 | box: { 121 | alignSelf: 'center', 122 | width: '80%', 123 | height: '80%', 124 | }, 125 | streamPlayer: { 126 | width: '100%', 127 | height: '80%', 128 | alignSelf: 'center', 129 | }, 130 | button: { 131 | alignItems: 'center', 132 | backgroundColor: '#DDDDDD', 133 | padding: 10, 134 | }, 135 | startButton: { 136 | alignItems: 'center', 137 | backgroundColor: '#AAAAAA', 138 | padding: 10, 139 | top: 400, 140 | }, 141 | heading: { 142 | alignSelf: 'center', 143 | color: 'black' 144 | }, 145 | }); 146 | -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExample/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@antmedia/react-native-ant-media", 3 | "version": "1.11.1", 4 | "description": "Ant Media Server WebRTC React Native SDK and Reference Project", 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 | "antmedia-react-native-ant-media.podspec", 17 | "!lib/typescript/example", 18 | "!android/build", 19 | "!ios/build", 20 | "!**/__tests__", 21 | "!**/__fixtures__", 22 | "!**/__mocks__" 23 | ], 24 | "scripts": { 25 | "test": "jest", 26 | "typescript": "tsc --noEmit", 27 | "lint": "eslint \"**/*.{js,ts,tsx}\"", 28 | "prepare": "bob build", 29 | "release": "release-it", 30 | "example": "yarn --cwd example", 31 | "pods": "cd example && pod-install --quiet", 32 | "bootstrap": "yarn example && yarn && yarn pods" 33 | }, 34 | "keywords": [ 35 | "react-native", 36 | "ios", 37 | "android" 38 | ], 39 | "repository": "https://github.com/ant-media/WebRTC-React-Native-SDK", 40 | "author": "ant-media", 41 | "license": "MIT", 42 | "bugs": { 43 | "url": "https://github.com/ant-media/WebRTC-React-Native-SDK/issues" 44 | }, 45 | "homepage": "https://github.com/ant-media/WebRTC-React-Native-SDK#readme", 46 | "publishConfig": { 47 | "registry": "https://registry.npmjs.org/" 48 | }, 49 | "devDependencies": { 50 | "@babel/core": "^7.20.0", 51 | "@babel/preset-env": "^7.20.0", 52 | "@babel/runtime": "^7.20.0", 53 | "@commitlint/config-conventional": "^11.0.0", 54 | "@react-native/babel-preset": "0.75.2", 55 | "@react-native/eslint-config": "0.75.2", 56 | "@react-native/metro-config": "0.75.2", 57 | "@react-native/typescript-config": "0.75.2", 58 | "@release-it/conventional-changelog": "^2.0.0", 59 | "@types/jest": "^26.0.0", 60 | "@types/react": "^18.2.6", 61 | "@types/react-test-renderer": "^18.0.0", 62 | "babel-jest": "^29.6.3", 63 | "commitlint": "^11.0.0", 64 | "eslint": "^8.19.0", 65 | "eslint-config-prettier": "^7.0.0", 66 | "eslint-plugin-prettier": "^3.1.3", 67 | "husky": "^6.0.0", 68 | "jest": "^29.6.3", 69 | "pod-install": "^0.1.0", 70 | "prettier": "2.8.8", 71 | "react": "18.3.1", 72 | "react-native": "0.75.2", 73 | "react-native-builder-bob": "^0.18.0", 74 | "react-native-url-polyfill": "^2.0.0", 75 | "react-test-renderer": "18.3.1", 76 | "release-it": "^14.2.2", 77 | "typescript": "5.0.4" 78 | }, 79 | "peerDependencies": { 80 | "react": "*", 81 | "react-native": "*" 82 | }, 83 | "jest": { 84 | "preset": "react-native", 85 | "modulePathIgnorePatterns": [ 86 | "/example/node_modules", 87 | "/lib/" 88 | ] 89 | }, 90 | "commitlint": { 91 | "extends": [ 92 | "@commitlint/config-conventional" 93 | ] 94 | }, 95 | "release-it": { 96 | "git": { 97 | "commitMessage": "chore: release ${version}", 98 | "tagName": "v${version}" 99 | }, 100 | "npm": { 101 | "publish": true 102 | }, 103 | "github": { 104 | "release": true 105 | }, 106 | "plugins": { 107 | "@release-it/conventional-changelog": { 108 | "preset": "angular" 109 | } 110 | } 111 | }, 112 | "eslintConfig": { 113 | "root": true, 114 | "extends": [ 115 | "@react-native", 116 | "prettier" 117 | ], 118 | "rules": { 119 | "prettier/prettier": [ 120 | "error", 121 | { 122 | "quoteProps": "consistent", 123 | "singleQuote": true, 124 | "tabWidth": 2, 125 | "trailingComma": "es5", 126 | "useTabs": false 127 | } 128 | ] 129 | } 130 | }, 131 | "eslintIgnore": [ 132 | "node_modules/", 133 | "lib/" 134 | ], 135 | "prettier": { 136 | "quoteProps": "consistent", 137 | "singleQuote": true, 138 | "tabWidth": 2, 139 | "trailingComma": "es5", 140 | "useTabs": false 141 | }, 142 | "react-native-builder-bob": { 143 | "source": "src", 144 | "output": "lib", 145 | "targets": [ 146 | "commonjs", 147 | "module", 148 | [ 149 | "typescript", 150 | { 151 | "project": "tsconfig.build.json" 152 | } 153 | ] 154 | ] 155 | }, 156 | "dependencies": { 157 | "react-native-webrtc": "124.0.4" 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /example/src/Peer.tsx: -------------------------------------------------------------------------------- 1 | import React, {useCallback, useRef, useState, useEffect} from 'react'; 2 | 3 | import { 4 | StyleSheet, 5 | View, 6 | SafeAreaView, 7 | TouchableOpacity, 8 | Text, 9 | } from 'react-native'; 10 | import {useAntMedia, rtc_view} from '@antmedia/react-native-ant-media'; 11 | 12 | import InCallManager from 'react-native-incall-manager'; 13 | 14 | export default function App() { 15 | var defaultStreamName = 'stream1'; 16 | const webSocketUrl = 'ws://test.antmedia.io:5080/WebRTCAppEE/websocket'; 17 | //or webSocketUrl: 'wss://server.com:5443/WebRTCAppEE/websocket', 18 | 19 | const [localMedia, setLocalMedia] = useState(''); 20 | const streamNameRef = useRef(defaultStreamName); 21 | const [remoteMedia, setRemoteStream] = useState(''); 22 | const [isPlaying, setIsPlaying] = useState(false); 23 | 24 | const adaptor = useAntMedia({ 25 | url: webSocketUrl, 26 | mediaConstraints: { 27 | audio: true, 28 | video: { 29 | width: 640, 30 | height: 480, 31 | frameRate: 30, 32 | facingMode: 'front', 33 | }, 34 | }, 35 | callback(command: any, data: any) { 36 | switch (command) { 37 | case 'pong': 38 | break; 39 | case 'joined': 40 | console.log('joined!'); 41 | setIsPlaying(true); 42 | break; 43 | case 'leaved': 44 | console.log('leaved!'); 45 | setIsPlaying(false); 46 | break; 47 | case "newStreamAvailable": 48 | if(data.streamId == streamNameRef.current) 49 | setRemoteStream(data.stream.toURL()); 50 | default: 51 | console.log(command); 52 | break; 53 | } 54 | }, 55 | callbackError: (err: any, data: any) => { 56 | console.error('callbackError', err, data); 57 | }, 58 | peer_connection_config: { 59 | iceServers: [ 60 | { 61 | url: 'stun:stun.l.google.com:19302', 62 | }, 63 | ], 64 | }, 65 | debug: true, 66 | }); 67 | 68 | useEffect(() => { 69 | if (adaptor) { 70 | const verify = () => { 71 | if ( 72 | adaptor.localStream.current && 73 | adaptor.localStream.current.toURL() 74 | ) { 75 | return setLocalMedia(adaptor.localStream.current.toURL()); 76 | } 77 | setTimeout(verify, 3000); 78 | }; 79 | verify(); 80 | } 81 | }, [adaptor]); 82 | 83 | useEffect(() => { 84 | if (localMedia && remoteMedia) { 85 | InCallManager.start({media: 'video'}); 86 | } 87 | }, [localMedia, remoteMedia]); 88 | 89 | const handleJoin = useCallback(() => { 90 | if (!adaptor) { 91 | return; 92 | } 93 | 94 | adaptor.join(streamNameRef.current); 95 | }, [adaptor]); 96 | 97 | const handleLeave = useCallback(() => { 98 | if (!adaptor) { 99 | return; 100 | } 101 | adaptor.leave(streamNameRef.current); 102 | InCallManager.stop(); 103 | setIsPlaying(false); 104 | }, [adaptor]); 105 | 106 | return ( 107 | 108 | 109 | Ant Media WebRTC Peer to Peer 110 | {localMedia ? <>{rtc_view(localMedia, styles.localPlayer)} : <>} 111 | {!isPlaying ? ( 112 | <> 113 | 114 | Join 115 | 116 | 117 | ) : ( 118 | <> 119 | {remoteMedia ? ( 120 | <>{rtc_view(remoteMedia, styles.streamPlayer)} 121 | ) : ( 122 | <> 123 | )} 124 | 125 | Leave 126 | 127 | 128 | )} 129 | 130 | 131 | ); 132 | } 133 | 134 | const styles = StyleSheet.create({ 135 | container: { 136 | flex: 1, 137 | alignItems: 'center', 138 | justifyContent: 'center', 139 | marginTop: 0, 140 | }, 141 | box: { 142 | alignSelf: 'center', 143 | width: '80%', 144 | height: '80%', 145 | marginTop: 0, 146 | }, 147 | streamPlayer: { 148 | zIndex: 1, 149 | width: '100%', 150 | height: '45%', 151 | alignSelf: 'center', 152 | backgroundColor: '#C5C5C5', 153 | marginBottom: 10, 154 | }, 155 | localPlayer: { 156 | width: '100%', 157 | height: '45%', 158 | alignSelf: 'center', 159 | backgroundColor: '#C5C5C5', 160 | marginBottom: 10, 161 | }, 162 | button: { 163 | alignItems: 'center', 164 | backgroundColor: '#AAAAAA', 165 | padding: 10, 166 | marginBottom: 10, 167 | }, 168 | heading: { 169 | alignSelf: 'center', 170 | marginBottom: 10, 171 | color: 'black' 172 | }, 173 | }); 174 | -------------------------------------------------------------------------------- /example/src/Chat.tsx: -------------------------------------------------------------------------------- 1 | import React, { useCallback, useRef, useState, useEffect } from 'react'; 2 | 3 | import { useAntMedia, rtc_view } from '@antmedia/react-native-ant-media'; 4 | 5 | import { 6 | StyleSheet, 7 | View, 8 | SafeAreaView, 9 | TouchableOpacity, 10 | Text, 11 | TextInput, 12 | ScrollView, 13 | } from 'react-native'; 14 | 15 | var defaultStreamName = 'streamTest1'; 16 | const webSocketUrl = 'ws://test.antmedia.io:5080/WebRTCAppEE/websocket'; 17 | //or webSocketUrl: 'wss://server.com:5443/WebRTCAppEE/websocket', 18 | 19 | const Chat: React.FC = () => { 20 | const [isPlaying, setIsPlaying] = useState(false); 21 | const [messages, setMessages] = useState([]); 22 | const [message, setMessage] = useState(''); 23 | const events = useRef<{ 24 | [key: string]: fn; 25 | }>({}); 26 | const adaptor = useAntMedia({ 27 | url: webSocketUrl, 28 | mediaConstraints: { 29 | video: false, 30 | audio: false, 31 | }, 32 | onlyDataChannel: true, 33 | callback(command, data) { 34 | switch (command) { 35 | case 'pong': 36 | break; 37 | case 'publish_started': 38 | console.log('publish_started'); 39 | setIsPlaying(true); 40 | break; 41 | case 'publish_finished': 42 | console.log('publish_finished'); 43 | setIsPlaying(false); 44 | break; 45 | case 'data_channel_opened': 46 | console.log('data_channel_opened inside'); 47 | break; 48 | case 'data_received': 49 | console.log(command, data.event.data); 50 | setMessages((msgs) => [...msgs, 'Received: ' + data.event.data]); 51 | break; 52 | default: 53 | console.log(command); 54 | break; 55 | } 56 | }, 57 | callbackError: (err, data) => { 58 | console.error('callbackError', err, data); 59 | }, 60 | peer_connection_config: { 61 | iceServers: [ 62 | { 63 | url: 'stun:stun.l.google.com:19302', 64 | }, 65 | ], 66 | }, 67 | debug: true, 68 | }); 69 | 70 | const handleConnect = useCallback(() => { 71 | if (!adaptor) { 72 | return; 73 | } 74 | adaptor.publish(defaultStreamName); 75 | }, [adaptor]); 76 | 77 | const sendMessage = useCallback(() => { 78 | if (!adaptor) { 79 | return; 80 | } 81 | adaptor.sendData(defaultStreamName, message); 82 | setMessages((msgs) => [...msgs, 'Sent: ' + message]); 83 | setMessage(''); 84 | console.log('send message', message); 85 | }, [message, adaptor]); 86 | 87 | const handleLeave = useCallback(() => { 88 | if (!adaptor) { 89 | return; 90 | } 91 | adaptor.stop(defaultStreamName); 92 | setIsPlaying(false); 93 | }, [adaptor]); 94 | 95 | useEffect(() => { 96 | events.current.handleLeave = handleLeave; 97 | }, [handleLeave]); 98 | 99 | useEffect(() => { 100 | const toLeave = events.current.handleLeave; 101 | return () => { 102 | if (defaultStreamName) { 103 | toLeave(); 104 | } 105 | }; 106 | }, []); 107 | 108 | return ( 109 | 110 | 111 | Ant Media WebRTC Data Channel 112 | 113 | {messages.map((i, k) => ( 114 | 115 | {i} 116 | 117 | ))} 118 | 119 | {!isPlaying ? ( 120 | <> 121 | 122 | Publish 123 | 124 | 125 | ) : ( 126 | <> 127 | 133 | 134 | Send 135 | 136 | 137 | Stop 138 | 139 | 140 | )} 141 | 142 | 143 | ); 144 | }; 145 | 146 | export default Chat; 147 | 148 | const styles = StyleSheet.create({ 149 | container: { 150 | flex: 1, 151 | alignItems: 'center', 152 | justifyContent: 'center', 153 | }, 154 | box: { 155 | alignSelf: 'center', 156 | width: '80%', 157 | height: '80%', 158 | }, 159 | InputView: { 160 | marginBottom: 10, 161 | }, 162 | TextContainer: { 163 | width: '100%', 164 | height: 'auto', 165 | flex: 1, 166 | marginTop: 5, 167 | marginBottom: 5, 168 | borderWidth: 1, 169 | borderColor: 'black', 170 | }, 171 | ChatText: { 172 | color: '#1a1a1a', 173 | position: 'relative', 174 | fontSize: 15, 175 | padding: 3, 176 | }, 177 | input: { 178 | width: '100%', 179 | height: 50, 180 | color: '#000', 181 | borderWidth: 1, 182 | marginBottom: 5, 183 | borderColor: '#232323', 184 | }, 185 | button: { 186 | alignItems: 'center', 187 | backgroundColor: '#AAAAAA', 188 | padding: 10, 189 | marginBottom: 10, 190 | }, 191 | heading: { 192 | alignSelf: 'center', 193 | color: 'black' 194 | }, 195 | }); 196 | -------------------------------------------------------------------------------- /example/src/Publish.tsx: -------------------------------------------------------------------------------- 1 | import React, {useCallback, useRef, useState, useEffect} from 'react'; 2 | 3 | import { 4 | StyleSheet, 5 | View, 6 | SafeAreaView, 7 | TouchableOpacity, 8 | Text, 9 | } from 'react-native'; 10 | import {useAntMedia, rtc_view} from '@antmedia/react-native-ant-media'; 11 | 12 | import InCallManager from 'react-native-incall-manager'; 13 | 14 | var publishStreamId:string; 15 | 16 | export default function App() { 17 | var defaultStreamName = 'streamTest1'; 18 | const webSocketUrl = 'ws://test.antmedia.io:5080/WebRTCAppEE/websocket'; 19 | //or webSocketUrl: 'wss://server.com:5443/WebRTCAppEE/websocket', 20 | 21 | const streamNameRef = useRef(defaultStreamName); 22 | const [localMedia, setLocalMedia] = useState(''); 23 | const [isPlaying, setIsPlaying] = useState(false); 24 | const [isWaitingWebsocketInit, setIsWaitingWebsocketInit] = useState(false); 25 | 26 | let localStream: any = useRef(null); 27 | 28 | useEffect(() => { 29 | console.log(' localStream.current ', localStream.current); 30 | }, []); 31 | 32 | const adaptor = useAntMedia({ 33 | url: webSocketUrl, 34 | mediaConstraints: { 35 | audio: true, 36 | video: { 37 | width: 640, 38 | height: 480, 39 | frameRate: 30, 40 | facingMode: 'front', 41 | }, 42 | }, 43 | callback(command: any, data: any) { 44 | switch (command) { 45 | case 'pong': 46 | break; 47 | case 'publish_started': 48 | console.log('publish_started'); 49 | setIsPlaying(true); 50 | break; 51 | case 'publish_finished': 52 | console.log('publish_finished'); 53 | InCallManager.stop(); 54 | setIsPlaying(false); 55 | adaptor.closeWebSocket(); 56 | break; 57 | case 'local_stream_updated': 58 | console.log('local_stream_updated'); 59 | verify(); 60 | break; 61 | case 'websocket_not_initialized': 62 | setIsWaitingWebsocketInit(true); 63 | adaptor.initialiseWebSocket(); 64 | break; 65 | case 'websocket_closed': 66 | console.log('websocket_closed'); 67 | adaptor.stopLocalStream(); 68 | break; 69 | default: 70 | console.log(command); 71 | break; 72 | } 73 | }, 74 | callbackError: (err: any, data: any) => { 75 | console.error('callbackError', err, data); 76 | }, 77 | peer_connection_config: { 78 | iceServers: [ 79 | { 80 | url: 'stun:stun.l.google.com:19302', 81 | }, 82 | ], 83 | }, 84 | debug: true, 85 | }); 86 | 87 | const generateRandomString = (length: number): string => { 88 | const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 89 | let result = ''; 90 | const charactersLength = characters.length; 91 | 92 | for (let i = 0; i < length; i++) { 93 | const randomIndex = Math.floor(Math.random() * charactersLength); 94 | result += characters.charAt(randomIndex); 95 | } 96 | return result; 97 | }; 98 | 99 | const verify = () => { 100 | console.log('in verify'); 101 | if (adaptor.localStream.current && adaptor.localStream.current.toURL()) { 102 | console.log('in verify if adaptor local stream', adaptor.localStream); 103 | if (isWaitingWebsocketInit) { 104 | setIsWaitingWebsocketInit(false); 105 | publishStreamId = generateRandomString(12); 106 | adaptor.publish(publishStreamId); 107 | } 108 | return setLocalMedia(adaptor.localStream.current.toURL()); 109 | } 110 | setTimeout(verify, 5000); 111 | }; 112 | 113 | useEffect(() => { 114 | verify(); 115 | }, [adaptor.localStream]); 116 | 117 | useEffect(() => { 118 | if (localMedia) { 119 | InCallManager.start({media: 'video'}); 120 | } 121 | }, [localMedia]); 122 | 123 | const handlePublish = useCallback(() => { 124 | if (!adaptor) { 125 | return; 126 | } 127 | publishStreamId = generateRandomString(12); 128 | adaptor.publish(publishStreamId); 129 | }, [adaptor]); 130 | 131 | const handleStop = useCallback(() => { 132 | if (!adaptor) { 133 | return; 134 | } 135 | adaptor.stop(publishStreamId); 136 | }, [adaptor]); 137 | 138 | return ( 139 | 140 | 141 | Ant Media WebRTC Publish 142 | {localMedia ? <>{rtc_view(localMedia, styles.streamPlayer, 'cover')} : <>} 143 | {!isPlaying ? ( 144 | <> 145 | 146 | Start Publishing 147 | 148 | 149 | ) : ( 150 | <> 151 | 152 | Stop Publishing 153 | 154 | 155 | )} 156 | 157 | 158 | ); 159 | } 160 | 161 | const styles = StyleSheet.create({ 162 | container: { 163 | flex: 1, 164 | alignItems: 'center', 165 | justifyContent: 'center', 166 | }, 167 | box: { 168 | alignSelf: 'center', 169 | width: '80%', 170 | height: '80%', 171 | }, 172 | streamPlayer: { 173 | width: '100%', 174 | height: '80%', 175 | alignSelf: 'center', 176 | }, 177 | button: { 178 | alignItems: 'center', 179 | backgroundColor: '#AAAAAA', 180 | padding: 10, 181 | marginBottom: 10, 182 | }, 183 | heading: { 184 | alignSelf: 'center', 185 | color: 'black' 186 | }, 187 | }); 188 | -------------------------------------------------------------------------------- /example/android/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | apply plugin: "org.jetbrains.kotlin.android" 3 | apply plugin: "com.facebook.react" 4 | 5 | /** 6 | * This is the configuration block to customize your React Native Android app. 7 | * By default you don't need to apply any configuration, just uncomment the lines you need. 8 | */ 9 | react { 10 | /* Folders */ 11 | // The root of your project, i.e. where "package.json" lives. Default is '..' 12 | // root = file("../") 13 | // The folder where the react-native NPM package is. Default is ../node_modules/react-native 14 | // reactNativeDir = file("../node_modules/react-native") 15 | // The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen 16 | // codegenDir = file("../node_modules/react-native-codegen") 17 | // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js 18 | // cliFile = file("../node_modules/react-native/cli.js") 19 | 20 | /* Variants */ 21 | // The list of variants to that are debuggable. For those we're going to 22 | // skip the bundling of the JS bundle and the assets. By default is just 'debug'. 23 | // If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants. 24 | // debuggableVariants = ["liteDebug", "prodDebug"] 25 | 26 | /* Bundling */ 27 | // A list containing the node command and its flags. Default is just 'node'. 28 | // nodeExecutableAndArgs = ["node"] 29 | // 30 | // The command to run when bundling. By default is 'bundle' 31 | // bundleCommand = "ram-bundle" 32 | // 33 | // The path to the CLI configuration file. Default is empty. 34 | // bundleConfig = file(../rn-cli.config.js) 35 | // 36 | // The name of the generated asset file containing your JS bundle 37 | // bundleAssetName = "MyApplication.android.bundle" 38 | // 39 | // The entry file for bundle generation. Default is 'index.android.js' or 'index.js' 40 | // entryFile = file("../js/MyApplication.android.js") 41 | // 42 | // A list of extra flags to pass to the 'bundle' commands. 43 | // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle 44 | // extraPackagerArgs = [] 45 | 46 | /* Hermes Commands */ 47 | // The hermes compiler command to run. By default it is 'hermesc' 48 | // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc" 49 | // 50 | // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map" 51 | // hermesFlags = ["-O", "-output-source-map"] 52 | 53 | autolinkLibrariesWithApp() 54 | } 55 | 56 | /** 57 | * Set this to true to create four separate APKs instead of one, 58 | * one for each native architecture. This is useful if you don't 59 | * use App Bundles (https://developer.android.com/guide/app-bundle/) 60 | * and want to have separate APKs to upload to the Play Store. 61 | */ 62 | def enableSeparateBuildPerCPUArchitecture = false 63 | 64 | /** 65 | * Set this to true to Run Proguard on Release builds to minify the Java bytecode. 66 | */ 67 | def enableProguardInReleaseBuilds = false 68 | 69 | /** 70 | * The preferred build flavor of JavaScriptCore (JSC) 71 | * 72 | * For example, to use the international variant, you can use: 73 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 74 | * 75 | * The international variant includes ICU i18n library and necessary data 76 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 77 | * give correct results when using with locales other than en-US. Note that 78 | * this variant is about 6MiB larger per architecture than default. 79 | */ 80 | def jscFlavor = 'org.webkit:android-jsc:+' 81 | 82 | /** 83 | * Private function to get the list of Native Architectures you want to build. 84 | * This reads the value from reactNativeArchitectures in your gradle.properties 85 | * file and works together with the --active-arch-only flag of react-native run-android. 86 | */ 87 | def reactNativeArchitectures() { 88 | def value = project.getProperties().get("reactNativeArchitectures") 89 | return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] 90 | } 91 | 92 | android { 93 | ndkVersion rootProject.ext.ndkVersion 94 | 95 | compileSdk rootProject.ext.compileSdkVersion 96 | 97 | namespace "com.reactnativeantmediaexample" 98 | defaultConfig { 99 | applicationId "com.reactnativeantmediaexample" 100 | minSdkVersion rootProject.ext.minSdkVersion 101 | targetSdkVersion rootProject.ext.targetSdkVersion 102 | versionCode 1 103 | versionName "1.0" 104 | } 105 | 106 | 107 | signingConfigs { 108 | debug { 109 | storeFile file('debug.keystore') 110 | storePassword 'android' 111 | keyAlias 'androiddebugkey' 112 | keyPassword 'android' 113 | } 114 | } 115 | buildTypes { 116 | debug { 117 | signingConfig signingConfigs.debug 118 | } 119 | release { 120 | // Caution! In production, you need to generate your own keystore file. 121 | // see https://reactnative.dev/docs/signed-apk-android. 122 | signingConfig signingConfigs.debug 123 | minifyEnabled enableProguardInReleaseBuilds 124 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 125 | } 126 | } 127 | 128 | 129 | } 130 | 131 | dependencies { 132 | // The version of react-native is set by the React Native Gradle Plugin 133 | implementation("com.facebook.react:react-android") 134 | 135 | if (hermesEnabled.toBoolean()) { 136 | implementation("com.facebook.react:hermes-android") 137 | } else { 138 | implementation jscFlavor 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. 4 | 5 | ## Development workflow 6 | 7 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn 11 | ``` 12 | 13 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development. 14 | 15 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app. 16 | 17 | To start the packager: 18 | 19 | ```sh 20 | yarn example start 21 | ``` 22 | 23 | To run the example app on Android: 24 | 25 | ```sh 26 | yarn example android 27 | ``` 28 | 29 | To run the example app on iOS: 30 | 31 | ```sh 32 | yarn example ios 33 | ``` 34 | 35 | To run the example app on Web: 36 | 37 | ```sh 38 | yarn example web 39 | ``` 40 | 41 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 42 | 43 | ```sh 44 | yarn typescript 45 | yarn lint 46 | ``` 47 | 48 | To fix formatting errors, run the following: 49 | 50 | ```sh 51 | yarn lint --fix 52 | ``` 53 | 54 | Remember to add tests for your change if possible. Run the unit tests by: 55 | 56 | ```sh 57 | yarn test 58 | ``` 59 | 60 | ### Commit message convention 61 | 62 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 63 | 64 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 65 | - `feat`: new features, e.g. add new method to the module. 66 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 67 | - `docs`: changes into documentation, e.g. add usage example for the module.. 68 | - `test`: adding or updating tests, e.g. add integration tests using detox. 69 | - `chore`: tooling changes, e.g. change CI config. 70 | 71 | Our pre-commit hooks verify that your commit message matches this format when committing. 72 | 73 | ### Linting and tests 74 | 75 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 76 | 77 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 78 | 79 | Our pre-commit hooks verify that the linter and tests pass when committing. 80 | 81 | ### Publishing to npm 82 | 83 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc. 84 | 85 | To publish new versions, run the following: 86 | 87 | ```sh 88 | yarn release 89 | ``` 90 | 91 | ### Scripts 92 | 93 | The `package.json` file contains various scripts for common tasks: 94 | 95 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 96 | - `yarn typescript`: type-check files with TypeScript. 97 | - `yarn lint`: lint files with ESLint. 98 | - `yarn test`: run unit tests with Jest. 99 | - `yarn example start`: start the Metro server for the example app. 100 | - `yarn example android`: run the example app on Android. 101 | - `yarn example ios`: run the example app on iOS. 102 | 103 | ### Sending a pull request 104 | 105 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github). 106 | 107 | When you're sending a pull request: 108 | 109 | - Prefer small pull requests focused on one change. 110 | - Verify that linters and tests are passing. 111 | - Review the documentation to make sure it looks good. 112 | - Follow the pull request template when opening a pull request. 113 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 114 | 115 | ## Code of Conduct 116 | 117 | ### Our Pledge 118 | 119 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 120 | 121 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 122 | 123 | ### Our Standards 124 | 125 | Examples of behavior that contributes to a positive environment for our community include: 126 | 127 | - Demonstrating empathy and kindness toward other people 128 | - Being respectful of differing opinions, viewpoints, and experiences 129 | - Giving and gracefully accepting constructive feedback 130 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 131 | - Focusing on what is best not just for us as individuals, but for the overall community 132 | 133 | Examples of unacceptable behavior include: 134 | 135 | - The use of sexualized language or imagery, and sexual attention or 136 | advances of any kind 137 | - Trolling, insulting or derogatory comments, and personal or political attacks 138 | - Public or private harassment 139 | - Publishing others' private information, such as a physical or email 140 | address, without their explicit permission 141 | - Other conduct which could reasonably be considered inappropriate in a 142 | professional setting 143 | 144 | ### Enforcement Responsibilities 145 | 146 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 147 | 148 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 149 | 150 | ### Scope 151 | 152 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 153 | 154 | ### Enforcement 155 | 156 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. 157 | 158 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 159 | 160 | ### Enforcement Guidelines 161 | 162 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 163 | 164 | #### 1. Correction 165 | 166 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 167 | 168 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 169 | 170 | #### 2. Warning 171 | 172 | **Community Impact**: A violation through a single incident or series of actions. 173 | 174 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 175 | 176 | #### 3. Temporary Ban 177 | 178 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 179 | 180 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 181 | 182 | #### 4. Permanent Ban 183 | 184 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 185 | 186 | **Consequence**: A permanent ban from any sort of public interaction within the community. 187 | 188 | ### Attribution 189 | 190 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 191 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 192 | 193 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 194 | 195 | [homepage]: https://www.contributor-covenant.org 196 | 197 | For answers to common questions about this code of conduct, see the FAQ at 198 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 199 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /example/src/Conference.tsx: -------------------------------------------------------------------------------- 1 | import React, { useCallback, useRef, useState, useEffect } from 'react'; 2 | 3 | import { 4 | View, 5 | Platform, 6 | StyleSheet, 7 | TouchableOpacity, 8 | Text, 9 | ScrollView, 10 | SafeAreaView, 11 | } from 'react-native'; 12 | import { useAntMedia, rtc_view } from '@antmedia/react-native-ant-media'; 13 | import Icon from 'react-native-vector-icons/Ionicons'; 14 | import { DeviceEventEmitter } from 'react-native'; 15 | import InCallManager from 'react-native-incall-manager'; 16 | 17 | var publishStreamId: string; 18 | 19 | export default function Conference() { 20 | var defaultRoomName = 'room1'; 21 | const webSocketUrl = 'ws://test.antmedia.io:5080/WebRTCAppEE/websocket'; 22 | //or webSocketUrl: 'wss://server.com:5443/WebRTCAppEE/websocket', 23 | 24 | const [localMedia, setLocalMedia] = useState(''); 25 | const [isPublishing, setIsPublishing] = useState(false); 26 | const [isPlaying, setIsPlaying] = useState(false); 27 | const [roomId, setRoomId] = useState(defaultRoomName); 28 | const [remoteTracks, setremoteTracks] = useState([]); 29 | const [isMuted, setIsMuted] = useState(false); 30 | const [isCameraOpen, setIsCameraOpen] = useState(true); 31 | const [isWaitingWebsocketInit, setIsWaitingWebsocketInit] = useState(false); 32 | 33 | const adaptor = useAntMedia({ 34 | url: webSocketUrl, 35 | mediaConstraints: { 36 | audio: true, 37 | video: { 38 | width: 640, 39 | height: 480, 40 | frameRate: 30, 41 | facingMode: 'front', 42 | }, 43 | }, 44 | callback(command: any, data: any) { 45 | switch (command) { 46 | case 'initiated': 47 | console.log('initiated'); 48 | break; 49 | case 'pong': 50 | break; 51 | case 'publish_started': 52 | adaptor.play(roomId, undefined, roomId, []); 53 | setIsPlaying(true); 54 | setIsPublishing(true); 55 | break; 56 | case 'publish_finished': 57 | setIsPublishing(false); 58 | adaptor.closeWebSocket(); 59 | break; 60 | case 'local_stream_updated': 61 | console.log('local_stream_updated'); 62 | verify(); 63 | break; 64 | case 'websocket_not_initialized': 65 | setIsWaitingWebsocketInit(true); 66 | adaptor.initialiseWebSocket(); 67 | break; 68 | case 'websocket_closed': 69 | console.log('websocket_closed'); 70 | adaptor.stopLocalStream(); 71 | break; 72 | case 'play_finished': 73 | console.log('play_finished'); 74 | removeRemoteVideo(); 75 | break; 76 | case "newTrackAvailable": 77 | { 78 | var incomingTrackId = data.track.id.substring("ARDAMSx".length); 79 | 80 | if (incomingTrackId == roomId || incomingTrackId == publishStreamId) { 81 | return; 82 | } 83 | console.log("new track available with id ", incomingTrackId); 84 | 85 | setremoteTracks((prevTracks: any) => { 86 | const updatedTracks = { ...prevTracks, [data.track.id]: data }; 87 | return updatedTracks; 88 | }); 89 | 90 | data.stream.onremovetrack = (event: any) => { 91 | console.log("track is removed with id: " + event.track.id) 92 | removeRemoteVideo(event.track.id); 93 | } 94 | } 95 | break; 96 | case "data_received": 97 | console.log('data_received', data); 98 | handleNotificationEvent(data); 99 | break; 100 | case "available_devices": 101 | console.log('available_devices', data); 102 | break; 103 | default: 104 | break; 105 | } 106 | }, 107 | callbackError: (err: any, data: any) => { 108 | if (err === "no_active_streams_in_room" || err === "no_stream_exist") { 109 | // it throws this error when there is no stream in the room 110 | // so we shouldn't reset streams list 111 | } else { 112 | console.error('callbackError', err, data); 113 | } 114 | }, 115 | debug: true, 116 | }); 117 | 118 | const verify = () => { 119 | console.log('in verify'); 120 | if (adaptor.localStream.current && adaptor.localStream.current.toURL()) { 121 | console.log('in verify if adaptor local stream', adaptor.localStream); 122 | if (isWaitingWebsocketInit) { 123 | setIsWaitingWebsocketInit(false); 124 | publishStreamId = generateRandomString(12); 125 | adaptor.publish(publishStreamId, undefined, undefined, undefined, undefined, roomId, ""); 126 | } 127 | return setLocalMedia(adaptor.localStream.current.toURL()); 128 | } 129 | setTimeout(verify, 5000); 130 | }; 131 | 132 | const handleNotificationEvent = (notificationEvent: any) => { 133 | //var notificationEvent = JSON.parse(data); 134 | if (notificationEvent != null && typeof notificationEvent == "object") { 135 | var eventStreamId = notificationEvent.streamId; 136 | var eventType = notificationEvent.eventType; 137 | 138 | if (eventType == "VIDEO_TRACK_ASSIGNMENT_LIST") { 139 | var videoTrackAssignmentList = notificationEvent.payload; 140 | console.log("VIDEO_TRACK_ASSIGNMENT_LIST", videoTrackAssignmentList); 141 | } else if (eventType == "AUDIO_TRACK_ASSIGNMENT") { 142 | console.log("AUDIO_TRACK_ASSIGNMENT", notificationEvent.payload); 143 | } else if (eventType == "TRACK_LIST_UPDATED") { 144 | console.log("TRACK_LIST_UPDATED", notificationEvent.payload); 145 | adaptor.requestVideoTrackAssignments(roomId); 146 | } 147 | 148 | } 149 | }; 150 | 151 | const handleMic = useCallback(() => { 152 | if (adaptor) { 153 | (isMuted) ? adaptor.unmuteLocalMic() : adaptor.muteLocalMic(); 154 | setIsMuted(!isMuted); 155 | } 156 | }, [adaptor, isMuted]); 157 | 158 | const handleCamera = useCallback(() => { 159 | if (adaptor) { 160 | (isCameraOpen) ? adaptor.turnOffLocalCamera() : adaptor.turnOnLocalCamera(); 161 | setIsCameraOpen(!isCameraOpen); 162 | } 163 | }, [adaptor, isCameraOpen]); 164 | 165 | const handleConnect = useCallback(() => { 166 | if (adaptor) { 167 | publishStreamId = generateRandomString(12); 168 | adaptor.publish(publishStreamId, undefined, undefined, undefined, undefined, roomId, ""); 169 | } 170 | }, [adaptor, roomId]); 171 | 172 | const handleDisconnect = useCallback(() => { 173 | if (adaptor) { 174 | adaptor.stop(publishStreamId); 175 | adaptor.stop(roomId); 176 | removeRemoteVideo(); 177 | setIsPlaying(false); 178 | setIsPublishing(false); 179 | } 180 | }, [adaptor, roomId]); 181 | 182 | /* 183 | const handleRemoteAudio = useCallback((streamId: string) => { 184 | if (adaptor) { 185 | adaptor?.muteRemoteAudio(streamId, roomId); 186 | //adaptor?.unmuteRemoteAudio(streamId, roomId); 187 | } 188 | }, [adaptor]); 189 | */ 190 | 191 | const removeRemoteVideo = (streamId?: string) => { 192 | if (streamId != null || streamId != undefined) { 193 | setremoteTracks((prevTracks: any) => { 194 | const updatedTracks = { ...prevTracks }; 195 | if (updatedTracks[streamId]) { 196 | delete updatedTracks[streamId]; 197 | console.log('Deleting Remote Track:', streamId); 198 | return updatedTracks; 199 | } else { 200 | return prevTracks; 201 | } 202 | }); 203 | return; 204 | } 205 | console.info("clearing all the remote renderer", remoteTracks, streamId) 206 | setremoteTracks([]); 207 | }; 208 | 209 | useEffect(() => { 210 | if (localMedia && remoteTracks) { 211 | InCallManager.start({ media: 'video' }); 212 | DeviceEventEmitter.addListener("onAudioDeviceChanged", (event) => { 213 | console.log("onAudioDeviceChanged", event.availableAudioDeviceList); 214 | }); 215 | } 216 | }, [localMedia, remoteTracks]); 217 | 218 | const generateRandomString = (length: number): string => { 219 | const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; 220 | let result = ''; 221 | const charactersLength = characters.length; 222 | 223 | for (let i = 0; i < length; i++) { 224 | const randomIndex = Math.floor(Math.random() * charactersLength); 225 | result += characters.charAt(randomIndex); 226 | } 227 | return result; 228 | }; 229 | 230 | return ( 231 | 232 | 233 | Ant Media WebRTC Multi-track Conference 234 | Local Stream 235 | {localMedia ? <>{rtc_view(localMedia, styles.localPlayer)} : <>} 236 | {!isPlaying ? ( 237 | <> 238 | 239 | Join Room 240 | 241 | 242 | ) : ( 243 | <> 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | Remote Streams 253 | { 254 | 264 | {Object.values(remoteTracks).map((trackObj, index) => { 265 | //@ts-ignore 266 | console.log('index', index, trackObj.track.id); 267 | if (trackObj) 268 | return ( 269 | // @ts-ignore 270 | 271 | <>{ 272 | // @ts-ignore 273 | rtc_view(trackObj.track, styles.players) 274 | } 275 | {/* 276 | 277 | { 278 | // @ts-ignore 279 | handleRemoteAudio(trackObj.track.id.substring("ARDAMSx".length)) 280 | }} style={styles.roundButton}> 281 | 282 | 283 | 284 | */} 285 | 286 | ); 287 | })} 288 | 289 | } 290 | 291 | Leave Room 292 | 293 | 294 | )} 295 | 296 | 297 | 298 | ); 299 | } 300 | 301 | const styles = StyleSheet.create({ 302 | container: { 303 | flex: 1, 304 | alignItems: 'center', 305 | justifyContent: 'center', 306 | }, 307 | box: { 308 | alignSelf: 'center', 309 | width: '80%', 310 | height: '80%', 311 | }, 312 | players: { 313 | backgroundColor: '#DDDDDD', 314 | paddingVertical: 5, 315 | paddingHorizontal: 10, 316 | margin: 5, 317 | width: 150, 318 | height: 150, 319 | justifyContent: 'center', 320 | alignSelf: 'center', 321 | }, 322 | localPlayer: { 323 | backgroundColor: '#DDDDDD', 324 | borderRadius: 5, 325 | marginBottom: 5, 326 | height: 180, 327 | flexDirection: 'row', 328 | }, 329 | btnTxt: { 330 | color: 'black', 331 | }, 332 | button: { 333 | alignItems: 'center', 334 | justifyContent: 'center', 335 | backgroundColor: '#AAAAAA', 336 | padding: 10, 337 | width: '100%', 338 | marginTop: 20, 339 | }, 340 | heading: { 341 | alignSelf: 'center', 342 | marginBottom: 5, 343 | padding: 2, 344 | color: 'black' 345 | }, 346 | heading1: { 347 | alignSelf: 'center', 348 | marginTop: 20, 349 | color: 'black' 350 | }, 351 | roundButton: { 352 | alignItems: 'center', 353 | justifyContent: 'center', 354 | backgroundColor: '#AAAAAA', 355 | padding: 5, 356 | borderRadius: 25, // This will make the button round 357 | width: 30, // Diameter of the button 358 | height: 30, // Diameter of the button 359 | marginTop: 10, 360 | marginHorizontal: 10, 361 | }, 362 | }); 363 | -------------------------------------------------------------------------------- /example/ios/ReactNativeAntMediaExample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 54; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 00E356F31AD99517003FC87E /* ReactNativeAntMediaExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00E356F21AD99517003FC87E /* ReactNativeAntMediaExampleTests.m */; }; 11 | 0C80B921A6F3F58F76C31292 /* libPods-ReactNativeAntMediaExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-ReactNativeAntMediaExample.a */; }; 12 | 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; }; 13 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; }; 14 | 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; 15 | 2AD4DBB7933B1B501B42C76E /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = CC223FFB05656D595F69B6EF /* PrivacyInfo.xcprivacy */; }; 16 | 7699B88040F8A987B510C191 /* libPods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19F6CBCC0A4E27FBF8BF4A61 /* libPods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.a */; }; 17 | 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | 00E356F41AD99517003FC87E /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = 83CBB9F71A601CBA00E9B192 /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = 13B07F861A680F5B00A75B9A; 26 | remoteInfo = ReactNativeAntMediaExample; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | 00E356EE1AD99517003FC87E /* ReactNativeAntMediaExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ReactNativeAntMediaExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | 00E356F11AD99517003FC87E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | 00E356F21AD99517003FC87E /* ReactNativeAntMediaExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReactNativeAntMediaExampleTests.m; sourceTree = ""; }; 34 | 13B07F961A680F5B00A75B9A /* ReactNativeAntMediaExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ReactNativeAntMediaExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = ReactNativeAntMediaExample/AppDelegate.h; sourceTree = ""; }; 36 | 13B07FB01A68108700A75B9A /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = ReactNativeAntMediaExample/AppDelegate.mm; sourceTree = ""; }; 37 | 13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = ReactNativeAntMediaExample/Images.xcassets; sourceTree = ""; }; 38 | 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ReactNativeAntMediaExample/Info.plist; sourceTree = ""; }; 39 | 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = ReactNativeAntMediaExample/main.m; sourceTree = ""; }; 40 | 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = PrivacyInfo.xcprivacy; path = ReactNativeAntMediaExample/PrivacyInfo.xcprivacy; sourceTree = ""; }; 41 | 19F6CBCC0A4E27FBF8BF4A61 /* libPods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | 3B4392A12AC88292D35C810B /* Pods-ReactNativeAntMediaExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeAntMediaExample.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeAntMediaExample/Pods-ReactNativeAntMediaExample.debug.xcconfig"; sourceTree = ""; }; 43 | 5709B34CF0A7D63546082F79 /* Pods-ReactNativeAntMediaExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeAntMediaExample.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeAntMediaExample/Pods-ReactNativeAntMediaExample.release.xcconfig"; sourceTree = ""; }; 44 | 5B7EB9410499542E8C5724F5 /* Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.debug.xcconfig"; path = "Target Support Files/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.debug.xcconfig"; sourceTree = ""; }; 45 | 5DCACB8F33CDC322A6C60F78 /* libPods-ReactNativeAntMediaExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ReactNativeAntMediaExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 46 | 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = ReactNativeAntMediaExample/LaunchScreen.storyboard; sourceTree = ""; }; 47 | 89C6BE57DB24E9ADA2F236DE /* Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.release.xcconfig"; path = "Target Support Files/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.release.xcconfig"; sourceTree = ""; }; 48 | CC223FFB05656D595F69B6EF /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = ReactNativeAntMediaExample/PrivacyInfo.xcprivacy; sourceTree = ""; }; 49 | ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | 00E356EB1AD99517003FC87E /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | 7699B88040F8A987B510C191 /* libPods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.a in Frameworks */, 58 | ); 59 | runOnlyForDeploymentPostprocessing = 0; 60 | }; 61 | 13B07F8C1A680F5B00A75B9A /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | 0C80B921A6F3F58F76C31292 /* libPods-ReactNativeAntMediaExample.a in Frameworks */, 66 | ); 67 | runOnlyForDeploymentPostprocessing = 0; 68 | }; 69 | /* End PBXFrameworksBuildPhase section */ 70 | 71 | /* Begin PBXGroup section */ 72 | 00E356EF1AD99517003FC87E /* ReactNativeAntMediaExampleTests */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 00E356F21AD99517003FC87E /* ReactNativeAntMediaExampleTests.m */, 76 | 00E356F01AD99517003FC87E /* Supporting Files */, 77 | ); 78 | path = ReactNativeAntMediaExampleTests; 79 | sourceTree = ""; 80 | }; 81 | 00E356F01AD99517003FC87E /* Supporting Files */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 00E356F11AD99517003FC87E /* Info.plist */, 85 | ); 86 | name = "Supporting Files"; 87 | sourceTree = ""; 88 | }; 89 | 13B07FAE1A68108700A75B9A /* ReactNativeAntMediaExample */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 93 | 13B07FB01A68108700A75B9A /* AppDelegate.mm */, 94 | 13B07FB51A68108700A75B9A /* Images.xcassets */, 95 | 13B07FB61A68108700A75B9A /* Info.plist */, 96 | 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */, 97 | 13B07FB71A68108700A75B9A /* main.m */, 98 | 13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */, 99 | CC223FFB05656D595F69B6EF /* PrivacyInfo.xcprivacy */, 100 | ); 101 | name = ReactNativeAntMediaExample; 102 | sourceTree = ""; 103 | }; 104 | 2D16E6871FA4F8E400B85C8A /* Frameworks */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | ED297162215061F000B7C4FE /* JavaScriptCore.framework */, 108 | 5DCACB8F33CDC322A6C60F78 /* libPods-ReactNativeAntMediaExample.a */, 109 | 19F6CBCC0A4E27FBF8BF4A61 /* libPods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.a */, 110 | ); 111 | name = Frameworks; 112 | sourceTree = ""; 113 | }; 114 | 832341AE1AAA6A7D00B99B32 /* Libraries */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | ); 118 | name = Libraries; 119 | sourceTree = ""; 120 | }; 121 | 83CBB9F61A601CBA00E9B192 = { 122 | isa = PBXGroup; 123 | children = ( 124 | 13B07FAE1A68108700A75B9A /* ReactNativeAntMediaExample */, 125 | 832341AE1AAA6A7D00B99B32 /* Libraries */, 126 | 00E356EF1AD99517003FC87E /* ReactNativeAntMediaExampleTests */, 127 | 83CBBA001A601CBA00E9B192 /* Products */, 128 | 2D16E6871FA4F8E400B85C8A /* Frameworks */, 129 | BBD78D7AC51CEA395F1C20DB /* Pods */, 130 | ); 131 | indentWidth = 2; 132 | sourceTree = ""; 133 | tabWidth = 2; 134 | usesTabs = 0; 135 | }; 136 | 83CBBA001A601CBA00E9B192 /* Products */ = { 137 | isa = PBXGroup; 138 | children = ( 139 | 13B07F961A680F5B00A75B9A /* ReactNativeAntMediaExample.app */, 140 | 00E356EE1AD99517003FC87E /* ReactNativeAntMediaExampleTests.xctest */, 141 | ); 142 | name = Products; 143 | sourceTree = ""; 144 | }; 145 | BBD78D7AC51CEA395F1C20DB /* Pods */ = { 146 | isa = PBXGroup; 147 | children = ( 148 | 3B4392A12AC88292D35C810B /* Pods-ReactNativeAntMediaExample.debug.xcconfig */, 149 | 5709B34CF0A7D63546082F79 /* Pods-ReactNativeAntMediaExample.release.xcconfig */, 150 | 5B7EB9410499542E8C5724F5 /* Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.debug.xcconfig */, 151 | 89C6BE57DB24E9ADA2F236DE /* Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.release.xcconfig */, 152 | ); 153 | path = Pods; 154 | sourceTree = ""; 155 | }; 156 | /* End PBXGroup section */ 157 | 158 | /* Begin PBXNativeTarget section */ 159 | 00E356ED1AD99517003FC87E /* ReactNativeAntMediaExampleTests */ = { 160 | isa = PBXNativeTarget; 161 | buildConfigurationList = 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "ReactNativeAntMediaExampleTests" */; 162 | buildPhases = ( 163 | A55EABD7B0C7F3A422A6CC61 /* [CP] Check Pods Manifest.lock */, 164 | 00E356EA1AD99517003FC87E /* Sources */, 165 | 00E356EB1AD99517003FC87E /* Frameworks */, 166 | 00E356EC1AD99517003FC87E /* Resources */, 167 | C59DA0FBD6956966B86A3779 /* [CP] Embed Pods Frameworks */, 168 | F6A41C54EA430FDDC6A6ED99 /* [CP] Copy Pods Resources */, 169 | ); 170 | buildRules = ( 171 | ); 172 | dependencies = ( 173 | 00E356F51AD99517003FC87E /* PBXTargetDependency */, 174 | ); 175 | name = ReactNativeAntMediaExampleTests; 176 | productName = ReactNativeAntMediaExampleTests; 177 | productReference = 00E356EE1AD99517003FC87E /* ReactNativeAntMediaExampleTests.xctest */; 178 | productType = "com.apple.product-type.bundle.unit-test"; 179 | }; 180 | 13B07F861A680F5B00A75B9A /* ReactNativeAntMediaExample */ = { 181 | isa = PBXNativeTarget; 182 | buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ReactNativeAntMediaExample" */; 183 | buildPhases = ( 184 | C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */, 185 | 13B07F871A680F5B00A75B9A /* Sources */, 186 | 13B07F8C1A680F5B00A75B9A /* Frameworks */, 187 | 13B07F8E1A680F5B00A75B9A /* Resources */, 188 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */, 189 | 00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */, 190 | E235C05ADACE081382539298 /* [CP] Copy Pods Resources */, 191 | ); 192 | buildRules = ( 193 | ); 194 | dependencies = ( 195 | ); 196 | name = ReactNativeAntMediaExample; 197 | productName = ReactNativeAntMediaExample; 198 | productReference = 13B07F961A680F5B00A75B9A /* ReactNativeAntMediaExample.app */; 199 | productType = "com.apple.product-type.application"; 200 | }; 201 | /* End PBXNativeTarget section */ 202 | 203 | /* Begin PBXProject section */ 204 | 83CBB9F71A601CBA00E9B192 /* Project object */ = { 205 | isa = PBXProject; 206 | attributes = { 207 | LastUpgradeCheck = 1210; 208 | TargetAttributes = { 209 | 00E356ED1AD99517003FC87E = { 210 | CreatedOnToolsVersion = 6.2; 211 | TestTargetID = 13B07F861A680F5B00A75B9A; 212 | }; 213 | 13B07F861A680F5B00A75B9A = { 214 | LastSwiftMigration = 1120; 215 | }; 216 | }; 217 | }; 218 | buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "ReactNativeAntMediaExample" */; 219 | compatibilityVersion = "Xcode 12.0"; 220 | developmentRegion = en; 221 | hasScannedForEncodings = 0; 222 | knownRegions = ( 223 | en, 224 | Base, 225 | ); 226 | mainGroup = 83CBB9F61A601CBA00E9B192; 227 | productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; 228 | projectDirPath = ""; 229 | projectRoot = ""; 230 | targets = ( 231 | 13B07F861A680F5B00A75B9A /* ReactNativeAntMediaExample */, 232 | 00E356ED1AD99517003FC87E /* ReactNativeAntMediaExampleTests */, 233 | ); 234 | }; 235 | /* End PBXProject section */ 236 | 237 | /* Begin PBXResourcesBuildPhase section */ 238 | 00E356EC1AD99517003FC87E /* Resources */ = { 239 | isa = PBXResourcesBuildPhase; 240 | buildActionMask = 2147483647; 241 | files = ( 242 | ); 243 | runOnlyForDeploymentPostprocessing = 0; 244 | }; 245 | 13B07F8E1A680F5B00A75B9A /* Resources */ = { 246 | isa = PBXResourcesBuildPhase; 247 | buildActionMask = 2147483647; 248 | files = ( 249 | 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */, 250 | 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, 251 | 2AD4DBB7933B1B501B42C76E /* PrivacyInfo.xcprivacy in Resources */, 252 | ); 253 | runOnlyForDeploymentPostprocessing = 0; 254 | }; 255 | /* End PBXResourcesBuildPhase section */ 256 | 257 | /* Begin PBXShellScriptBuildPhase section */ 258 | 00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = { 259 | isa = PBXShellScriptBuildPhase; 260 | buildActionMask = 2147483647; 261 | files = ( 262 | ); 263 | inputPaths = ( 264 | "$(SRCROOT)/.xcode.env.local", 265 | "$(SRCROOT)/.xcode.env", 266 | ); 267 | name = "Bundle React Native code and images"; 268 | outputPaths = ( 269 | ); 270 | runOnlyForDeploymentPostprocessing = 0; 271 | shellPath = /bin/sh; 272 | shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n"; 273 | }; 274 | 00EEFC60759A1932668264C0 /* [CP] Embed Pods Frameworks */ = { 275 | isa = PBXShellScriptBuildPhase; 276 | buildActionMask = 2147483647; 277 | files = ( 278 | ); 279 | inputFileListPaths = ( 280 | "${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample/Pods-ReactNativeAntMediaExample-frameworks-${CONFIGURATION}-input-files.xcfilelist", 281 | ); 282 | name = "[CP] Embed Pods Frameworks"; 283 | outputFileListPaths = ( 284 | "${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample/Pods-ReactNativeAntMediaExample-frameworks-${CONFIGURATION}-output-files.xcfilelist", 285 | ); 286 | runOnlyForDeploymentPostprocessing = 0; 287 | shellPath = /bin/sh; 288 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample/Pods-ReactNativeAntMediaExample-frameworks.sh\"\n"; 289 | showEnvVarsInLog = 0; 290 | }; 291 | A55EABD7B0C7F3A422A6CC61 /* [CP] Check Pods Manifest.lock */ = { 292 | isa = PBXShellScriptBuildPhase; 293 | buildActionMask = 2147483647; 294 | files = ( 295 | ); 296 | inputFileListPaths = ( 297 | ); 298 | inputPaths = ( 299 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 300 | "${PODS_ROOT}/Manifest.lock", 301 | ); 302 | name = "[CP] Check Pods Manifest.lock"; 303 | outputFileListPaths = ( 304 | ); 305 | outputPaths = ( 306 | "$(DERIVED_FILE_DIR)/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests-checkManifestLockResult.txt", 307 | ); 308 | runOnlyForDeploymentPostprocessing = 0; 309 | shellPath = /bin/sh; 310 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 311 | showEnvVarsInLog = 0; 312 | }; 313 | C38B50BA6285516D6DCD4F65 /* [CP] Check Pods Manifest.lock */ = { 314 | isa = PBXShellScriptBuildPhase; 315 | buildActionMask = 2147483647; 316 | files = ( 317 | ); 318 | inputFileListPaths = ( 319 | ); 320 | inputPaths = ( 321 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 322 | "${PODS_ROOT}/Manifest.lock", 323 | ); 324 | name = "[CP] Check Pods Manifest.lock"; 325 | outputFileListPaths = ( 326 | ); 327 | outputPaths = ( 328 | "$(DERIVED_FILE_DIR)/Pods-ReactNativeAntMediaExample-checkManifestLockResult.txt", 329 | ); 330 | runOnlyForDeploymentPostprocessing = 0; 331 | shellPath = /bin/sh; 332 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 333 | showEnvVarsInLog = 0; 334 | }; 335 | C59DA0FBD6956966B86A3779 /* [CP] Embed Pods Frameworks */ = { 336 | isa = PBXShellScriptBuildPhase; 337 | buildActionMask = 2147483647; 338 | files = ( 339 | ); 340 | inputFileListPaths = ( 341 | "${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests-frameworks-${CONFIGURATION}-input-files.xcfilelist", 342 | ); 343 | name = "[CP] Embed Pods Frameworks"; 344 | outputFileListPaths = ( 345 | "${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests-frameworks-${CONFIGURATION}-output-files.xcfilelist", 346 | ); 347 | runOnlyForDeploymentPostprocessing = 0; 348 | shellPath = /bin/sh; 349 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests-frameworks.sh\"\n"; 350 | showEnvVarsInLog = 0; 351 | }; 352 | E235C05ADACE081382539298 /* [CP] Copy Pods Resources */ = { 353 | isa = PBXShellScriptBuildPhase; 354 | buildActionMask = 2147483647; 355 | files = ( 356 | ); 357 | inputFileListPaths = ( 358 | "${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample/Pods-ReactNativeAntMediaExample-resources-${CONFIGURATION}-input-files.xcfilelist", 359 | ); 360 | name = "[CP] Copy Pods Resources"; 361 | outputFileListPaths = ( 362 | "${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample/Pods-ReactNativeAntMediaExample-resources-${CONFIGURATION}-output-files.xcfilelist", 363 | ); 364 | runOnlyForDeploymentPostprocessing = 0; 365 | shellPath = /bin/sh; 366 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample/Pods-ReactNativeAntMediaExample-resources.sh\"\n"; 367 | showEnvVarsInLog = 0; 368 | }; 369 | F6A41C54EA430FDDC6A6ED99 /* [CP] Copy Pods Resources */ = { 370 | isa = PBXShellScriptBuildPhase; 371 | buildActionMask = 2147483647; 372 | files = ( 373 | ); 374 | inputFileListPaths = ( 375 | "${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests-resources-${CONFIGURATION}-input-files.xcfilelist", 376 | ); 377 | name = "[CP] Copy Pods Resources"; 378 | outputFileListPaths = ( 379 | "${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests-resources-${CONFIGURATION}-output-files.xcfilelist", 380 | ); 381 | runOnlyForDeploymentPostprocessing = 0; 382 | shellPath = /bin/sh; 383 | shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests/Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests-resources.sh\"\n"; 384 | showEnvVarsInLog = 0; 385 | }; 386 | /* End PBXShellScriptBuildPhase section */ 387 | 388 | /* Begin PBXSourcesBuildPhase section */ 389 | 00E356EA1AD99517003FC87E /* Sources */ = { 390 | isa = PBXSourcesBuildPhase; 391 | buildActionMask = 2147483647; 392 | files = ( 393 | 00E356F31AD99517003FC87E /* ReactNativeAntMediaExampleTests.m in Sources */, 394 | ); 395 | runOnlyForDeploymentPostprocessing = 0; 396 | }; 397 | 13B07F871A680F5B00A75B9A /* Sources */ = { 398 | isa = PBXSourcesBuildPhase; 399 | buildActionMask = 2147483647; 400 | files = ( 401 | 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */, 402 | 13B07FC11A68108700A75B9A /* main.m in Sources */, 403 | ); 404 | runOnlyForDeploymentPostprocessing = 0; 405 | }; 406 | /* End PBXSourcesBuildPhase section */ 407 | 408 | /* Begin PBXTargetDependency section */ 409 | 00E356F51AD99517003FC87E /* PBXTargetDependency */ = { 410 | isa = PBXTargetDependency; 411 | target = 13B07F861A680F5B00A75B9A /* ReactNativeAntMediaExample */; 412 | targetProxy = 00E356F41AD99517003FC87E /* PBXContainerItemProxy */; 413 | }; 414 | /* End PBXTargetDependency section */ 415 | 416 | /* Begin XCBuildConfiguration section */ 417 | 00E356F61AD99517003FC87E /* Debug */ = { 418 | isa = XCBuildConfiguration; 419 | baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.debug.xcconfig */; 420 | buildSettings = { 421 | BUNDLE_LOADER = "$(TEST_HOST)"; 422 | GCC_PREPROCESSOR_DEFINITIONS = ( 423 | "DEBUG=1", 424 | "$(inherited)", 425 | ); 426 | INFOPLIST_FILE = ReactNativeAntMediaExampleTests/Info.plist; 427 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 428 | LD_RUNPATH_SEARCH_PATHS = ( 429 | "$(inherited)", 430 | "@executable_path/Frameworks", 431 | "@loader_path/Frameworks", 432 | ); 433 | OTHER_LDFLAGS = ( 434 | "-ObjC", 435 | "-lc++", 436 | "$(inherited)", 437 | ); 438 | PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; 439 | PRODUCT_NAME = "$(TARGET_NAME)"; 440 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReactNativeAntMediaExample.app/ReactNativeAntMediaExample"; 441 | }; 442 | name = Debug; 443 | }; 444 | 00E356F71AD99517003FC87E /* Release */ = { 445 | isa = XCBuildConfiguration; 446 | baseConfigurationReference = 89C6BE57DB24E9ADA2F236DE /* Pods-ReactNativeAntMediaExample-ReactNativeAntMediaExampleTests.release.xcconfig */; 447 | buildSettings = { 448 | BUNDLE_LOADER = "$(TEST_HOST)"; 449 | COPY_PHASE_STRIP = NO; 450 | INFOPLIST_FILE = ReactNativeAntMediaExampleTests/Info.plist; 451 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 452 | LD_RUNPATH_SEARCH_PATHS = ( 453 | "$(inherited)", 454 | "@executable_path/Frameworks", 455 | "@loader_path/Frameworks", 456 | ); 457 | OTHER_LDFLAGS = ( 458 | "-ObjC", 459 | "-lc++", 460 | "$(inherited)", 461 | ); 462 | PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; 463 | PRODUCT_NAME = "$(TARGET_NAME)"; 464 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ReactNativeAntMediaExample.app/ReactNativeAntMediaExample"; 465 | }; 466 | name = Release; 467 | }; 468 | 13B07F941A680F5B00A75B9A /* Debug */ = { 469 | isa = XCBuildConfiguration; 470 | baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-ReactNativeAntMediaExample.debug.xcconfig */; 471 | buildSettings = { 472 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 473 | CLANG_ENABLE_MODULES = YES; 474 | CURRENT_PROJECT_VERSION = 1; 475 | ENABLE_BITCODE = NO; 476 | GCC_PREPROCESSOR_DEFINITIONS = ( 477 | "$(inherited)", 478 | "COCOAPODS=1", 479 | "USE_HERMES=1", 480 | ); 481 | INFOPLIST_FILE = ReactNativeAntMediaExample/Info.plist; 482 | LD_RUNPATH_SEARCH_PATHS = ( 483 | "$(inherited)", 484 | "@executable_path/Frameworks", 485 | ); 486 | MARKETING_VERSION = 1.0; 487 | OTHER_LDFLAGS = ( 488 | "$(inherited)", 489 | "-ObjC", 490 | "-lc++", 491 | ); 492 | PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; 493 | PRODUCT_NAME = ReactNativeAntMediaExample; 494 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 495 | SWIFT_VERSION = 5.0; 496 | VERSIONING_SYSTEM = "apple-generic"; 497 | }; 498 | name = Debug; 499 | }; 500 | 13B07F951A680F5B00A75B9A /* Release */ = { 501 | isa = XCBuildConfiguration; 502 | baseConfigurationReference = 5709B34CF0A7D63546082F79 /* Pods-ReactNativeAntMediaExample.release.xcconfig */; 503 | buildSettings = { 504 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 505 | CLANG_ENABLE_MODULES = YES; 506 | CURRENT_PROJECT_VERSION = 1; 507 | GCC_PREPROCESSOR_DEFINITIONS = ( 508 | "$(inherited)", 509 | "COCOAPODS=1", 510 | "USE_HERMES=1", 511 | ); 512 | INFOPLIST_FILE = ReactNativeAntMediaExample/Info.plist; 513 | LD_RUNPATH_SEARCH_PATHS = ( 514 | "$(inherited)", 515 | "@executable_path/Frameworks", 516 | ); 517 | MARKETING_VERSION = 1.0; 518 | OTHER_LDFLAGS = ( 519 | "$(inherited)", 520 | "-ObjC", 521 | "-lc++", 522 | ); 523 | PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; 524 | PRODUCT_NAME = ReactNativeAntMediaExample; 525 | SWIFT_VERSION = 5.0; 526 | VERSIONING_SYSTEM = "apple-generic"; 527 | }; 528 | name = Release; 529 | }; 530 | 83CBBA201A601CBA00E9B192 /* Debug */ = { 531 | isa = XCBuildConfiguration; 532 | buildSettings = { 533 | ALWAYS_SEARCH_USER_PATHS = NO; 534 | CC = ""; 535 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 536 | CLANG_CXX_LANGUAGE_STANDARD = "c++20"; 537 | CLANG_CXX_LIBRARY = "libc++"; 538 | CLANG_ENABLE_MODULES = YES; 539 | CLANG_ENABLE_OBJC_ARC = YES; 540 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 541 | CLANG_WARN_BOOL_CONVERSION = YES; 542 | CLANG_WARN_COMMA = YES; 543 | CLANG_WARN_CONSTANT_CONVERSION = YES; 544 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 545 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 546 | CLANG_WARN_EMPTY_BODY = YES; 547 | CLANG_WARN_ENUM_CONVERSION = YES; 548 | CLANG_WARN_INFINITE_RECURSION = YES; 549 | CLANG_WARN_INT_CONVERSION = YES; 550 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 551 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 552 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 553 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 554 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 555 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 556 | CLANG_WARN_STRICT_PROTOTYPES = YES; 557 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 558 | CLANG_WARN_UNREACHABLE_CODE = YES; 559 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 560 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 561 | COPY_PHASE_STRIP = NO; 562 | CXX = ""; 563 | ENABLE_STRICT_OBJC_MSGSEND = YES; 564 | ENABLE_TESTABILITY = YES; 565 | "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = ""; 566 | GCC_C_LANGUAGE_STANDARD = gnu99; 567 | GCC_DYNAMIC_NO_PIC = NO; 568 | GCC_NO_COMMON_BLOCKS = YES; 569 | GCC_OPTIMIZATION_LEVEL = 0; 570 | GCC_PREPROCESSOR_DEFINITIONS = ( 571 | "DEBUG=1", 572 | "$(inherited)", 573 | ); 574 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 575 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 576 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 577 | GCC_WARN_UNDECLARED_SELECTOR = YES; 578 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 579 | GCC_WARN_UNUSED_FUNCTION = YES; 580 | GCC_WARN_UNUSED_VARIABLE = YES; 581 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 582 | LD = ""; 583 | LDPLUSPLUS = ""; 584 | LD_RUNPATH_SEARCH_PATHS = ( 585 | /usr/lib/swift, 586 | "$(inherited)", 587 | ); 588 | LIBRARY_SEARCH_PATHS = ( 589 | "\"$(SDKROOT)/usr/lib/swift\"", 590 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"", 591 | "\"$(inherited)\"", 592 | ); 593 | MTL_ENABLE_DEBUG_INFO = YES; 594 | ONLY_ACTIVE_ARCH = YES; 595 | OTHER_CPLUSPLUSFLAGS = ( 596 | "$(OTHER_CFLAGS)", 597 | "-DFOLLY_NO_CONFIG", 598 | "-DFOLLY_MOBILE=1", 599 | "-DFOLLY_USE_LIBCPP=1", 600 | "-DFOLLY_CFG_NO_COROUTINES=1", 601 | "-DFOLLY_HAVE_CLOCK_GETTIME=1", 602 | ); 603 | OTHER_LDFLAGS = ( 604 | "$(inherited)", 605 | " ", 606 | ); 607 | REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; 608 | SDKROOT = iphoneos; 609 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) DEBUG"; 610 | USE_HERMES = true; 611 | }; 612 | name = Debug; 613 | }; 614 | 83CBBA211A601CBA00E9B192 /* Release */ = { 615 | isa = XCBuildConfiguration; 616 | buildSettings = { 617 | ALWAYS_SEARCH_USER_PATHS = NO; 618 | CC = ""; 619 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 620 | CLANG_CXX_LANGUAGE_STANDARD = "c++20"; 621 | CLANG_CXX_LIBRARY = "libc++"; 622 | CLANG_ENABLE_MODULES = YES; 623 | CLANG_ENABLE_OBJC_ARC = YES; 624 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 625 | CLANG_WARN_BOOL_CONVERSION = YES; 626 | CLANG_WARN_COMMA = YES; 627 | CLANG_WARN_CONSTANT_CONVERSION = YES; 628 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 629 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 630 | CLANG_WARN_EMPTY_BODY = YES; 631 | CLANG_WARN_ENUM_CONVERSION = YES; 632 | CLANG_WARN_INFINITE_RECURSION = YES; 633 | CLANG_WARN_INT_CONVERSION = YES; 634 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 635 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 636 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 637 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 638 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 639 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 640 | CLANG_WARN_STRICT_PROTOTYPES = YES; 641 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 642 | CLANG_WARN_UNREACHABLE_CODE = YES; 643 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 644 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 645 | COPY_PHASE_STRIP = YES; 646 | CXX = ""; 647 | ENABLE_NS_ASSERTIONS = NO; 648 | ENABLE_STRICT_OBJC_MSGSEND = YES; 649 | "EXCLUDED_ARCHS[sdk=iphonesimulator*]" = ""; 650 | GCC_C_LANGUAGE_STANDARD = gnu99; 651 | GCC_NO_COMMON_BLOCKS = YES; 652 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 653 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 654 | GCC_WARN_UNDECLARED_SELECTOR = YES; 655 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 656 | GCC_WARN_UNUSED_FUNCTION = YES; 657 | GCC_WARN_UNUSED_VARIABLE = YES; 658 | IPHONEOS_DEPLOYMENT_TARGET = 13.4; 659 | LD = ""; 660 | LDPLUSPLUS = ""; 661 | LD_RUNPATH_SEARCH_PATHS = ( 662 | /usr/lib/swift, 663 | "$(inherited)", 664 | ); 665 | LIBRARY_SEARCH_PATHS = ( 666 | "\"$(SDKROOT)/usr/lib/swift\"", 667 | "\"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)\"", 668 | "\"$(inherited)\"", 669 | ); 670 | MTL_ENABLE_DEBUG_INFO = NO; 671 | OTHER_CPLUSPLUSFLAGS = ( 672 | "$(OTHER_CFLAGS)", 673 | "-DFOLLY_NO_CONFIG", 674 | "-DFOLLY_MOBILE=1", 675 | "-DFOLLY_USE_LIBCPP=1", 676 | "-DFOLLY_CFG_NO_COROUTINES=1", 677 | "-DFOLLY_HAVE_CLOCK_GETTIME=1", 678 | ); 679 | OTHER_LDFLAGS = ( 680 | "$(inherited)", 681 | " ", 682 | ); 683 | REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native"; 684 | SDKROOT = iphoneos; 685 | USE_HERMES = true; 686 | VALIDATE_PRODUCT = YES; 687 | }; 688 | name = Release; 689 | }; 690 | /* End XCBuildConfiguration section */ 691 | 692 | /* Begin XCConfigurationList section */ 693 | 00E357021AD99517003FC87E /* Build configuration list for PBXNativeTarget "ReactNativeAntMediaExampleTests" */ = { 694 | isa = XCConfigurationList; 695 | buildConfigurations = ( 696 | 00E356F61AD99517003FC87E /* Debug */, 697 | 00E356F71AD99517003FC87E /* Release */, 698 | ); 699 | defaultConfigurationIsVisible = 0; 700 | defaultConfigurationName = Release; 701 | }; 702 | 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ReactNativeAntMediaExample" */ = { 703 | isa = XCConfigurationList; 704 | buildConfigurations = ( 705 | 13B07F941A680F5B00A75B9A /* Debug */, 706 | 13B07F951A680F5B00A75B9A /* Release */, 707 | ); 708 | defaultConfigurationIsVisible = 0; 709 | defaultConfigurationName = Release; 710 | }; 711 | 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "ReactNativeAntMediaExample" */ = { 712 | isa = XCConfigurationList; 713 | buildConfigurations = ( 714 | 83CBBA201A601CBA00E9B192 /* Debug */, 715 | 83CBBA211A601CBA00E9B192 /* Release */, 716 | ); 717 | defaultConfigurationIsVisible = 0; 718 | defaultConfigurationName = Release; 719 | }; 720 | /* End XCConfigurationList section */ 721 | }; 722 | rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; 723 | } 724 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { 2 | useCallback, 3 | useEffect, 4 | useRef, 5 | MutableRefObject, 6 | } from 'react'; 7 | 8 | import { 9 | RTCPeerConnection, 10 | RTCIceCandidate, 11 | RTCSessionDescription, 12 | MediaStream, 13 | MediaStreamTrack, 14 | mediaDevices, 15 | RTCView, 16 | } from 'react-native-webrtc'; 17 | 18 | import 'react-native-url-polyfill/auto'; 19 | 20 | //Interfaces 21 | export interface Params { 22 | url: string; 23 | mediaConstraints: any; 24 | callback(this: Adaptor, message: string, data?: any): void; 25 | callbackError?: (errorMessage: string, data?: any) => void; 26 | peer_connection_config?: any; 27 | debug?: boolean; 28 | onlyDataChannel?: boolean; 29 | playMode?: boolean; 30 | } 31 | export interface RemoteStreams { 32 | [key: string]: MediaStream; 33 | } 34 | 35 | export interface Adaptor { 36 | publish: (streamId: string, token?: string, subscriberId?:string , subscriberCode?: string, streamName?: string, mainTrack?:string, metaData?:string) => void; 37 | play: (streamId: string, token?: string, room?: string , enableTracks?: MediaStream[],subscriberId?:string , subscriberCode?: string, metaData?:string) => void; 38 | stop: (streamId: string) => void; 39 | stopLocalStream: () => void; 40 | initialiseWebSocket: () => void; 41 | closeWebSocket: () => void; 42 | join: (streamId: string) => void; 43 | leave: (streamId: string) => void; 44 | getRoomInfo: (room: string, streamId?: string) => void; 45 | initPeerConnection: ( 46 | streamId: string, 47 | dataChannelMode: 'publish' | 'play' | 'peer' 48 | ) => Promise; 49 | localStream: MutableRefObject; 50 | peerMessage: (streamId: string, definition: any, data: any) => void; 51 | sendData: (streamId: string, message: string) => void; 52 | muteLocalMic: () => void; 53 | unmuteLocalMic: () => void; 54 | setLocalMicVolume: (volume: number) => void; 55 | setRemoteAudioVolume: (volume: number, streamId: string, roomName: string|undefined) => void; 56 | muteRemoteAudio: (streamId: string, roomName: string|undefined) => void; 57 | unmuteRemoteAudio: (streamId: string, roomName: string|undefined) => void; 58 | turnOffLocalCamera: () => void; 59 | turnOnLocalCamera: () => void; 60 | turnOffRemoteCamera: () => void; 61 | turnOnRemoteCamera: () => void; 62 | switchCamera: () => void; 63 | getDevices: () => Promise; 64 | } 65 | export interface RemotePeerConnection { 66 | [key: string]: RTCPeerConnection; 67 | } 68 | export interface RemotePeerConnectionStats { 69 | [key: string]: { timerId: number }; 70 | } 71 | 72 | export interface RemoteDescriptionSet { 73 | [key: string]: boolean; 74 | } 75 | export interface IceCandidateList { 76 | [key: string]: RTCIceCandidate[]; 77 | } 78 | export interface Sender { 79 | track: MediaStreamTrack; 80 | getParameters: () => { 81 | encodings?: any; 82 | }; 83 | setParameters: (data: any) => Record; 84 | } 85 | //useAntMedia main adaptor function 86 | export function useAntMedia(params: Params) { 87 | 88 | const { 89 | url, 90 | mediaConstraints, 91 | callbackError, 92 | callback, 93 | peer_connection_config, 94 | debug, 95 | onlyDataChannel, 96 | playMode, 97 | } = params; 98 | 99 | var websocketUrl = url; 100 | 101 | const adaptorRef: any = useRef(null); 102 | 103 | const isPlayMode = playMode || false; 104 | 105 | const updatedUrl = new URL(websocketUrl); 106 | if (!['origin', 'edge'].includes(updatedUrl.searchParams.get('target') ?? '')) { 107 | updatedUrl.searchParams.set('target', isPlayMode ? 'edge' : 'origin'); 108 | websocketUrl = updatedUrl.toString(); 109 | } 110 | 111 | const wsRef: any = useRef(new WebSocket(websocketUrl)); 112 | 113 | var ws = wsRef.current; 114 | 115 | let localStream: any = useRef(null); 116 | 117 | const remotePeerConnection = useRef({}).current; 118 | const remotePeerConnectionStats = useRef( 119 | {} 120 | ).current; 121 | 122 | const remoteDescriptionSet = useRef({}).current; 123 | const iceCandidateList = useRef({}).current; 124 | 125 | const config: any = peer_connection_config; 126 | 127 | const playStreamIds = useRef([]).current; 128 | 129 | var pingTimer: any = -1; 130 | 131 | var idMapping = new Array(); 132 | 133 | const closePeerConnection = useCallback( 134 | (streamId: string) => { 135 | if (debug) console.log('closePeerConnection'); 136 | 137 | var peerConnection: RTCPeerConnection = remotePeerConnection[streamId]; 138 | 139 | if (peerConnection != null) { 140 | delete remotePeerConnection[streamId]; 141 | 142 | // @ts-ignore 143 | if (peerConnection.dataChannel != null) { 144 | // @ts-ignore 145 | peerConnection.dataChannel.close(); 146 | } 147 | if (peerConnection.signalingState !== 'closed') { 148 | peerConnection.close(); 149 | } 150 | const playStreamIndex = playStreamIds.indexOf(streamId); 151 | 152 | if (playStreamIndex !== -1) { 153 | playStreamIds.splice(playStreamIndex, 1); 154 | } 155 | } 156 | 157 | if (remotePeerConnectionStats[streamId] != null) { 158 | clearInterval(remotePeerConnectionStats[streamId].timerId); 159 | delete remotePeerConnectionStats[streamId]; 160 | } 161 | 162 | clearPingTimer(); 163 | }, 164 | [playStreamIds, remotePeerConnection, remotePeerConnectionStats] 165 | ); 166 | 167 | const iceCandidateReceived = useCallback( 168 | (event: any, streamId: string) => { 169 | if (event.candidate) { 170 | const jsCmd = { 171 | command: 'takeCandidate', 172 | streamId, 173 | label: event.candidate.sdpMLineIndex, 174 | id: event.candidate.sdpMid, 175 | candidate: event.candidate.candidate, 176 | }; 177 | 178 | if (ws) ws.sendJson(jsCmd); 179 | } 180 | }, 181 | [ws] 182 | ); 183 | 184 | const onTrack = useCallback( 185 | (event: any, streamId: any) => { 186 | const dataObj = { 187 | stream: event.streams[0], 188 | track: event.track, 189 | streamId: streamId, 190 | trackId: idMapping[streamId] != undefined? idMapping[streamId][event.transceiver.mid]:undefined, 191 | } 192 | if (adaptorRef.current) { 193 | callback.call(adaptorRef.current, 'newStreamAvailable', dataObj); 194 | callback.call(adaptorRef.current, 'newTrackAvailable', dataObj); 195 | } 196 | }, 197 | [callback] 198 | ); 199 | 200 | const initDataChannel = useCallback((streamId: string, dataChannel: any) => { 201 | dataChannel.onerror = (error: any) => { 202 | console.log('Data Channel Error:', error); 203 | const obj = { 204 | streamId: streamId, 205 | error: error, 206 | }; 207 | console.log('channel status: ', dataChannel.readyState); 208 | if (dataChannel.readyState !== 'closed' && callbackError) { 209 | callbackError('data_channel_error', obj); 210 | } 211 | }; 212 | 213 | dataChannel.onmessage = (event: any) => { 214 | const obj = { 215 | streamId: streamId, 216 | event: event, 217 | }; 218 | if (callback && adaptorRef.current) 219 | callback.call(adaptorRef.current, 'data_received', obj); 220 | }; 221 | 222 | dataChannel.onopen = () => { 223 | // @ts-ignore 224 | remotePeerConnection[streamId].dataChannel = dataChannel; 225 | console.log('Data channel is opened'); 226 | if (callback && adaptorRef.current) 227 | callback.call(adaptorRef.current, 'data_channel_opened', streamId); 228 | }; 229 | 230 | dataChannel.onclose = () => { 231 | console.log('Data channel is closed'); 232 | if (callback && adaptorRef.current) 233 | callback.call(adaptorRef.current, 'data_channel_closed', streamId); 234 | }; 235 | }, []); 236 | 237 | const initPeerConnection = useCallback( 238 | async (streamId: string, dataChannelMode: 'publish' | 'play' | 'peer') => { 239 | if (debug) console.log('in initPeerConnection'); 240 | 241 | if (remotePeerConnection[streamId] == null) { 242 | const closedStreamId = streamId; 243 | remotePeerConnection[streamId] = new RTCPeerConnection(config || { iceServers: [] }); 244 | remoteDescriptionSet[streamId] = false; 245 | iceCandidateList[streamId] = []; 246 | 247 | if (!playStreamIds.includes(streamId) && localStream.current) { 248 | // @ts-ignore 249 | localStream.current.getTracks().forEach((track) => { 250 | remotePeerConnection[streamId].addTrack(track, localStream.current); 251 | // localStream.current.getTracks().forEach((track: MediaStreamTrack) => { remotePeerConnection[streamId].addTrack(track, localStream.current); }); 252 | }); 253 | 254 | } 255 | 256 | try { 257 | // @ts-ignore 258 | remotePeerConnection[streamId].onicecandidate = (event: RTCPeerConnectionIceEvent) => { 259 | if (debug) console.log('onicecandidate', event); 260 | iceCandidateReceived(event, closedStreamId); 261 | }; 262 | // @ts-ignore 263 | remotePeerConnection[streamId].ontrack = (event: any) => { 264 | if (debug) console.log('onTrack', event); 265 | onTrack(event, closedStreamId); 266 | }; 267 | 268 | // @ts-ignore 269 | remotePeerConnection[streamId].ondatachannel = (event: RTCDataChannelEvent) => { 270 | initDataChannel(streamId, event.channel); 271 | }; 272 | 273 | if (dataChannelMode === 'publish') { 274 | const dataChannelOptions = { 275 | ordered: true, 276 | }; 277 | const dataChannelPeer = remotePeerConnection[streamId].createDataChannel(streamId, dataChannelOptions); 278 | initDataChannel(streamId, dataChannelPeer); 279 | } else if (dataChannelMode === 'play') { 280 | // @ts-ignore 281 | remotePeerConnection[streamId].ondatachannel = (event: RTCDataChannelEvent) => { 282 | initDataChannel(streamId, event.channel); 283 | }; 284 | } else { 285 | const dataChannelOptions = { 286 | ordered: true, 287 | }; 288 | const dataChannelPeer = remotePeerConnection[streamId].createDataChannel(streamId, dataChannelOptions); 289 | initDataChannel(streamId, dataChannelPeer); 290 | // @ts-ignore 291 | remotePeerConnection[streamId].ondatachannel = (event: RTCDataChannelEvent) => { 292 | initDataChannel(streamId, event.channel); 293 | }; 294 | } 295 | } catch (err: any) { 296 | if (debug) console.error('initPeerConnectionError', err.message); 297 | } 298 | } 299 | }, 300 | [ 301 | config, 302 | debug, 303 | iceCandidateList, 304 | iceCandidateReceived, 305 | onTrack, 306 | playStreamIds, 307 | remoteDescriptionSet, 308 | remotePeerConnection, 309 | ] 310 | ); 311 | 312 | const gotDescription = useCallback( 313 | async (configuration: any, streamId: string) => { 314 | try { 315 | if (debug) console.log('in gotDescription'); 316 | 317 | // const response = 318 | await remotePeerConnection[streamId].setLocalDescription(configuration); 319 | 320 | const jsCmd = { 321 | command: 'takeConfiguration', 322 | streamId, 323 | type: configuration.type, 324 | sdp: configuration.sdp, 325 | }; 326 | 327 | if (ws) ws.sendJson(jsCmd); 328 | } catch (err: any) { 329 | if (debug) console.log('gotDescriptionError', err); 330 | } 331 | }, 332 | [debug, remotePeerConnection, ws] 333 | ); 334 | 335 | const startPublishing = useCallback( 336 | async (streamId: string) => { 337 | try { 338 | if (debug) console.log('in start publishing'); 339 | 340 | await initPeerConnection(streamId, 'publish'); 341 | const configuration = await remotePeerConnection[streamId].createOffer( 342 | config 343 | ); 344 | await gotDescription(configuration, streamId); 345 | } catch (err: any) { 346 | if (debug) console.log('startPublishing error', err.message, err.stack); 347 | } 348 | }, 349 | [config, debug, gotDescription, initPeerConnection, remotePeerConnection] 350 | ); 351 | 352 | const addIceCandidate = useCallback( 353 | async (streamId: string, candidate: any) => { 354 | try { 355 | if (debug) console.log('in addIceCandidate'); 356 | if (debug) console.debug(`addIceCandidate ${streamId}`); 357 | if (debug) console.debug('candidate', candidate); 358 | await remotePeerConnection[streamId].addIceCandidate(candidate); 359 | } catch (err) {} 360 | }, 361 | [debug, remotePeerConnection] 362 | ); 363 | 364 | const takeConfiguration = useCallback( 365 | async (streamId: any, configuration: string, typeOfConfiguration: string , idMap?:string) => { 366 | const type = typeOfConfiguration; 367 | var conf = configuration; 368 | conf = conf.replace("a=extmap:13 urn:3gpp:video-orientation\r\n", ""); 369 | const isTypeOffer = type === 'offer'; 370 | idMapping[streamId] = idMap; 371 | 372 | if (debug) console.log('in takeConfiguration'); 373 | let dataChannelMode: 'publish' | 'play' = 'publish'; 374 | if (isTypeOffer) { 375 | dataChannelMode = 'play'; 376 | } 377 | await initPeerConnection(streamId, dataChannelMode); 378 | try { 379 | await remotePeerConnection[streamId].setRemoteDescription( 380 | new RTCSessionDescription({ 381 | sdp: conf, 382 | type, 383 | }) 384 | ); 385 | remoteDescriptionSet[streamId] = true; 386 | const { length } = Object.keys(iceCandidateList[streamId]); 387 | for (let i = 0; i < length; i++) { 388 | await addIceCandidate(streamId, iceCandidateList[streamId][i]); 389 | } 390 | iceCandidateList[streamId] = []; 391 | if (isTypeOffer) { 392 | const configur = await remotePeerConnection[streamId].createAnswer( 393 | 394 | ); 395 | await gotDescription(configur, streamId); 396 | } 397 | } catch (error: any) { 398 | if ( 399 | error.toString().indexOf('InvalidAccessError') > -1 || 400 | error.toString().indexOf('setRemoteDescription') > -1 401 | ) { 402 | /** 403 | * This error generally occurs in codec incompatibility. 404 | * AMS for a now supports H.264 codec. This error happens when some browsers try to open it from VP8. 405 | */ 406 | if (callbackError) callbackError('notSetRemoteDescription'); 407 | } 408 | } 409 | }, 410 | [ 411 | addIceCandidate, 412 | callbackError, 413 | debug, 414 | gotDescription, 415 | iceCandidateList, 416 | initPeerConnection, 417 | remoteDescriptionSet, 418 | remotePeerConnection, 419 | ] 420 | ); 421 | 422 | const takeCandidate = useCallback( 423 | // @ts-ignore 424 | async (idOfTheStream: string, tmpLabel, tmpCandidate, sdpMid) => { 425 | if (debug) console.log('in takeCandidate'); 426 | 427 | const streamId = idOfTheStream; 428 | const label = tmpLabel; 429 | const candidateSdp = tmpCandidate; 430 | 431 | const candidate = new RTCIceCandidate({ 432 | sdpMLineIndex: label, 433 | candidate: candidateSdp, 434 | sdpMid, 435 | }); 436 | 437 | await initPeerConnection(streamId, 'peer'); 438 | 439 | if (remoteDescriptionSet[streamId] === true) { 440 | await addIceCandidate(streamId, candidate); 441 | } else { 442 | if (debug) 443 | console.debug( 444 | 'Ice candidate is added to list because remote description is not set yet' 445 | ); 446 | const index = iceCandidateList[streamId].findIndex( 447 | (i) => JSON.stringify(i) === JSON.stringify(candidate) 448 | ); 449 | if (index === -1) { 450 | const keys = Object.keys(candidate); 451 | for (const key in keys) { 452 | // @ts-ignore 453 | if (candidate[key] === undefined || candidate[key] === '') { 454 | // @ts-ignore 455 | candidate[key] = null; 456 | } 457 | } 458 | iceCandidateList[streamId].push(candidate); 459 | } 460 | } 461 | }, 462 | [ 463 | addIceCandidate, 464 | debug, 465 | iceCandidateList, 466 | initPeerConnection, 467 | remoteDescriptionSet, 468 | ] 469 | ); 470 | 471 | const setWebSocketListeners = useCallback(() => { 472 | if (!ws) return; 473 | ws.sendJson = (dt: any) => { 474 | if (ws && ws.send && ws.readyState === ws.OPEN) { 475 | ws.send(JSON.stringify(dt)); 476 | } 477 | }; 478 | 479 | ws.onopen = () => { 480 | if (debug) console.log('web socket opened !'); 481 | callback.call(adaptorRef.current, 'initiated'); 482 | // connection opened 483 | 484 | getDevices(); 485 | 486 | if (!onlyDataChannel && !isPlayMode) { 487 | mediaDevices.getUserMedia(mediaConstraints) 488 | .then((stream: any) => { 489 | // Got stream! 490 | if (debug) console.log('got stream'); 491 | 492 | localStream.current = stream; 493 | if (adaptorRef.current) callback.call(adaptorRef.current, 'local_stream_updated', stream); 494 | if (debug) console.log('in stream', localStream.current); 495 | }) 496 | .catch((error: any) => { 497 | // Log error 498 | if (debug) console.log('got error', error , mediaConstraints); 499 | }); 500 | } else { 501 | if (debug) console.log('only data channel or play only'); 502 | } 503 | setPingTimer(); 504 | }; 505 | 506 | ws.onmessage = (e: any) => { 507 | // a message was received 508 | const data = JSON.parse(e.data); 509 | if (debug) console.log(' onmessage', data); 510 | 511 | switch (data.command) { 512 | case 'start': 513 | // start publishing 514 | startPublishing(data.streamId); 515 | break; 516 | case 'takeCandidate': 517 | //console.log(' in takeCandidate', data); 518 | takeCandidate(data.streamId, data.label, data.candidate, data.id); 519 | break; 520 | case 'takeConfiguration': 521 | takeConfiguration(data.streamId, data.sdp, data.type,data.idMapping); 522 | break; 523 | case 'stop': 524 | if (debug) console.log(' in stop', data); 525 | closePeerConnection(data.streamId); 526 | break; 527 | case 'error': 528 | if (debug) console.log(' in error', data); 529 | if (callbackError) { 530 | callbackError(data.definition, data); 531 | } 532 | break; 533 | case 'notification': 534 | if (debug) console.log(' in notification', data); 535 | 536 | if (adaptorRef.current) 537 | callback.call(adaptorRef.current, data.definition, data); 538 | break; 539 | case 'roomInformation': 540 | if (debug) console.log(' in roomInformation', data); 541 | callback.call(adaptorRef.current, data.command, data); 542 | break; 543 | case 'pong': 544 | if (debug) console.log(' in pong', data); 545 | break; 546 | case 'streamInformation': 547 | if (debug) console.log(' in streamInformation', data); 548 | callback.call(adaptorRef.current, data.command, data); 549 | break; 550 | case 'trackList': 551 | if (debug) console.log(' in trackList', data); 552 | callback.call(adaptorRef.current, data.command, data); 553 | break; 554 | case 'connectWithNewId': 555 | if (debug) console.log(' in connectWithNewId', data); 556 | callback.call(adaptorRef.current, data.command, data); 557 | break; 558 | case 'peerMessageCommand': 559 | if (debug) console.log(' in peerMessageCommand', data); 560 | callback.call(adaptorRef.current, data.command, data); 561 | break; 562 | default: 563 | if (debug) console.log(' in default', data); 564 | callback.call(adaptorRef.current, data.command, data); 565 | break; 566 | } 567 | }; 568 | 569 | ws.onerror = (e: any) => { 570 | // an error occurred 571 | clearPingTimer(); 572 | if (debug) console.log(e.message); 573 | }; 574 | 575 | ws.onclose = (e: any) => { 576 | // connection closed 577 | clearPingTimer(); 578 | if (debug) console.log(e.code, e.reason); 579 | if (callback && adaptorRef.current) callback.call(adaptorRef.current, 'websocket_closed', '' ); 580 | ws = null; 581 | }; 582 | }, [callback, callbackError, closePeerConnection, debug, mediaConstraints, startPublishing, takeCandidate, takeConfiguration, ws]); 583 | 584 | useEffect(() => { 585 | setWebSocketListeners(); 586 | }, [ 587 | callback, 588 | callbackError, 589 | closePeerConnection, 590 | config, 591 | debug, 592 | mediaConstraints, 593 | startPublishing, 594 | takeCandidate, 595 | takeConfiguration, 596 | ws, 597 | ]); 598 | 599 | const publish = useCallback( 600 | ( 601 | streamId: string, 602 | token?: string, 603 | subscriberId?: string, 604 | subscriberCode?: string, 605 | streamName?: string, 606 | mainTrack?:string, 607 | metaData?:string 608 | ) => { 609 | if (ws && ws.readyState === ws.CLOSED) { 610 | if (debug) console.log('WebSocket is not connected'); 611 | if (adaptorRef.current) callback.call(adaptorRef.current, 'websocket_not_initialized', ''); 612 | } 613 | 614 | if (localStream.current === null) { 615 | if (debug) console.log('Local stream is not ready'); 616 | return; 617 | } 618 | 619 | let data = {} as any; 620 | if (onlyDataChannel) { 621 | data = { 622 | command: 'publish', 623 | streamId: streamId, 624 | token: token, 625 | subscriberId: typeof subscriberId !== undefined ? subscriberId : '', 626 | subscriberCode: typeof subscriberCode !== undefined ? subscriberCode : '', 627 | video: false, 628 | audio: false, 629 | }; 630 | } else { 631 | 632 | let [video, audio] = [false, false]; 633 | 634 | // @ts-ignore 635 | video = localStream.current.getVideoTracks().length > 0; 636 | // @ts-ignore 637 | audio = localStream.current.getAudioTracks().length > 0; 638 | 639 | data = { 640 | command: 'publish', 641 | streamId, 642 | token, 643 | subscriberId: typeof subscriberId !== undefined ? subscriberId : '', 644 | subscriberCode: typeof subscriberCode !== undefined ? subscriberCode : '', 645 | streamName, 646 | mainTrack, 647 | video, 648 | audio, 649 | metaData 650 | }; 651 | } 652 | 653 | if (ws) ws.sendJson(data); 654 | }, 655 | [ws] 656 | ); 657 | 658 | //play 659 | const play = useCallback( 660 | (streamId: string, token?: string, room?: string , enableTracks?:MediaStreamTrack[],subscriberId?:string, subscriberCode?:string ,metaData?:string ) => { 661 | if (ws && ws.readyState === ws.CLOSED) { 662 | if (debug) console.log('WebSocket is not connected'); 663 | if (adaptorRef.current) callback.call(adaptorRef.current, 'websocket_not_initialized', ''); 664 | } 665 | 666 | playStreamIds.push(streamId); 667 | const data = { 668 | command: 'play', 669 | streamId, 670 | token, 671 | room, 672 | enableTracks, 673 | subscriberId: typeof subscriberId !== undefined ? subscriberId : '', 674 | subscriberCode: typeof subscriberCode !== undefined ? subscriberCode : '', 675 | viewerInfo: typeof metaData !== undefined && metaData != null ? metaData : "" 676 | }; 677 | 678 | if (token) { 679 | data.token = token; 680 | } 681 | 682 | if (ws) ws.sendJson(data); 683 | }, 684 | [playStreamIds, ws] 685 | ); 686 | 687 | const stopLocalStream = useCallback( 688 | () => { 689 | if (localStream.current) { 690 | // @ts-ignore 691 | localStream.current.getTracks().forEach((track) => { 692 | track.stop(); 693 | }); 694 | localStream.current = null; 695 | } 696 | }, 697 | [localStream] 698 | ); 699 | 700 | const initialiseWebSocket = useCallback(() => { 701 | console.log('initialising websocket') 702 | if (ws && ws.readyState === ws.OPEN) { 703 | if (debug) console.log('WebSocket is already connected'); 704 | return; 705 | } 706 | 707 | const updatedUrl: URL = new URL(websocketUrl); 708 | if (!['origin', 'edge'].includes(updatedUrl.searchParams.get('target') ?? '')) { 709 | updatedUrl.searchParams.set('target', isPlayMode ? 'edge' : 'origin'); 710 | websocketUrl = updatedUrl.toString(); 711 | } 712 | 713 | wsRef.current = new WebSocket(websocketUrl); 714 | ws = wsRef.current; 715 | setWebSocketListeners(); 716 | console.log('WebSocket is connected'); 717 | }, [ws]); 718 | 719 | const closeWebSocket = useCallback(() => { 720 | if (ws) { 721 | ws.close(); 722 | } 723 | }, [ws]); 724 | 725 | const stop = useCallback( 726 | (streamId: any) => { 727 | closePeerConnection(streamId); 728 | 729 | const data = { 730 | command: 'stop', 731 | streamId: streamId, 732 | }; 733 | if (ws) ws.sendJson(data); 734 | }, 735 | [ws] 736 | ); 737 | 738 | const join = useCallback( 739 | (streamId: string) => { 740 | const data = { 741 | command: 'join', 742 | streamId, 743 | }; 744 | if (ws) ws.sendJson(data); 745 | }, 746 | [ws] 747 | ); 748 | 749 | const leave = useCallback( 750 | (streamId: string) => { 751 | const data = { 752 | command: 'leave', 753 | streamId, 754 | }; 755 | if (ws) ws.sendJson(data); 756 | }, 757 | [ws] 758 | ); 759 | 760 | const muteLocalMic = useCallback(() => { 761 | if (localStream.current) { 762 | // @ts-ignore 763 | localStream.current.getAudioTracks().forEach((track) => { 764 | track.enabled = false; 765 | }); 766 | } 767 | }, [localStream]); 768 | 769 | const unmuteLocalMic = useCallback(() => { 770 | if (localStream.current) { 771 | // @ts-ignore 772 | localStream.current.getAudioTracks().forEach((track) => { 773 | track.enabled = true; 774 | }); 775 | } 776 | }, [localStream]); 777 | 778 | const setLocalMicVolume = useCallback((volume: number) => { 779 | if (localStream.current) { 780 | // @ts-ignore 781 | localStream.current.getAudioTracks().forEach((track) => { 782 | track._setVolume(volume); 783 | }); 784 | } 785 | }, [localStream]); 786 | 787 | const setRemoteAudioVolume = useCallback((volume: number, streamId: string, roomName: string|undefined) => { 788 | console.log("Setting remote mic") 789 | // @ts-ignore 790 | if (typeof roomName != 'undefined' && remotePeerConnection[roomName]) { 791 | remotePeerConnection[roomName]._remoteStreams.forEach((stream) => { 792 | let audioTrackID = "ARDAMSa" + streamId; 793 | let track = stream.getTrackById(audioTrackID); 794 | if (track) { 795 | track._setVolume(volume); 796 | } 797 | }); 798 | } else if(remotePeerConnection[streamId]) { 799 | remotePeerConnection[streamId]._remoteStreams.forEach((stream) => { 800 | let audioTrackID = "ARDAMSa" + streamId; 801 | let track = stream.getTrackById(audioTrackID); 802 | if (track) { 803 | track._setVolume(volume); 804 | } 805 | }); 806 | } 807 | }, [remotePeerConnection]); 808 | 809 | const muteRemoteAudio = useCallback((streamId: string, roomName: string|undefined) => { 810 | console.log("Muting remote mic") 811 | // @ts-ignore 812 | if (typeof roomName != 'undefined' && remotePeerConnection[roomName]) { 813 | remotePeerConnection[roomName]._remoteStreams.forEach((stream) => { 814 | let audioTrackID = "ARDAMSa" + streamId; 815 | let track = stream.getTrackById(audioTrackID); 816 | if (track) { 817 | track.enabled = false; 818 | } 819 | }); 820 | } else if(remotePeerConnection[streamId]) { 821 | remotePeerConnection[streamId]._remoteStreams.forEach((stream) => { 822 | let audioTrackID = "ARDAMSa" + streamId; 823 | let track = stream.getTrackById(audioTrackID); 824 | if (track) { 825 | track.enabled = false; 826 | } 827 | }); 828 | } 829 | }, [remotePeerConnection]); 830 | 831 | const unmuteRemoteAudio = useCallback((streamId: string, roomName: string|undefined) => { 832 | console.log("Muting remote mic") 833 | // @ts-ignore 834 | if (typeof roomName != 'undefined' && remotePeerConnection[roomName]) { 835 | remotePeerConnection[roomName]._remoteStreams.forEach((stream) => { 836 | let audioTrackID = "ARDAMSa" + streamId; 837 | let track = stream.getTrackById(audioTrackID); 838 | if (track) { 839 | track.enabled = true; 840 | } 841 | }); 842 | } else if(remotePeerConnection[streamId]) { 843 | remotePeerConnection[streamId]._remoteStreams.forEach((stream) => { 844 | let audioTrackID = "ARDAMSa" + streamId; 845 | let track = stream.getTrackById(audioTrackID); 846 | if (track) { 847 | track.enabled = true; 848 | } 849 | }); 850 | } 851 | }, [remotePeerConnection]); 852 | 853 | const getRoomInfo = useCallback( 854 | (room: string, streamId?: string) => { 855 | var data = { 856 | command: 'getRoomInfo', 857 | streamId, 858 | room, 859 | }; 860 | if (ws) ws.sendJson(data); 861 | }, 862 | [ws] 863 | ); 864 | const setPingTimer = useCallback(() => { 865 | pingTimer = setInterval(()=>{ 866 | if(ws != null) 867 | ws.sendJson({ 868 | command: 'ping', 869 | }); 870 | },3000); 871 | },[]); 872 | 873 | const clearPingTimer = useCallback(() => { 874 | if (pingTimer != -1) { 875 | if (debug) { 876 | console.log("Clearing ping message timer"); 877 | } 878 | clearInterval(pingTimer); 879 | pingTimer = -1; 880 | } 881 | },[]); 882 | 883 | //Data Channel 884 | const peerMessage = useCallback( 885 | (streamId: string, definition: any, data: any) => { 886 | const jsCmd = { 887 | command: 'peerMessageCommand', 888 | streamId: streamId, 889 | definition: definition, 890 | data: data, 891 | }; 892 | if (ws) ws.sendJson(jsCmd); 893 | }, 894 | [ws] 895 | ); 896 | 897 | const getDevices = useCallback( async () => { 898 | var deviceArray = new Array(); 899 | 900 | try { 901 | const devices = await mediaDevices.enumerateDevices(); 902 | // @ts-ignore 903 | devices.map( device => { 904 | deviceArray.push(device); 905 | } ); 906 | 907 | callback.call(adaptorRef.current, 'available_devices', deviceArray); 908 | } catch (err: any) { 909 | console.log("Cannot get devices -> error: " + err); 910 | } 911 | // @ts-ignore 912 | mediaDevices.ondevicechange = async () => { 913 | console.log("Device change event") 914 | getDevices(); 915 | }; 916 | 917 | return deviceArray; 918 | 919 | }, [callback]); 920 | 921 | const sendData = useCallback( 922 | (streamId: string, message: string) => { 923 | // @ts-ignore 924 | const dataChannel = remotePeerConnection[streamId].dataChannel; 925 | dataChannel.send(message); 926 | if (debug) console.log(' send message in server', message); 927 | }, 928 | [ws] 929 | ); 930 | 931 | const turnOffLocalCamera = useCallback(() => { 932 | if (localStream.current) { 933 | // @ts-ignore 934 | localStream.current.getVideoTracks().forEach((track) => { 935 | track.enabled = false; 936 | }); 937 | } 938 | }, []); 939 | 940 | const turnOnLocalCamera = useCallback(() => { 941 | if (localStream.current) { 942 | // @ts-ignore 943 | localStream.current.getVideoTracks().forEach((track) => { 944 | track.enabled = true; 945 | }); 946 | } 947 | }, []); 948 | 949 | const turnOffRemoteCamera = useCallback((streamId: string, roomName: string|undefined) => { 950 | console.log("Turning off remote camera") 951 | // @ts-ignore 952 | if (typeof roomName != 'undefined' && remotePeerConnection[roomName]) { 953 | remotePeerConnection[roomName]._remoteStreams.forEach((stream) => { 954 | let videoTrackID = "ARDAMSv" + streamId; 955 | let track = stream.getTrackById(videoTrackID); 956 | if (track) { 957 | track.enabled = false; 958 | } 959 | }); 960 | } else if(remotePeerConnection[streamId]) { 961 | remotePeerConnection[streamId]._remoteStreams.forEach((stream) => { 962 | let videoTrackID = "ARDAMSv" + streamId; 963 | let track = stream.getTrackById(videoTrackID); 964 | if (track) { 965 | track.enabled = false; 966 | } 967 | }); 968 | } 969 | }, [remotePeerConnection]); 970 | 971 | const turnOnRemoteCamera = useCallback((streamId: string, roomName: string|undefined) => { 972 | console.log("Turning on remote camera") 973 | // @ts-ignore 974 | if (typeof roomName != 'undefined' && remotePeerConnection[roomName]) { 975 | remotePeerConnection[roomName]._remoteStreams.forEach((stream) => { 976 | let videoTrackID = "ARDAMSv" + streamId; 977 | let track = stream.getTrackById(videoTrackID); 978 | if (track) { 979 | track.enabled = true; 980 | } 981 | }); 982 | } else if(remotePeerConnection[streamId]) { 983 | remotePeerConnection[streamId]._remoteStreams.forEach((stream) => { 984 | let videoTrackID = "ARDAMSv" + streamId; 985 | let track = stream.getTrackById(videoTrackID); 986 | if (track) { 987 | track.enabled = true; 988 | } 989 | }); 990 | } 991 | }, [remotePeerConnection]); 992 | 993 | const switchCamera = useCallback(() => { 994 | if (localStream.current) { 995 | // @ts-ignore 996 | localStream.current.getVideoTracks().forEach((track) => { 997 | track._switchCamera(); 998 | }); 999 | } 1000 | }, [localStream]); 1001 | 1002 | //adaptor ref 1003 | useEffect(() => { 1004 | adaptorRef.current = { 1005 | publish, 1006 | play, 1007 | stop, 1008 | stopLocalStream, 1009 | initialiseWebSocket, 1010 | closeWebSocket, 1011 | join, 1012 | leave, 1013 | getRoomInfo, 1014 | initPeerConnection, 1015 | localStream, 1016 | peerMessage, 1017 | sendData, 1018 | muteLocalMic, 1019 | unmuteLocalMic, 1020 | setLocalMicVolume, 1021 | setRemoteAudioVolume, 1022 | muteRemoteAudio, 1023 | unmuteRemoteAudio, 1024 | turnOffLocalCamera, 1025 | turnOnLocalCamera, 1026 | turnOffRemoteCamera, 1027 | turnOnRemoteCamera, 1028 | switchCamera, 1029 | getDevices, 1030 | }; 1031 | }, [ 1032 | publish, 1033 | play, 1034 | stop, 1035 | stopLocalStream, 1036 | initialiseWebSocket, 1037 | closeWebSocket, 1038 | localStream, 1039 | join, 1040 | leave, 1041 | getRoomInfo, 1042 | initPeerConnection, 1043 | peerMessage, 1044 | sendData, 1045 | muteLocalMic, 1046 | unmuteLocalMic, 1047 | setLocalMicVolume, 1048 | setRemoteAudioVolume, 1049 | muteRemoteAudio, 1050 | unmuteRemoteAudio, 1051 | turnOffLocalCamera, 1052 | turnOnLocalCamera, 1053 | turnOffRemoteCamera, 1054 | turnOnRemoteCamera, 1055 | switchCamera, 1056 | getDevices, 1057 | ]); 1058 | 1059 | return { 1060 | publish, 1061 | play, 1062 | stop, 1063 | stopLocalStream, 1064 | initialiseWebSocket, 1065 | closeWebSocket, 1066 | localStream, 1067 | join, 1068 | leave, 1069 | getRoomInfo, 1070 | initPeerConnection, 1071 | peerMessage, 1072 | sendData, 1073 | setLocalMicVolume, 1074 | setRemoteAudioVolume, 1075 | muteLocalMic, 1076 | unmuteLocalMic, 1077 | muteRemoteAudio, 1078 | unmuteRemoteAudio, 1079 | turnOffLocalCamera, 1080 | turnOnLocalCamera, 1081 | turnOffRemoteCamera, 1082 | turnOnRemoteCamera, 1083 | switchCamera, 1084 | getDevices, 1085 | } as Adaptor; 1086 | } // useAntmedia fn end 1087 | 1088 | export function rtc_view( 1089 | stream: any, 1090 | customStyles: any = { width: '70%', height: '50%', alignSelf: 'center' }, 1091 | objectFit: any = 'cover' 1092 | ) { 1093 | if(stream instanceof MediaStreamTrack ){ 1094 | let mediaStream = new MediaStream(undefined); 1095 | mediaStream.addTrack(stream); 1096 | stream = mediaStream.toURL(); 1097 | } 1098 | const props = { 1099 | streamURL: stream, 1100 | style: customStyles, 1101 | objectFit: objectFit, 1102 | }; 1103 | 1104 | // @ts-ignore 1105 | return ; 1106 | } 1107 | --------------------------------------------------------------------------------