HotBox is a React Native wrapper around TokBox OpenTOK SDK.
I tried the other React Native OpenTOK wrappers but they did not seem to work / provide the flexibility we wanted so we created our own.
yarn add react-native-hot-box
or inferiorlynpm install --save react-native-hot-box
- Add the files under
node_modules/react-native-hot-box/HotBoxService
(In Xcode: File -> Add files to "App Name") - You're going to want a bridging header:
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTViewManager.h>
- You will also want a Podfile:
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'Example' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
use_frameworks!
pod 'RxSwift'
pod 'OpenTok'
end
- Investigate
Example
for a full example just in case something is missing or open a ticket.
Please open a PR :)
Something like:
import {Session, PublisherView, SubscriberView} from 'react-native-hot-box'
var session = new Session()
session.on('sessionDidConnect', () => console.log('connected'))
session.on("sessionDidDisconnect", () => console.log('disconnected'))
session.on('publisherStreamCreated', () => console.log("PUBLISHER CREATED"))
session.on('sessionStreamCreated', () => console.log('sessionStreamCreated'))
session.on('subscriberDidConnect', (streamId) => console.log("New subscriber", streamId))
session.on("subscriberDidDisconnect", (streamId) => console.log("Subscriber disconnected", streamId))
session.on('sessionStreamDestroyed', (streamId) => console.log("Stream destroyed", streamId))
let apiKey = ''
let sessionId = ''
let token = ''
session.createSession(apiKey, sessionId, token)
* sessionDidConnect (sessionId)
* sessionDidDisconnect (sessionId)
* sessionConnectionCreated (connectionId)
* sessionConnectionDestroyed (connectionId)
* sessionStreamCreated (streamId)
* sessionStreamDidFailWithError (err)
* sessionStreamDestroyed (streamId)
* sessionReceivedSignal ({type, connectionId, message})
* publisherStreamCreated (streamId)
* publisherStreamDidFailWithError (err)
* publisherStreamDestroyed (streamId)
* subscriberDidConnect (streamId)
* subscriberDidFailWithError (streamId)
* subscriberDidDisconnect (streamId)
session.createSession(apiKey, sessionId, token)
session.createPublisher() // You can manually create the publisher but by default it's created automatically
session.disconnectAllSessions()
// Turn on/off video stream for given streamId (null for publisher)
session.requestVideoStream(streamId, on)
// Turn on/off audio stream for given streamId (null for publisher)
session.requestAudioStream(streamId, on)
// Flip publisher camera
session.requestCameraSwap(toBack) // toBack==true ==> back camera
//Send messages
session.sendMessage(type, message, connectionId)
session.broadcastMessage(type, message)
//Subscribe to Stream
session.subscribe(streamId)
//Subscribe to signals
session.on(event, handler)
<PublisherView style={styles.viewStyle} />
<SubscriberView style={styles.viewStyle} streamId={streamId} />
To run:
yarn install
cd Example/ios & pod install
open Example/ios/Example.xcworkspace
- Add your api key, token and session key in App.js
run
Thanks to my team:
- @george-lim
- @jyliang
Thanks to the following projects for inspiration!
- https://github.com/callstack-io/react-native-opentok
- https://github.com/tokboxnerds/opentok-react-native
Feel free to open an issue, submit a PR or email [email protected] to give feedback / suggestions.