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 #22 from sean-perkins/release-1.6.0
Browse files Browse the repository at this point in the history
Release 1.5.11
  • Loading branch information
Sean Perkins authored Sep 13, 2016
2 parents 45aab2f + 3c4b18e commit 2f01aac
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 41 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
*.js
*.js.map
*.log
node_modules
.idea
demo/app/*.js
demo/*.d.ts
demo/platforms
demo/node_modules
demo/lib/ios
node_modules
*.log
*.d.ts
!opentok.d.ts
9 changes: 4 additions & 5 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
demo/
demo
*.png
*.jpg
*.log
*.map
/*.android.ts
/*.ios.ts
!.d.ts
*.ts
!*.d.ts
4 changes: 3 additions & 1 deletion demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:OT="nativescript-opentok" loaded="pageLoaded">
<GridLayout rows="*,auto,auto">
<GridLayout>
<StackLayout id="subscriber" width="100%" height="100%"></StackLayout>
<OT:TNSOTSubscriber id="subscriber" width="100%" height="100%"></OT:TNSOTSubscriber>
<OT:TNSOTPublisher id="publisher" verticalAlignment="top" horizontalAlignment="right" margin="10" width="200" height="200"></OT:TNSOTPublisher>
</GridLayout>

Expand All @@ -13,6 +13,8 @@
<Button text="Toggle Camera" tap="{{ toggleVideo }}" />
<Button text="Toggle Mute" tap="{{ toggleMute }}" />
<Button text="Stop Publishing" tap="{{ unpublish }}" />
<Button text="Stop Subscribing" tap="{{ unsubscribe }}" />
<Button text="Disconnect" tap="{{ disconnect }}" />
</StackLayout>
</StackLayout>
</GridLayout>
Expand Down
20 changes: 19 additions & 1 deletion demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Observable, EventData} from 'data/observable';
import {isAndroid, isIOS} from 'platform';
import {Page} from 'ui/page';

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

export class Demo extends Observable {

Expand All @@ -12,13 +12,17 @@ export class Demo extends Observable {
private _publisherToken: string = 'T1==cGFydG5lcl9pZD00NTY0NDIwMiZzaWc9ODMwYzUyMTEwMjk5ODQ1OGQ3YmJlOWY1MDFhOGU2MGQwZGQyMmQyYjpzZXNzaW9uX2lkPTFfTVg0ME5UWTBOREl3TW41LU1UUTNNakl5TnpVM05UQXdNMzVGY3pGV01IZFZla054ZVhOYWJXUlNUVWRJVWtwalJtUi1mZyZjcmVhdGVfdGltZT0xNDcyODQ4NDk1Jm5vbmNlPTAuNjYyMzAzOTA2MTY2OTI2JnJvbGU9cHVibGlzaGVyJmV4cGlyZV90aW1lPTE0NzU0NDA0OTU=';

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() {
Expand All @@ -29,6 +33,12 @@ export class Demo extends Observable {
});
}

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

switchCamera() {
this.publisher.cycleCamera();
}
Expand All @@ -45,4 +55,12 @@ export class Demo extends Observable {
this.publisher.unpublish(this.session);
}

unsubscribe() {
this.subscriber.unsubscribe(this.session);
}

disconnect() {
this.session.disconnect();
}

}
File renamed without changes.
2 changes: 1 addition & 1 deletion opentok.ios.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './src/ios/session';
export * from './src/ios/publisher';
export * from './src/ios/subscriber';
export * from './src/ios/subscriber';
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "nativescript-opentok",
"version": "1.5.4",
"version": "1.5.11",
"description": "Integrates OpenTok for NativeScript.",
"main": "opentok.js",
"typings": "./index.d.ts",
"typings": "./opentok.d.ts",
"nativescript": {
"platforms": {
"android": "2.1.1",
Expand Down
7 changes: 2 additions & 5 deletions src/ios/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ export class TNSOTPublisher extends ContentView {
constructor() {
super();
this._publisherKitDelegate = TNSPublisherKitDelegateImpl.initWithOwner(new WeakRef(this));
}

onLoaded() {
super.onLoaded();
UIView.alloc().initWithFrame(CGRectMake(0, 0, this.width, this.height));
this._view = UIView.alloc().init();
}

publish(session: TNSOTSession, name?:string, cameraResolution?: string, cameraFrameRate?: string): void {
Expand All @@ -36,6 +32,7 @@ export class TNSOTPublisher extends ContentView {
this.getCameraFrameRate(cameraFrameRate)
);
this._ios.view.frame = CGRectMake(0, 0, this.width, this.height);
// this._view.frame = CGRectMake(this.originX, this.originY, this.width, this.height);
this._view.addSubview(this._ios.view);

session.events.on('sessionDidConnect', (result) => {
Expand Down
24 changes: 17 additions & 7 deletions src/ios/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ export class TNSOTSession extends NSObject {

public static ObjCProtocols = [OTSessionDelegate];

public subscriber: TNSOTSubscriber;
public _ios: any;

private _stream: any;
private _events: Observable;
private _publisher: TNSOTPublisher;

public static initWithApiKeySessionId(apiKey: string, sessionId: string): TNSOTSession {
let instance = <TNSOTSession>TNSOTSession.new();
Expand All @@ -36,17 +35,25 @@ export class TNSOTSession extends NSObject {
disconnect(): void {
if(this._ios) {
try {
this._ios.disconnect();
let errorRef = new interop.Reference();
this._ios.disconnect(errorRef);
if(errorRef.value) {
console.log(errorRef.value);
}
} catch(error) {
console.log(error);
}
}
}

unsubscribe(): void {
unsubscribe(subscriber: any): void {
try {
if(this._ios) {
this._ios.unsubscribe();
let errorRef = new interop.Reference();
this._ios.unsubscribe(subscriber, errorRef);
if(errorRef.value) {
console.log(errorRef.value);
}
}
}
catch(error) {
Expand All @@ -58,6 +65,10 @@ export class TNSOTSession extends NSObject {
return this._events;
}

get stream(): any {
return this._stream;
}

public sessionDidConnect(session: any) {
if(this.events) {
this.events.notify({
Expand Down Expand Up @@ -104,8 +115,7 @@ export class TNSOTSession extends NSObject {
})
});
}
this.subscriber = new TNSOTSubscriber();
this.subscriber.subscribe(session, stream);
this._stream = stream;
}

public sessionStreamDestroyed(session: any, stream: any) {
Expand Down
53 changes: 37 additions & 16 deletions src/ios/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,59 @@ import {TNSOTSession} from './session';
import {TNSOTPublisher} from './publisher';

declare var OTSubscriber: any,
OTSubscriberKitDelegate: any;
OTStream: any,
OTSubscriberKitDelegate: any,
interop: any;

export class TNSOTSubscriber {
export class TNSOTSubscriber extends ContentView {

private _subscriberKitDelegate: any;
private _subscriber: any;

private _session: any;
private _ios: any;
private _view: UIView;

constructor() {
super();
this._subscriberKitDelegate = TNSSubscriberKitDelegateImpl.initWithOwner(new WeakRef(this));
this._view = UIView.alloc().init();
}

subscribe(session: any, stream: any) {
this._subscriber = new OTSubscriber(stream, this._subscriberKitDelegate);
session.subscribe(this._subscriber);
subscribe(session: any) {
if(session.stream) {
this._ios = new OTSubscriber(session.stream, this._subscriberKitDelegate);
this._ios.view.frame = CGRectMake(0, 0, screen.mainScreen.widthDIPs, screen.mainScreen.heightDIPs);
this._view.addSubview(this._ios.view);
let errorRef = new interop.Reference();
session._ios.subscribeError(this._ios, errorRef);
if(errorRef.value) {
console.log(errorRef.value);
}
}
}

addSubscriberToView(subscriber: any) {
let view = topmost().currentPage.getViewById('subscriber');
if(view) {
this._subscriber.view.frame = CGRectMake(0, 0, screen.mainScreen.widthDIPs, screen.mainScreen.heightDIPs);
view.ios.addSubview(this._subscriber.view);
unsubscribe(session: any) {
try {
let errorRef = new interop.Reference();
session._ios.unsubscribeError(this._ios, errorRef);
if(errorRef.value) {
console.log(errorRef.value);
}
} catch(error) {
console.log(error);
}
}

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

get ios(): any {
return this._ios;
}

get _nativeView(): any {
return this._view;
}

}

class TNSSubscriberKitDelegateImpl extends NSObject {
Expand All @@ -53,7 +76,6 @@ class TNSSubscriberKitDelegateImpl extends NSObject {
}

subscriberDidFailWithError(subscriber: any, error: any) {
console.log('subscriberDidFailWithError');
if(this._events) {
this._events.notify({
eventName: 'didFailWithError',
Expand All @@ -63,6 +85,7 @@ class TNSSubscriberKitDelegateImpl extends NSObject {
})
});
}
console.log(error);
}

subscriberDidConnectToStream(subscriber) {
Expand All @@ -75,8 +98,6 @@ class TNSSubscriberKitDelegateImpl extends NSObject {
})
});
}
let owner = this._owner.get();
owner.addSubscriberToView(subscriber);
}

subscriberDidDisconnectFromStream(subscriber: any) {
Expand Down
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"module": "commonjs",
"removeComments": true,
"experimentalDecorators": true,
"sourceMap": true
"sourceMap": true,
"declaration": true,
"noEmitOnError": false,
"noEmitHelpers": true,
"noImplicitUseStrict": true
},
"files": [
"node_modules/tns-core-modules/tns-core-modules.d.ts",
Expand Down

0 comments on commit 2f01aac

Please sign in to comment.