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

Element driven approach - 1.4.0 #17

Merged
merged 15 commits into from
Aug 29, 2016
Prev Previous commit
Next Next commit
Fixes publisher delegate events not being bound
  • Loading branch information
Sean Perkins committed Aug 29, 2016
commit 840136e696391df50b27d17cb83f824ee945701f
32 changes: 13 additions & 19 deletions src/ios/publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ export class TNSOTPublisher extends ContentView {
if(this._apiKey && this._sessionId && this._token) {
let session = new TNSOTSession(this._apiKey);
session.initSession(this._sessionId).then((result) => {
session.connect(this._token).then((result) => {
this.publishStream(result);
}, (error) => {
session.connect(this._token).then(() => {}, (error) => {
console.log('Failed to connect to session: ' + error);
});
}, (error) => {
console.log('Failed to initialize session: ' + error);
});
session.events.on('sessionDidConnect', (result) => {
this.publishStream(result.object);
});
}
}

Expand Down Expand Up @@ -103,6 +104,10 @@ export class TNSOTPublisher extends ContentView {
}
}

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

}

class TNSPublisherKitDelegateImpl extends NSObject {
Expand All @@ -121,19 +126,8 @@ class TNSPublisherKitDelegateImpl extends NSObject {
return publisherKitDelegate;
}

didChangeCameraPosition(publisher: any, position: any) {
if(this._events) {
this._events.notify({
eventName: 'didChangeCameraPosition',
object: new Observable({
publisher: publisher,
position: position
})
});
}
}

streamCreated(publisher: any, stream: any) {
public publisherStreamCreated(publisher: any, stream: any) {
console.log('Your own published stream was created!');
if(this._events) {
this._events.notify({
eventName: 'streamCreated',
Expand All @@ -143,10 +137,9 @@ class TNSPublisherKitDelegateImpl extends NSObject {
})
});
}
console.log('stream created for publisher delegate!');
}

streamDestroyed(publisher: any, stream: any) {
public publisherStreamDestroyed(publisher: any, stream: any) {
if(this._events) {
this._events.notify({
eventName: 'streamDestroyed',
Expand All @@ -158,7 +151,7 @@ class TNSPublisherKitDelegateImpl extends NSObject {
}
}

didFailWithError(publisher: any, error: any) {
public publisherDidFailWithError(publisher: any, error: any) {
if(this._events) {
this._events.notify({
eventName: 'didFailWithError',
Expand All @@ -168,6 +161,7 @@ class TNSPublisherKitDelegateImpl extends NSObject {
})
});
}
console.log('publisher did fail with error!');
}

get events(): Observable {
Expand Down
8 changes: 2 additions & 6 deletions src/ios/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ export class TNSOTSession {
});
}

publish() {
this._publisher = new TNSOTPublisher();
this._publisher.publish(this._session);
}

/**
* Converts the OTSessionErrorCode values into meaningful error messages for debugging purposes
*
Expand Down Expand Up @@ -146,7 +141,7 @@ class TNSSessionDelegateImpl extends NSObject {
if(this._events) {
this._events.notify({
eventName: 'sessionDidConnect',
object: new Observable(session)
object: session
});
}
}
Expand Down Expand Up @@ -227,6 +222,7 @@ class TNSSessionDelegateImpl extends NSObject {
})
});
}
console.log('connection created!!');
}

sessionArchiveStartedWithId(session:any, archiveId: string, name?: string) {
Expand Down