Skip to content

Commit

Permalink
0.19.0 (#547)
Browse files Browse the repository at this point in the history
* * fix crash in OTSubscriberLayout

* - add ICEConfig in JS and Native

* - working on iOS

* - update Utils Swift

* - utils java

* - FIX OTSESSION Helper

* - fix Utils.java

* - fix Utils java sanitizeIceServer

* - update OTSession documentation

* - remove comments in SEssion Manager

* - check value != null Utils.java

* - update native Android SDK

* - ios add named input

* fix typings

* - fix spacing

* - fix NPE on Utils.java

* - Bump version
- update CHANGELOG

* - OTSession md typo
- Utils.java refactor functions

* - fix indentation of typings

Co-authored-by: Pavel Zarecky <p.zarecky@quin.md>
  • Loading branch information
Enrico Portolan and Pavel Zarecky authored Oct 12, 2021
1 parent f943e1c commit f7e7447
Show file tree
Hide file tree
Showing 12 changed files with 202 additions and 26 deletions.
14 changes: 13 additions & 1 deletion @types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,19 @@ declare module "opentok-react-native" {
/**
* Enable Stereo output
*/
enableStereoOutput: boolean;
enableStereoOutput?: boolean;
/**
* Ice Config. Please check https://tokbox.com/developer/guides/configurable-turn-servers/
*/
iceConfig?: {
includeServers: 'all' | 'custom';
transportPolicy: 'all' | 'relay';
customServers: {
urls: string[];
username?: string;
credential?: string;
}[];
};
}

interface OTSessionEventHandlers {
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 0.19.0 (Oct 11, 2021)
- [Update]: update SDKs Android to 2.20.2
- [Update]: added IceConfig options in the Session Options object
- [Fix]: added missing typings in @types/index.d.ts
- [Fix]: fix crash in OTSubscriberLayout [#525](https://github.com/opentok/opentok-react-native/pull/525)

# 0.18.0 (Jun 24, 2021)
- [Update]: update SDKs iOS to 2.20.0 and Android to 2.20.1
- [Fix]: fix crash in OTPublisherLayout when sessionId is null. Fix: https://github.com/opentok/opentok-react-native/issues/462#issuecomment-752171962
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.facebook.react:react-native:${_reactNativeVersion}" // From node_modules
implementation 'com.opentok.android:opentok-android-sdk:2.20.1'
implementation 'com.opentok.android:opentok-android-sdk:2.20.2'
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.opentok.android.VideoUtils;
import com.opentok.android.Session.Builder.TransportPolicy;
import com.opentok.android.Session.Builder.IncludeServers;
import com.opentok.android.Session.Builder.IceServer;
import com.opentok.android.AudioDeviceManager;
import com.opentokreactnative.utils.EventUtils;
import com.opentokreactnative.utils.Utils;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.ArrayList;
import java.util.List;

public class OTSessionManager extends ReactContextBaseJavaModule
implements Session.SessionListener,
Expand Down Expand Up @@ -83,10 +86,9 @@ public void initSession(String apiKey, String sessionId, ReadableMap sessionOpti
OTCustomAudioDriver otCustomAudioDriver = new OTCustomAudioDriver(this.getReactApplicationContext());
AudioDeviceManager.setAudioDevice(otCustomAudioDriver);
}
// Note: IceConfig is an additional property not supported at the moment.
// final ReadableMap iceConfig = sessionOptions.getMap("iceConfig");
// final List<Session.Builder.IceServer> iceConfigServerList = (List<Session.Builder.IceServer>) iceConfig.getArray("customServers");
// final Session.Builder.IncludeServers iceConfigServerConfig; // = iceConfig.getString("includeServers");
final List<IceServer> iceServersList = Utils.sanitizeIceServer(sessionOptions.getArray("customServers"));
final IncludeServers includeServers = Utils.sanitizeIncludeServer(sessionOptions.getString("includeServers"));
final TransportPolicy transportPolicy = Utils.sanitizeTransportPolicy(sessionOptions.getString("transportPolicy"));
final String proxyUrl = sessionOptions.getString("proxyUrl");
String androidOnTop = sessionOptions.getString("androidOnTop");
String androidZOrder = sessionOptions.getString("androidZOrder");
Expand All @@ -108,8 +110,8 @@ public boolean isCamera2Capable() {
}
})
.connectionEventsSuppressed(connectionEventsSuppressed)
// Note: setCustomIceServers is an additional property not supported at the moment.
// .setCustomIceServers(serverList, config)
.setCustomIceServers(iceServersList, includeServers)
.setIceRouting(transportPolicy)
.setIpWhitelist(ipWhitelist)
.setProxyUrl(proxyUrl)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.facebook.react.uimanager.ThemedReactContext;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.Session;
import com.opentok.android.Subscriber;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -34,12 +35,16 @@ public void createSubscriberView(String streamId) {
String pubOrSub = "";
String zOrder = "";
if (mSubscriber != null) {
if (mSubscriber.getSession() != null) {
if (androidOnTopMap.get(mSubscriber.getSession().getSessionId()) != null) {
pubOrSub = androidOnTopMap.get(mSubscriber.getSession().getSessionId());
}
if (androidZOrderMap.get(mSubscriber.getSession().getSessionId()) != null) {
zOrder = androidZOrderMap.get(mSubscriber.getSession().getSessionId());
Session session = mSubscriber.getSession();
if (session != null) {
String sessionId = session.getSessionId();
if (sessionId != null) {
if (androidOnTopMap.get(sessionId) != null) {
pubOrSub = androidOnTopMap.get(sessionId);
}
if (androidZOrderMap.get(sessionId) != null) {
zOrder = androidZOrderMap.get(sessionId);
}
}
}
if (mSubscriber.getView().getParent() != null) {
Expand Down
39 changes: 39 additions & 0 deletions android/src/main/java/com/opentokreactnative/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
import com.opentok.android.PublisherKit;
import com.opentok.android.Subscriber;
import com.opentok.android.SubscriberKit;
import com.opentok.android.Session.Builder.TransportPolicy;
import com.opentok.android.Session.Builder.IncludeServers;
import com.opentok.android.Session.Builder.IceServer;
import com.opentokreactnative.OTRN;

import com.facebook.react.bridge.ReadableArray;

import java.util.ArrayList;
import java.util.Map;
import java.util.List;

public final class Utils {

Expand Down Expand Up @@ -59,4 +65,37 @@ public static String getStreamIdBySubscriber(SubscriberKit subscriberKit) {
}
return "";
}

public static IncludeServers sanitizeIncludeServer(String value) {
IncludeServers includeServers = IncludeServers.All;
if (value != null && value.equals("custom")) {
includeServers = IncludeServers.Custom;
}
return includeServers;
}

public static TransportPolicy sanitizeTransportPolicy(String value) {
TransportPolicy transportPolicy = TransportPolicy.All;
if (value != null && value.equals("relay")) {
transportPolicy = TransportPolicy.Relay;
}
return transportPolicy;
}

public static List<IceServer> sanitizeIceServer(ReadableArray serverList) {
List<IceServer> iceServers = new ArrayList<>();
if (serverList != null) {
for (int i = 0; i < serverList.size(); i++) {
for (int j = 0; j < serverList.getMap(i).getArray("urls").size(); j++) {
iceServers.add(new IceServer(
serverList.getMap(i).getArray("urls").getString(j),
serverList.getMap(i).getString("username"),
serverList.getMap(i).getString("credential")

));
}
}
}
return iceServers;
}
}
30 changes: 28 additions & 2 deletions docs/OTSession.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ class App extends Component {

* **streamPropertyChanged** (Object) - Sent when a stream has started or stopped publishing audio or video or if the video dimensions of the stream have changed.

### Setting Session options:
### Setting Session options:

You can set the session options using the `options` prop. Please note that all session options are optional:

```javascript
class App extends Component {
constructor(props) {
Expand All @@ -99,6 +100,20 @@ class App extends Component {
isCamera2Capable: false, // Android only - default is false
ipWhitelist: false, // https://tokbox.com/developer/sdks/js/reference/OT.html#initSession - ipWhitelist
enableStereoOutput: true // Enable stereo output, default is false
iceConfig:{
transportPolicy: 'all', // Valid options are 'all' or 'relay'. Default is 'all'
includeServers: 'all', // Valid options are 'all' or 'custom'. Default is 'all'
customServers: [
{
urls: [
'turn:123.124.125.126:3478?transport=udp',
'turn:123.124.125.126:3478?transport=tcp'
],
username: 'webrtc',
credential: 'foO0Bar1'
},
],
},
};
}

Expand All @@ -111,4 +126,15 @@ class App extends Component {
);
}
}
```
```

#### Configurable Turn Servers

You can customize TURN server usage for each client in the session in the following ways:

- You can add a list of your own TURN servers that the client will use.
- You can decide whether the client should use your TURN servers exclusively or use them in addition to the OpenTok TURN servers

This feature is available as an [add-on feature](https://tokbox.com/pricing/plans).
Please see [https://tokbox.com/developer/guides/configurable-turn-servers/](https://tokbox.com/developer/guides/configurable-turn-servers/) for a detailed documentation.

1 change: 1 addition & 0 deletions ios/OpenTokReactNative/OTSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class OTSessionManager: RCTEventEmitter {
// settings.iceConfig = sessionOptions["iceConfig"];
settings.proxyURL = Utils.sanitizeStringProperty(sessionOptions["proxyUrl"] as Any);
settings.ipWhitelist = Utils.sanitizeBooleanProperty(sessionOptions["ipWhitelist"] as Any);
settings.iceConfig = Utils.sanitizeIceServer(sessionOptions["customServers"] as Any, sessionOptions["transportPolicy"] as Any, sessionOptions["includeServers"] as Any);
OTRN.sharedState.sessions.updateValue(OTSession(apiKey: apiKey, sessionId: sessionId, delegate: self, settings: settings)!, forKey: sessionId);
}

Expand Down
42 changes: 42 additions & 0 deletions ios/OpenTokReactNative/Utils/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,46 @@ class Utils {
return "CodecNotSupported"
}
}

static func sanitizeIncludeServer(_ value: Any) -> OTSessionICEIncludeServers {
var includeServers = OTSessionICEIncludeServers.all;
if let includeServer = value as? String, includeServer == "custom" {
includeServers = OTSessionICEIncludeServers.custom;
}
return includeServers;
}

static func sanitizeTransportPolicy(_ value: Any) -> OTSessionICETransportPolicy {
var transportPolicy = OTSessionICETransportPolicy.all;
if let policy = value as? String, policy == "relay" {
transportPolicy = OTSessionICETransportPolicy.relay;
}
return transportPolicy;
}

static func sanitiseServerList(_ serverList: Any) -> [(urls: [String], userName: String, credential: String)] {
var iceServerList: [([String], String, String)] = []

if let serverList = serverList as? [[String: Any]] {
for server in serverList {
if let urls = server["urls"] as? [String], let username = server["username"] as? String, let credential = server["credential"] as? String {
iceServerList.append((urls, username, credential))
}
}
}
return iceServerList
}

static func sanitizeIceServer(_ serverList: Any, _ transportPolicy: Any, _ includeServer: Any) -> OTSessionICEConfig {
let myICEServerConfiguration: OTSessionICEConfig = OTSessionICEConfig();
myICEServerConfiguration.includeServers = Utils.sanitizeIncludeServer(includeServer);
myICEServerConfiguration.transportPolicy = Utils.sanitizeTransportPolicy(transportPolicy);
let serverList = Utils.sanitiseServerList(serverList);
for server in serverList {
for url in server.urls {
myICEServerConfiguration.addICEServer(withURL: url, userName: server.userName, credential: server.credential, error: nil);
}
}
return myICEServerConfiguration;
}
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opentok-react-native",
"version": "0.18.0",
"version": "0.19.0",
"description": "React Native components for OpenTok iOS and Android SDKs",
"main": "src/index.js",
"homepage": "https://www.tokbox.com",
Expand Down
Loading

0 comments on commit f7e7447

Please sign in to comment.