Code Monkey home page Code Monkey 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 tushar-1health avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

nativescript-opentok's Issues

Better Implementation of Appending Video Stream

Currently the video streams are added to the activity/frame using an absolute layout. I believe the video streams are actually added to a new activity that is placed over the existing foreground activity.

Investigate a better way to control where the video streams are published to. Ideally you would be able to specify a container ID to append the stream to.

If this is not possible, we need to find a better way to allow users to change the video stream's location and size, after it has been appended to the view.

Parent Issue: #12

Support in iOS and android

Hello. My team and I are looking for a solution to integrate video chat into our Nativescript application. We're starting this portion of development in the next few days and we had a couple of questions; hoping you could help us answer them:

  1. How is the support for OpenTok on mobile devices? Is this something we could use to support all sorts of arm devices? If not, is there another solution out there that can help us facilitate that?
  2. Do you have any advice on using this plugin in a production environment?

Investigate Overlaying UI Components on top of Video Stream

Investigate the difficulty and possibility of overlaying native UI components on-top of the video streams, controlled from the demo app.

Example circumstances would be:

  • Play/pause buttons
  • Toggle camera button (front-facing to back camera)
  • Mute button
  • Dragging subscriber video stream around screen (similar to FaceTime)

Parent issue: #12

Publisher element height and width in %

Hello,

I stumbled upon a weird issue today. If we configure the element

<TNSOTSubscriber #subscriber id="subscriber" width="1" height="1"></TNSOTSubscriber>
<TNSOTPublisher #publisher id="publisher" width="100%" height="100%"></TNSOTPublisher>

The app crashes in iOS device. However, as soon as we set a defined height and width to the publisher element it works out fine.

Could you help me with it

integrate with Angular 2

Hello,
I have build an ionic 2 app. I want to add video call between users and came upon your plugin. I have looked over the wiki regarding angular 2 integration, but it does not work.

import {TNSOTSession, TNSOTPublisher, TNSOTSubscriber} from "nativescript-opentok";
this displays an error like: Cannot find module "nativescript-opentok"

I installed the library using this command:
npm install nativescript-opentok --save

Could you please help me solve this problem ?

[Webpack] CssProperty is not a constructor or android of undefined.

Hello,

I am trying to build on webpacks. This is what I'm getting, sometimes the error contains CssProperty is not a constructor which belongs to opentok plugin or else android of undefined as show below:

ERROR:

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to create application com.tns.NativeScriptApplication: com.tns.NativeScriptException: 

Error calling module function 

Error calling module function 

TypeError: Cannot read property 'android' of undefined
File: "file:///data/data/com.patient/files/app/bundle.js, line: 34446, column: 25

StackTrace: 
	Frame: function:'', file:'file:///data/data/com.patient/files/app/bundle.js', line: 34446, column: 26
	Frame: function:'__webpack_require__', file:'file:///data/data/com.patient/files/app/vendor.js', line: 53, column: 30
	Frame: function:'', file:'file:///data/data/com.patient/files/app/bundle.js', line: 8640, column: 10
	Frame: function:'__webpack_require__', file:'file:///data/data/com.patient/files/app/vendor.js', line: 53, column: 30
	Frame: function:'', file:'file:///data/data/com.patient/files/app/bundle.js', line: 28095, column: 30
	Frame: function:'__webpack_require__', file:'file:///

Line: 34446

/***/ }),
/* 551 */
/* no static exports found */
/* all exports used */
/*!********************************************************!*\
  !*** ../~/nativescript-opentok/src/android/session.js ***!
  \********************************************************/
/***/ (function(module, exports, __webpack_require__) {

"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var observable_1 = __webpack_require__(/*! tns-core-modules/data/observable */ 61);
var utils = __webpack_require__(/*! tns-core-modules/utils/utils */ 12);
var Session = com.opentok.android.Session;

Line 34446 is var Session = com.opentok.android.Session;

I hope this will help resolve the issue.

nativescript Angular 4+ support

Hi there, I'm not sure if this works in angular 4+ nativescript mobile application, I'm always receiving an undefined Session error and not sure if this works on such versions. Can you please tell me if it could run in tns angular 4+?? thanks

camera feed does not refresh when publish

live camera looks fine when publish for the first time. then i tap "stop publish" the camera freeze. when i tap the "start publish" button again, it remain frozen.

Angular2 error TS2307: Cannot find module 'nativescript-opentok'.

First off, really excited to use Tokbox on angular2. I followed the instructions for the Opentok angular2 integration and am still having this issue. I have tried re installing the module and re running npm install. Was wondering if there is something I am missing in the instructions?
screen shot 2017-08-02 at 8 08 26 pm
screen shot 2017-08-02 at 8 08 54 pm
screen shot 2017-08-02 at 8 09 27 pm

Android API Contract

Do your best to match the existing call signature for iOS, in Android. We need to expose the event callbacks (listeners) from the Android SDK to the demo app, in order to allow users to attach custom logic to event firings.

For example, in iOS the demo app has this call signature:

this._session.sessionEvents.on('sessionDidConnect', (result) => {
    console.log('sessionConnected event');
    this._session.publish();
    this._session.publisherEvents.on('streamCreated', () => {
        console.log('streamCreated event on publisher object');
    });
});

Parent task: #12

Fix Video Issue on Android

Currently in Android, the device will force quit the camera as soon as it attempts to publish the feed. Identify the issue causing the camera to quit and fix it, so that the publisher camera is visible on the device and/or emulator.

Parent issue: #12

Subscribe to Stream - Android

Refer to this diagram:

image

The device needs to follow the appropriate flow to allow two users to publisher and subscribe to each other's feeds. Their camera feeds should display on each other's devices, as well as their own camera feed should be visible on the screen. Think of the same concept as iOS FaceTime.

Image

Parent issue: #12

this.publisher.events return undefined

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

I got error message : TypeError: Cannot read property 'on' of undefined

Subscribe shows black screen

Hello,

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

This will help as subscribe needs a stream object while subscribing.

However, this too doesn't work I tried and it shows a black screen in subscriber.

@sean-perkins Any help in subscribing? I can see that the device is publishing here https://tokbox.com/developer/tools/playground/ but it does not subscribe, all I can see is a particular black screen.

Error: Could not find module 'nativescript-opentok'

Hi Sean, great plugin!
When I run the demo I get the following error:
file:///app/main-view-model.js:3:37: JS ERROR Error: Could not find module 'nativescript-opentok'.

Do you know how I can fix this?
Thanks

Error: File is not under 'rootDir'. 'rootDir' is expected to contain all source files.

I tried to implement your plugin in my angular2 project and getting these errors during compilation:

error TS6059: File '../node_modules/nativescript-opentok/opentok.ios.ts' is not under 'rootDir' '../app'. 'rootDir' is expected to contain all source files.

error TS6059: File '../node_modules/nativescript-opentok/src/common.ts' is not under 'rootDir' '../app'. 'rootDir' is expected to contain all source files.

error TS6059: File '../node_modules/nativescript-opentok/src/ios/publisher-delegate.ts' is not under 'rootDir' '../app'. 'rootDir' is expected to contain all source files.

error TS6059: File '../node_modules/nativescript-opentok/src/ios/publisher.ts' is not under 'rootDir' '../app'. 'rootDir' is expected to contain all source files.
error TS6059: File '../node_modules/nativescript-opentok/src/ios/session-delegate.ts' is not under 'rootDir' '../app'. 'rootDir' is expected to contain all source files.
error TS6059: File '../node_modules/nativescript-opentok/src/ios/session.ts' is not under 'rootDir' '../app'. 'rootDir' is expected to contain all source files.

I guess it's a similar problem to "Remove *.ts files from src during publishing to npm": https://github.com/ocombe/ng2-translate/issues/4

Thank you

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.