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

Commit 2f01aac

Browse files
author
Sean Perkins
authored
Merge pull request #22 from sean-perkins/release-1.6.0
Release 1.5.11
2 parents 45aab2f + 3c4b18e commit 2f01aac

File tree

11 files changed

+94
-41
lines changed

11 files changed

+94
-41
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
*.js
22
*.js.map
3-
*.log
3+
node_modules
44
.idea
55
demo/app/*.js
66
demo/*.d.ts
77
demo/platforms
88
demo/node_modules
99
demo/lib/ios
10-
node_modules
10+
*.log
11+
*.d.ts
12+
!opentok.d.ts

.npmignore

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
demo/
1+
demo
22
*.png
3+
*.jpg
34
*.log
4-
*.map
5-
/*.android.ts
6-
/*.ios.ts
7-
!.d.ts
5+
*.ts
6+
!*.d.ts

demo/app/main-page.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:OT="nativescript-opentok" loaded="pageLoaded">
44
<GridLayout rows="*,auto,auto">
55
<GridLayout>
6-
<StackLayout id="subscriber" width="100%" height="100%"></StackLayout>
6+
<OT:TNSOTSubscriber id="subscriber" width="100%" height="100%"></OT:TNSOTSubscriber>
77
<OT:TNSOTPublisher id="publisher" verticalAlignment="top" horizontalAlignment="right" margin="10" width="200" height="200"></OT:TNSOTPublisher>
88
</GridLayout>
99

@@ -13,6 +13,8 @@
1313
<Button text="Toggle Camera" tap="{{ toggleVideo }}" />
1414
<Button text="Toggle Mute" tap="{{ toggleMute }}" />
1515
<Button text="Stop Publishing" tap="{{ unpublish }}" />
16+
<Button text="Stop Subscribing" tap="{{ unsubscribe }}" />
17+
<Button text="Disconnect" tap="{{ disconnect }}" />
1618
</StackLayout>
1719
</StackLayout>
1820
</GridLayout>

demo/app/main-view-model.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Observable, EventData} from 'data/observable';
33
import {isAndroid, isIOS} from 'platform';
44
import {Page} from 'ui/page';
55

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

88
export class Demo extends Observable {
99

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

1414
private publisher: TNSOTPublisher;
15+
private subscriber: TNSOTSubscriber;
16+
1517
private session: TNSOTSession;
1618

1719
constructor(private page: Page) {
1820
super();
1921
this.session = TNSOTSession.initWithApiKeySessionId(this._apiKey, this._sessionId);
2022
this.publisher = <TNSOTPublisher> this.page.getViewById('publisher');
23+
this.subscriber = <TNSOTSubscriber> this.page.getViewById('subscriber');
2124
this.initPublisher();
25+
this.initSubscriber();
2226
}
2327

2428
initPublisher() {
@@ -29,6 +33,12 @@ export class Demo extends Observable {
2933
});
3034
}
3135

36+
initSubscriber() {
37+
this.session.events.on('streamCreated', () => {
38+
this.subscriber.subscribe(this.session);
39+
});
40+
}
41+
3242
switchCamera() {
3343
this.publisher.cycleCamera();
3444
}
@@ -45,4 +55,12 @@ export class Demo extends Observable {
4555
this.publisher.unpublish(this.session);
4656
}
4757

58+
unsubscribe() {
59+
this.subscriber.unsubscribe(this.session);
60+
}
61+
62+
disconnect() {
63+
this.session.disconnect();
64+
}
65+
4866
}

index.d.ts renamed to opentok.d.ts

File renamed without changes.

opentok.ios.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './src/ios/session';
22
export * from './src/ios/publisher';
3-
export * from './src/ios/subscriber';
3+
export * from './src/ios/subscriber';

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "nativescript-opentok",
3-
"version": "1.5.4",
3+
"version": "1.5.11",
44
"description": "Integrates OpenTok for NativeScript.",
55
"main": "opentok.js",
6-
"typings": "./index.d.ts",
6+
"typings": "./opentok.d.ts",
77
"nativescript": {
88
"platforms": {
99
"android": "2.1.1",

src/ios/publisher.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ export class TNSOTPublisher extends ContentView {
2121
constructor() {
2222
super();
2323
this._publisherKitDelegate = TNSPublisherKitDelegateImpl.initWithOwner(new WeakRef(this));
24-
}
25-
26-
onLoaded() {
27-
super.onLoaded();
28-
UIView.alloc().initWithFrame(CGRectMake(0, 0, this.width, this.height));
24+
this._view = UIView.alloc().init();
2925
}
3026

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

4138
session.events.on('sessionDidConnect', (result) => {

src/ios/session.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ export class TNSOTSession extends NSObject {
1212

1313
public static ObjCProtocols = [OTSessionDelegate];
1414

15-
public subscriber: TNSOTSubscriber;
1615
public _ios: any;
1716

17+
private _stream: any;
1818
private _events: Observable;
19-
private _publisher: TNSOTPublisher;
2019

2120
public static initWithApiKeySessionId(apiKey: string, sessionId: string): TNSOTSession {
2221
let instance = <TNSOTSession>TNSOTSession.new();
@@ -36,17 +35,25 @@ export class TNSOTSession extends NSObject {
3635
disconnect(): void {
3736
if(this._ios) {
3837
try {
39-
this._ios.disconnect();
38+
let errorRef = new interop.Reference();
39+
this._ios.disconnect(errorRef);
40+
if(errorRef.value) {
41+
console.log(errorRef.value);
42+
}
4043
} catch(error) {
4144
console.log(error);
4245
}
4346
}
4447
}
4548

46-
unsubscribe(): void {
49+
unsubscribe(subscriber: any): void {
4750
try {
4851
if(this._ios) {
49-
this._ios.unsubscribe();
52+
let errorRef = new interop.Reference();
53+
this._ios.unsubscribe(subscriber, errorRef);
54+
if(errorRef.value) {
55+
console.log(errorRef.value);
56+
}
5057
}
5158
}
5259
catch(error) {
@@ -58,6 +65,10 @@ export class TNSOTSession extends NSObject {
5865
return this._events;
5966
}
6067

68+
get stream(): any {
69+
return this._stream;
70+
}
71+
6172
public sessionDidConnect(session: any) {
6273
if(this.events) {
6374
this.events.notify({
@@ -104,8 +115,7 @@ export class TNSOTSession extends NSObject {
104115
})
105116
});
106117
}
107-
this.subscriber = new TNSOTSubscriber();
108-
this.subscriber.subscribe(session, stream);
118+
this._stream = stream;
109119
}
110120

111121
public sessionStreamDestroyed(session: any, stream: any) {

src/ios/subscriber.ts

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,59 @@ import {TNSOTSession} from './session';
66
import {TNSOTPublisher} from './publisher';
77

88
declare var OTSubscriber: any,
9-
OTSubscriberKitDelegate: any;
9+
OTStream: any,
10+
OTSubscriberKitDelegate: any,
11+
interop: any;
1012

11-
export class TNSOTSubscriber {
13+
export class TNSOTSubscriber extends ContentView {
1214

1315
private _subscriberKitDelegate: any;
14-
private _subscriber: any;
15-
16-
private _session: any;
16+
private _ios: any;
17+
private _view: UIView;
1718

1819
constructor() {
20+
super();
1921
this._subscriberKitDelegate = TNSSubscriberKitDelegateImpl.initWithOwner(new WeakRef(this));
22+
this._view = UIView.alloc().init();
2023
}
2124

22-
subscribe(session: any, stream: any) {
23-
this._subscriber = new OTSubscriber(stream, this._subscriberKitDelegate);
24-
session.subscribe(this._subscriber);
25+
subscribe(session: any) {
26+
if(session.stream) {
27+
this._ios = new OTSubscriber(session.stream, this._subscriberKitDelegate);
28+
this._ios.view.frame = CGRectMake(0, 0, screen.mainScreen.widthDIPs, screen.mainScreen.heightDIPs);
29+
this._view.addSubview(this._ios.view);
30+
let errorRef = new interop.Reference();
31+
session._ios.subscribeError(this._ios, errorRef);
32+
if(errorRef.value) {
33+
console.log(errorRef.value);
34+
}
35+
}
2536
}
2637

27-
addSubscriberToView(subscriber: any) {
28-
let view = topmost().currentPage.getViewById('subscriber');
29-
if(view) {
30-
this._subscriber.view.frame = CGRectMake(0, 0, screen.mainScreen.widthDIPs, screen.mainScreen.heightDIPs);
31-
view.ios.addSubview(this._subscriber.view);
38+
unsubscribe(session: any) {
39+
try {
40+
let errorRef = new interop.Reference();
41+
session._ios.unsubscribeError(this._ios, errorRef);
42+
if(errorRef.value) {
43+
console.log(errorRef.value);
44+
}
45+
} catch(error) {
46+
console.log(error);
3247
}
3348
}
3449

3550
get events(): Observable {
3651
return this._subscriberKitDelegate.events;
3752
}
3853

54+
get ios(): any {
55+
return this._ios;
56+
}
57+
58+
get _nativeView(): any {
59+
return this._view;
60+
}
61+
3962
}
4063

4164
class TNSSubscriberKitDelegateImpl extends NSObject {
@@ -53,7 +76,6 @@ class TNSSubscriberKitDelegateImpl extends NSObject {
5376
}
5477

5578
subscriberDidFailWithError(subscriber: any, error: any) {
56-
console.log('subscriberDidFailWithError');
5779
if(this._events) {
5880
this._events.notify({
5981
eventName: 'didFailWithError',
@@ -63,6 +85,7 @@ class TNSSubscriberKitDelegateImpl extends NSObject {
6385
})
6486
});
6587
}
88+
console.log(error);
6689
}
6790

6891
subscriberDidConnectToStream(subscriber) {
@@ -75,8 +98,6 @@ class TNSSubscriberKitDelegateImpl extends NSObject {
7598
})
7699
});
77100
}
78-
let owner = this._owner.get();
79-
owner.addSubscriberToView(subscriber);
80101
}
81102

82103
subscriberDidDisconnectFromStream(subscriber: any) {

tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"module": "commonjs",
55
"removeComments": true,
66
"experimentalDecorators": true,
7-
"sourceMap": true
7+
"sourceMap": true,
8+
"declaration": true,
9+
"noEmitOnError": false,
10+
"noEmitHelpers": true,
11+
"noImplicitUseStrict": true
812
},
913
"files": [
1014
"node_modules/tns-core-modules/tns-core-modules.d.ts",

0 commit comments

Comments
 (0)