Socket
Socket
Sign inDemoInstall

opentok-react-native

Package Overview
Dependencies
1
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    opentok-react-native

React Native components for OpenTok iOS and Android SDKs


Version published
Maintainers
1
Created

Readme

Source

OpenTok Labs

opentok-react-native

  • Pre-Requisites
  • Installation
  • API Reference
  • Contributing

In this repo, you'll find the OpenTok React Native library:

Pre-Requisites:

  1. Install node.js

  2. Install and update Xcode (you will need a Mac)

  1. Install and update Android Studio

Installation:

  1. In your terminal, change into your React Native project's directory

  2. In your terminal, run npm install opentok-react-native

iOS Installation

Note Please make sure to have CocoaPods on your computer.

  1. In you terminal, change into your ios directory.

  2. Create a pod file by running: pod init.

  3. Add the following to your pod file:

    platform :ios, '9.0'

    target '<YourProjectName>' do
      use_frameworks!

      # Pods for <YourProject>
        pod 'OpenTok'
    end

  1. Now run, pod install

  2. Open XCode

  3. Open .xcworkspace file in XCode. This file can be found in the ios folder.

  4. Click File and Add Files to

  5. Add the following files to the project:

  • OTPublisher.h
  • OTPublisher.m
  • OTPublisherManager.swift
  • OTPublisherView.swift
  • OTRN.swift
  • OTSessionManager.m
  • OTSessionManager.swift
  • OTSubscriber.h
  • OTSubscriber.m
  • OTSubscriberManager.swift
  • OTSubscriberView.swift
  • <YourProjectName>-Bridging-Header.h

Android Installation

  1. In you terminal, change into your project directory.

  2. Run react-native link opentok-react-native

  3. Open your Android project in Android Studio.

  4. Sync Gradle

  5. Make sure the following in your app's gradle compileSdkVersion, buildToolsVersion, minSdkVersion, and targetSdkVersion are the same in the OpenTok React Native library.

API Reference

The OpenTok React Native library comprises of:

  • OTSession Component
  • OTPublisher Component
  • OTSubscriber Component

OTSession Component

PropTypeRequiredDescription
apiKeyStringYesTokBox API Key
sessionIdStringYesTokBox Session ID
tokenStringYesTokBox token
signalObjectNoUsed to send a signal to the session
eventHandlersObject<Function>NoEvent handlers passed into the native session instance.

The OTSession component manages the connection to an OpenTok Session. It passes the sessionId to the sessionId prop to its child components. To publish and subscribe, you must nest OTPublisher and OTSubscriber inside OTSession:

<OTSession apiKey="your-api-key" sessionId="your-session-id" token="your-session-token">
  <OTPublisher />
  <OTSubscriber />
</OTSession>

OTPublisher Component

PropTypeRequiredDescription
sessionIdStringNoOpenTok sessionId. This is auto populated by wrapping OTPublisher with OTSession
propertiesObjectNoProperties passed into the native publisher instance
eventHandlersObject<Function>NoEvent handlers passed into native publsiher instance

The OTPublisher component will initialize a publisher and publish to a specified session upon mounting.

<OTSession apiKey="your-api-key" sessionId="your-session-id" token="your-session-token">
  <OTPublisher />
</OTSession>
class App extends Component {
  constructor(props) {
    super(props);

    this.publisherProperties = {
      audioFallbackEnabled: false,
      cameraPosition: 'front'
    };

    this.publisherEventHandlers = {
      streamCreated: event => {
        console.log('Publisher stream created!', event);
      },
      streamDestroyed: event => {
        console.log('Publisher stream destroyed!', event);
      }
    };
  }

  render() {
    return (
      <OTSession apiKey="your-api-key" sessionId="your-session-id" token="your-session-token">
        <OTPublisher
          properties={this.publisherProperties}
          eventHandlers={this.publisherEventHandlers}
        />
      </OTSession>
    );
  }
}

The properties prop is used for initial set up of the Publisher and making changes to it will update the Publisher. For convenience the OTPublisher watches for changes on a few keys of the properties object and makes the necessary changes. Currently these are:

Publisher PropertyAction
publishAudioCalls OT.publishAudio() to toggle audio on and off
publishVideoCalls OT.publishVideo() to toggle video on and off

Please keep in mind that OT is not the same as OT in the JS SDK, the OT in this library refers to the iOS and Android OTSessionManager class.

OTSubscriber Component

PropTypeRequiredDescription
sessionIdStringNoOpenTok Session Id. This is auto populated by wrapping OTSubscriber with OTSession
streamIdStringNoOpenTok Subscriber streamId. This is auto populated inside the OTSubscriber component when streamCreated event is fired from the native session delegate(iOS)/ interface(Android)
propertiesObjectNoProperties passed into the native subscriber instance
eventHandlersObject<Function>NoEvent handlers passed into the native subscriber instance

The OTSubscriber component will subscribe to a specified stream from a specified session upon mounting.

Contributing

If you make changes to the project that you would like to contribute back then please follow the contributing guidelines. All contributions are greatly appreciated!

Keywords

FAQs

Last updated on 08 Mar 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc