Search code examples
javascriptandroidreact-nativeopentok

opentok-react-native subscriber crash the android app


I'm trying to implement the OpenTok Lib for react-native but I'm facing some issues that I can't figured it out yet. First one, and I think the most important, is that I can't connect as a Subscriber to a session without crashing the App, that occurs only on android devices, and for that I can't see if it's working the connections between two phones.

What am I doing wrong?


Appointment

import React, { Component } from 'react';
import { OTSession } from 'opentok-react-native';

import { TokBox } from '../../../helpers/constants';
import PublisherStream from './PublisherStream';
import SubscriberStream from './SubscriberStream';

class Appointment extends Component {
  static navigationOptions = {
    header: null
  };

  render() {
    const { navigation: { navigate, state: { params } } } = this.props;
    return (
      <OTSession style={{ flex: 1 }}
        apiKey={TokBox.API_KEY}
        sessionId={params.sessionId}
        token={params.token}
        eventHandlers={this.sessionEventHandlers}>
        <PublisherStream style={{ borderColor: 'red', borderWidth: 3, height: '50%' }} />
        <SubscriberStream style={{ borderColor: 'blue', borderWidth: 3, height: '50%' }} />
      </OTSession>
    );
  }
}

export default Appointment;

PublisherStream

import React, { Component } from 'react';
import { OTPublisher } from 'opentok-react-native';

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


  render() {
    return (
      <OTPublisher style={this.props.style} eventHandlers={this.publisherEventHandlers} />
    );
  }
}

export default PublisherStream;

SubscriberStream

import React, { Component } from 'react';
import { OTSubscriber } from 'opentok-react-native';

class SubscriberStream extends Component {
  subscriberProperties = {
    subscribeToAudio: true,
    subscribeToVideo: true,
  };

  subscriberEventHandler = {
    connected(event) {
      console.log('connected', event);
    },
    disconnected(event) {
      console.log('disconnected', event);
    },
    videoDataReceived(event) {
      console.log('videoDataReceived', event);
    },
    videoEnabled(event) {
      console.log('videoEnabled', event);
    },
    videoNetworkStats(event) {
      console.log('videoNetworkStats', event);
    }
  };

  render() {
    return (
      <OTSubscriber
        properties={this.subscriberProperties}
        eventHandlers={this.subscriberEventHandler}
        style={this.props.style}
      />
    );
  }
}

export default SubscriberStream;

Package.json

{
  {...omitted}
  "dependencies": {
    "opentok-react-native": "^0.9.5",
    "react": "^16.8.1",
    "react-native": "0.58.4",
  },
  {...omitted}
}


Solution

  • Actually, the problem was that I was trying to stream video from a subscriber, which can't be done in this way....

    The answer is in here: https://github.com/opentok/opentok-react-native/issues/239