Coder Social home page Coder Social logo

nativescript-opentok's Introduction

Nativescript OpenTok

npm npm

A Nativescript plugin for the OpenTok iOS and Android SDK.

OpenTok: https://tokbox.com/developer/

Getting Started

Requirements

  • API Key with OpenTok. Get one here.
  • Ability to generate a valid session id (either through OpenTok account or back-end service)
  • Ability to generate a valid token (either through OpenTok account or back-end service)
  • Opentok.framework requires projects to be built for only armv7 (device); i386 (simulator), armv6, armv7s, and arm64 are not supported.

Installation

Node Package Manager (NPM)

  • npm install nativescript-opentok --save

Integration

Routed Sessions

View

You will first need to import the custom element into the {N} xml view. This can be accomplished by adding this snippet: xmlns:OT="nativescript-opentok" to your existing Page element tag.

The basic integration example would include the following declarations for publisher and subscriber. Notice subscriber is any element with id="subscriber".

<StackLayout id="subscriber" width="100%" height="100%"></StackLayout>
<OT:TNSOTPublisher id="publisher" verticalAlignment="top" horizontalAlignment="right" margin="10" width="100" height="100"></OT:TNSOTPublisher>

Next in your page's binding context (a controller, view model, etc.), you will need to import and hook to the OpenTok implementation.

import {TNSOTSession, TNSOTPublisher, TNSOTSubscriber} from 'nativescript-opentok';

private _apiKey:string = 'API_KEY';
private _sessionId: string = 'SESSION_ID';
private _token: string = 'TOKEN';

private publisher: TNSOTPublisher;
private subscriber: TNSOTSubscriber;

private session: TNSOTSession;

constructor(private page: Page) {
   super();
   this.session = TNSOTSession.initWithApiKeySessionId(this._apiKey, this._sessionId);
   this.publisher = <TNSOTPublisher> this.page.getViewById('publisher');
   this.subscriber = <TNSOTSubscriber> this.page.getViewById('subscriber');
   this.initPublisher();
   this.initSubscriber();
}

initPublisher() {
   this.session.connect(this._token);
   this.publisher.publish(this.session, '', 'HIGH', '30');
   this.publisher.events.on('streamDestroyed', (result) => {
       console.log('publisher stream destroyed');
   });
}

initSubscriber() {
   this.session.events.on('streamCreated', () => {
       this.subscriber.subscribe(this.session);
   });
}

Special Articles

Images

iPhone iPad
iPhone Image iPad Image

Notes

  • Publishing is not supported in the Simulator because it does not have access to your webcam. You may see a yellow tea-kettle instead.
  • TNS stands for Telerik NativeScript

nativescript-opentok's People

Contributors

triniwiz avatar joshjensen avatar tushar-1health avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.