Skip to content

lucienbl/react-native-vivox

Repository files navigation

react-native-vivox

Getting started

$ yarn add react-native-vivox

Mostly automatic installation (RN < 0.60)

$ react-native link react-native-vivox

Additional steps

Android

  1. Unzip aar.zip(download) in android
  2. Add the following code in android/app/build.gradle
repositories {
    flatDir {
        dirs "../aar"
    }
}

dependencies {
    // ...
    debugImplementation(name: 'sdk-debug', ext: 'aar')
    releaseImplementation(name: 'sdk-release', ext: 'aar')
}
  1. Add the following code in android/app/src/main/java/com.package.name/MainApplication.java
import com.vivox.sdk.JniHelpers; // <-- this line

// ...

@Override
public void onCreate() {
  super.onCreate();
  JniHelpers.init(getApplicationContext(), null, new String[]{"mvc"}); // <-- this line
}

iOS

  1. Add (link) libvivoxsdk.a (from /react-native-vivox/ios/core/Libraries/${CONFIGURATION}/libvivoxsdk.a) into Frameworks
  2. Add (link) libresolv.tbd (download) into Frameworks
  3. Add the following to your App's Info.plist
<key>NSMicrophoneUsageDescription</key>
<string>Need microphone access to communicate with other players</string>
<key>UIBackgroundModes</key>
<array>
  <string>audio</string>
  <string>voip</string>
</array>

Usage

Example

This example will connect your app to your Vivox server and join the test123 voice channel. Make sure you requested microphone permission before!

import React from 'react';
import * as Vivox from 'react-native-vivox';

class App extends React.Component {
  async componentDidMount(): void {
    await Vivox.connect("https://vdx5.www.vivox.com/api2/", "issuer", "vdx5.vivox.com");
    await Vivox.login("userId", "loginToken");
    await Vivox.joinChannel("test123", "joinToken");
  }

  render() {
    return null;
  }
}

export default App;

Example app: https://github.com/lucienbl/react-native-vivox-demo

Connect to the Vivox server

Vivox.connect("server", "issuer", "realm"); // returns Promise<>

Login the user

Vivox.login("userId", "loginToken"); // returns Promise<>

Join a channel

Vivox.joinChannel("channelId", "joinToken"); // returns Promise<>

Leave current channel

Vivox.leaveChannel(); // returns Promise<>

Disconnect from the Vivox server

Vivox.disconnect(); // returns Promise<>

Retrieve the current state integer

Vivox.getState(); // returns Promise<number>

Retrieve the current state name

Vivox.getStateName(); // returns Promise<string>

Mute the current player

Vivox.muteMyself(true); // returns Promise<>

Retrieve if the current player is muted or not

Vivox.isMuted(); // returns Promise<boolean>

Retrieve the currently speaking players

Vivox.getSpeakingParticipants(); // returns Promise<Object>

Mute / Unmute a player for the current user

Vivox.setParticipantMutedForMe("targetUserId", true); // returns Promise<>

Mute / Unmute everyone for the current user

Vivox.setAudioOutputDeviceMuted(true); // returns Promise<>

Set volume (between 0 and 100) for a target player

Vivox.setParticipantAudioOutputDeviceVolumeForMe("targetUserId", 50); // returns Promise<>