Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #41 from sean-perkins/v3-update
Browse files Browse the repository at this point in the history
{N} V3 Update
  • Loading branch information
Sean Perkins committed May 18, 2017
2 parents 3abdaff + 223b190 commit a2badea
Show file tree
Hide file tree
Showing 20 changed files with 326 additions and 394 deletions.
2 changes: 1 addition & 1 deletion demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<GridLayout rows="*,auto,auto">
<GridLayout>
<OT:TNSOTSubscriber id="subscriber" width="100%" height="100%"></OT:TNSOTSubscriber>
<OT:TNSOTPublisher render_style="fill" id="publisher" verticalAlignment="top" horizontalAlignment="right" margin="10" width="200" height="200"></OT:TNSOTPublisher>
<OT:TNSOTPublisher width="200" height="200" renderStyle="fill" id="publisher" verticalAlignment="top" horizontalAlignment="right" margin="10"></OT:TNSOTPublisher>
</GridLayout>

<StackLayout verticalAlignment="bottom" marginBottom="50">
Expand Down
10 changes: 5 additions & 5 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {TNSOTSession, TNSOTPublisher, TNSOTSubscriber} from 'nativescript-opento
const M = 23;
export class Demo extends Observable {

public _apiKey:string = '45771112';
private _sessionId: string = '1_MX40NTc3MTExMn5-MTQ4NzI1MTY3NTg2NX5JZzFvWHI4NmFLMG1tZnRad2ZwNGl2YTR-UH4';
private _publisherToken: string = 'T1==cGFydG5lcl9pZD00NTc3MTExMiZzaWc9YjY5ODg5ZWNkNWU2YjU0YmY2YjU1ZGFiOGMzZGNlNjQ5OTQ2MjgyZjpzZXNzaW9uX2lkPTFfTVg0ME5UYzNNVEV4TW41LU1UUTROekkxTVRZM05UZzJOWDVKWnpGdldISTRObUZMTUcxdFpuUmFkMlp3TkdsMllUUi1VSDQmY3JlYXRlX3RpbWU9MTQ4NzMzNDkzNSZub25jZT0wLjg3NzA0ODc3ODc1MTA1NTkmcm9sZT1wdWJsaXNoZXImZXhwaXJlX3RpbWU9MTQ4NzkzOTczNA==';
private _subscriberToken: string = 'T1==cGFydG5lcl9pZD00NTc3MTExMiZzaWc9ZGQ2MDIzNWQ1ZDEyZWM4MTZiMzEzMjE2NDNmNTg5Zjg1ZTQ1MmNkYjpzZXNzaW9uX2lkPTFfTVg0ME5UYzNNVEV4TW41LU1UUTROekkxTVRZM05UZzJOWDVKWnpGdldISTRObUZMTUcxdFpuUmFkMlp3TkdsMllUUi1VSDQmY3JlYXRlX3RpbWU9MTQ4NzMzNDk1OSZub25jZT0wLjg2OTkzODk3NTAzNjUxMDcmcm9sZT1wdWJsaXNoZXImZXhwaXJlX3RpbWU9MTQ4NzkzOTc1OA==';
public _apiKey:string = '45829912';
private _sessionId: string = '1_MX40NTgyOTkxMn5-MTQ5NTE0Mzk3NzI2OX5vdzhEdGtBSm40MW5KWU0rY3RFU3FJNUl-fg';
private _publisherToken: string = 'T1==cGFydG5lcl9pZD00NTgyOTkxMiZzaWc9ZDMxMjcxMjE2MTcwZDRkMDY3ZDMyYzg4YmJkODZlYWQ0M2Q0MmQyMTpzZXNzaW9uX2lkPTFfTVg0ME5UZ3lPVGt4TW41LU1UUTVOVEUwTXprM056STJPWDV2ZHpoRWRHdEJTbTQwTVc1S1dVMHJZM1JGVTNGSk5VbC1mZyZjcmVhdGVfdGltZT0xNDk1MTQ0MDAzJm5vbmNlPTAuMjk1ODExOTA1MTIwMDI0MyZyb2xlPXB1Ymxpc2hlciZleHBpcmVfdGltZT0xNDk3NzM2MDAy';
private _subscriberToken: string = 'T1==cGFydG5lcl9pZD00NTgyOTkxMiZzaWc9YTVhNzI5MWZkZWUzZjhhMGRhOWZlMGY2YjYyNzlkYjQ0MWYxOTYwODpzZXNzaW9uX2lkPTFfTVg0ME5UZ3lPVGt4TW41LU1UUTVOVEUwTXprM056STJPWDV2ZHpoRWRHdEJTbTQwTVc1S1dVMHJZM1JGVTNGSk5VbC1mZyZjcmVhdGVfdGltZT0xNDk1MTQ0MDI0Jm5vbmNlPTAuNjk3NTY4MTUzNjA3MTM0MSZyb2xlPXN1YnNjcmliZXImZXhwaXJlX3RpbWU9MTQ5NzczNjAyMw==';
private publisher: TNSOTPublisher;
private subscriber: TNSOTSubscriber;

Expand All @@ -28,7 +28,7 @@ export class Demo extends Observable {
});
this.session.events.on('signalReceived',(data:any)=>{
alert("signal received");
console.dump(data);
console.dir(data);
});
}

Expand Down
1 change: 0 additions & 1 deletion demo/app/references.d.ts
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
/// <reference path="../node_modules/tns-core-modules/tns-core-modules.d.ts" /> Enable smart suggestions and completions in Visual Studio Code JavaScript projects.
10 changes: 5 additions & 5 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"nativescript": {
"id": "com.mobileagility.opentok",
"tns-ios": {
"version": "2.4.0"
"version": "3.0.0"
},
"tns-android": {
"version": "2.4.1"
"version": "3.0.0"
}
},
"dependencies": {
"nativescript-opentok": "file:..",
"tns-core-modules": "^2.4.0"
"tns-core-modules": "^3.0.0"
},
"devDependencies": {
"babel-traverse": "6.7.6",
Expand All @@ -20,7 +20,7 @@
"lazy": "1.0.11",
"nativescript-dev-typescript": "^0.3.2",
"shelljs": "^0.6.0",
"tns-platform-declarations": "^2.4.0",
"typescript": "^2.0.7"
"tns-platform-declarations": "^3.0.0",
"typescript": "^2.2.0"
}
}
18 changes: 17 additions & 1 deletion demo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"removeComments": true,
"preserveConstEnums": true,
"declaration": true,
"noLib": false,
"noEmitHelpers": true,
"experimentalDecorators": true,
"noEmitHelpers": true
"lib": [
"es6",
"dom"
],
"baseUrl": ".",
"paths": {
"*": [
"./node_modules/tns-core-modules/*",
"./node_modules/*"
]
}
},
"exclude": [
"node_modules",
Expand Down
8 changes: 0 additions & 8 deletions opentok.d.ts

This file was deleted.

22 changes: 10 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "nativescript-opentok",
"version": "1.6.8",
"version": "2.0.0",
"description": "Integrates OpenTok for NativeScript.",
"main": "opentok.js",
"typings": "./opentok.d.ts",
"main": "opentok",
"nativescript": {
"platforms": {
"android": "2.4.0",
"ios": "2.4.0"
"android": "3.0.0",
"ios": "3.0.0"
}
},
"scripts": {
Expand Down Expand Up @@ -50,15 +49,14 @@
"homepage": "https://github.com/sean-perkins/nativescript-opentok",
"readmeFilename": "README.md",
"devDependencies": {
"es6-promise": "^3.2.1",
"tns-core-modules": "^2.3.0",
"tns-platform-declarations": "^2.3.0",
"typescript": "^2.0.7",
"prompt": "^1.0.0",
"rimraf": "^2.5.0",
"@types/es6-promise": "0.0.28"
"tns-core-modules": "^3.0.0",
"tns-platform-declarations": "^3.0.0",
"typescript": "^2.2.0"
},
"dependencies": {
"nativescript-permissions":"latest"
},
"peerDependencies": {
"tns-core-modules": "3.0.0"
}
}
79 changes: 39 additions & 40 deletions src/android/publisher.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as utils from "utils/utils";
import * as app from 'application';
import {ContentView} from 'ui/content-view'
import {Observable} from "data/observable";
import {TNSOTSession} from "./session";
import * as utils from "tns-core-modules/utils/utils";
import * as app from 'tns-core-modules/application';
import { View, CssProperty, Style } from 'tns-core-modules/ui/core/view'
import { Observable, fromObject } from "tns-core-modules/data/observable";
import { TNSOTSession } from "./session";
import { RENDERSTYLE } from "../common";
declare var com: any, android: any;
const CameraListener = com.opentok.android.Publisher.CameraListener;
const PublisherListener = com.opentok.android.PublisherKit.PublisherListener;
Expand All @@ -11,50 +12,52 @@ const BaseVideoRenderer = com.opentok.android.BaseVideoRenderer;
const AbsoluteLayout = android.widget.AbsoluteLayout;
const RelativeLayout = android.widget.RelativeLayout;

export class TNSOTPublisher extends ContentView {
private _android: any;
const renderStyle = new CssProperty<Style, string>({
name: 'renderStyle',
cssName: 'render-style',
defaultValue: 'fill',
valueConverter: (v: RENDERSTYLE) => { return String(v) }
});

export class TNSOTPublisher extends View {
private _publisher: any;
public static toggleVideoEvent = "toggleVideo";
public static toggleAudioEvent = "toggleAudio";
public static cycleCameraEvent;
private _events;
_render_style: any;

private _events: any;
private _renderStyle: any;
public renderStyle: any;
constructor() {
super();
this._events = new Observable();
this._events = fromObject({});
}

get android() {
return this._android;
}

get _nativeView() {
return this._android;
return this.nativeView;
}

public _createUI() {
this._android = new android.widget.LinearLayout(this._context);
public createNativeView() {
return new android.widget.LinearLayout(this._context);
}

publish(session: TNSOTSession, name?: string, cameraResolution?: string, cameraFrameRate?: string) {
const that = new WeakRef(this);
this._publisher = new com.opentok.android.Publisher(
utils.ad.getApplicationContext(),
name ? name : '',
TNSOTPublisher.getCameraResolution(cameraResolution),
name ? name : '',
TNSOTPublisher.getCameraResolution(cameraResolution),
TNSOTPublisher.getCameraFrameRate(cameraFrameRate)
);
let pub = this._publisher.getView();
this._android.addView(pub);
this._publisher.getRenderer().setStyle(com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE, this.render_style);
this.nativeView.addView(pub);
this.renderStyle = this._renderStyle;
this._publisher.setPublisherListener(new PublisherListener({
owner: that.get(),
onError(publisher: any, error: any) {
if (this.owner._events) {
this.owner._events.notify({
eventName: 'didFailWithError',
object: new Observable({
object: fromObject({
publisher: publisher,
error: error
})
Expand All @@ -65,7 +68,7 @@ export class TNSOTPublisher extends ContentView {
if (this.owner._events) {
this.owner._events.notify({
eventName: 'streamCreated',
object: new Observable({
object: fromObject({
publisher: publisher,
stream: stream
})
Expand All @@ -76,7 +79,7 @@ export class TNSOTPublisher extends ContentView {
if (this.owner._events) {
this.owner._events.notify({
eventName: 'streamDestroyed',
object: new Observable({
object: fromObject({
publisher: publisher,
stream: stream
})
Expand All @@ -90,7 +93,7 @@ export class TNSOTPublisher extends ContentView {
if (this.owner._events) {
this.owner._events.notify({
eventName: 'cameraChanged',
object: new Observable({
object: fromObject({
publisher: publisher,
cameraId: newCameraId
})
Expand All @@ -100,15 +103,15 @@ export class TNSOTPublisher extends ContentView {
if (this.owner._events) {
this.owner._events.notify({
eventName: 'cameraError',
object: new Observable({
object: fromObject({
publisher: publisher,
error: error
})
});
}
}
}));
session.events.on('sessionDidConnect', (result:any) => {
session.events.on('sessionDidConnect', (result: any) => {
try {
let stream: any = result.object;
session.session.publish(this._publisher);
Expand Down Expand Up @@ -149,23 +152,17 @@ export class TNSOTPublisher extends ContentView {
return com.opentok.android.Publisher.CameraCaptureFrameRate.FPS_30;
}

get render_style() {
return this._render_style;
}

set render_style(value: any) {
[renderStyle.setNative](value: any) {
this._renderStyle = value;
switch (value) {
case 'fit':
this._render_style = com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FIT;
break;
case 'fill':
this._render_style = com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FILL;
this._publisher.getRenderer().setStyle(com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE, com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FILL);
break;
case 'scale':
this._render_style = com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE;
this._publisher.getRenderer().setStyle(com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE, com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE);
break;
default:
this._render_style = com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FIT;
this._publisher.getRenderer().setStyle(com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_SCALE, com.opentok.android.BaseVideoRenderer.STYLE_VIDEO_FIT);
break;
}
}
Expand All @@ -174,9 +171,10 @@ export class TNSOTPublisher extends ContentView {
return this._publisher;
}

get events():Observable{
get events(): Observable {
return this._events;
}

toggleCamera() {
this.publishVideo = !this.publishVideo;
}
Expand Down Expand Up @@ -218,3 +216,4 @@ export class TNSOTPublisher extends ContentView {
}

}
renderStyle.register(Style);
Loading

0 comments on commit a2badea

Please sign in to comment.