Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #103 from opentok/3.3.0
Browse files Browse the repository at this point in the history
v3.3.0
  • Loading branch information
Manik Sachdeva authored May 30, 2018
2 parents 59beecb + 55ef06c commit 4c71d67
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![OpenTok Labs](https://d26dzxoao6i3hh.cloudfront.net/items/0U1R0a0e2g1E361H0x3c/Image%202017-11-22%20at%2012.16.38%20PM.png?v=2507a2df)
# Cordova Plugin for OpenTok iOS and Android
![OpenTok Labs](https://d26dzxoao6i3hh.cloudfront.net/items/0U1R0a0e2g1E361H0x3c/Image%202017-11-22%20at%2012.16.38%20PM.png?v=2507a2df)

##### Disclaimer: This plugin is based on the [Cordova OpenTok Plugin](https://github.com/songz/cordova-plugin-opentok/). Please keep in mind that this is an OpenTok Labs project which means that it's not officially supported by TokBox.

Expand Down
20 changes: 10 additions & 10 deletions src/android/OpenTokAndroidPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ public void updateZIndices() {
for (RunnableUpdateViews viewContainer : allStreamViews) {
// Set depth location of camera view based on CSS z-index.
// See: https://developer.android.com/reference/android/view/View.html#setTranslationZ(float)
viewContainer.mView.setTranslationZ(viewContainer.getZIndex());

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
viewContainer.mView.setTranslationZ(viewContainer.getZIndex());
}
// If the zIndex is 0(default) bring the view to the top, last one wins.
// See: https://github.com/saghul/cordova-plugin-iosrtc/blob/5b6a180b324c8c9bac533fa481a457b74183c740/src/PluginMediaStreamRenderer.swift#L191
if(viewContainer.getZIndex() == 0) {
Expand Down Expand Up @@ -270,7 +271,9 @@ public void run() {

// Set depth location of camera view based on CSS z-index.
// See: https://developer.android.com/reference/android/view/View.html#setTranslationZ(float)
this.mView.setTranslationZ(this.getZIndex());
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
this.mView.setTranslationZ(this.getZIndex());
}
}
super.run();
}
Expand Down Expand Up @@ -380,7 +383,9 @@ public void run() {

// Set depth location of camera view based on CSS z-index.
// See: https://developer.android.com/reference/android/view/View.html#setTranslationZ(float)
this.mView.setTranslationZ(this.getZIndex());
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
this.mView.setTranslationZ(this.getZIndex());
}
Log.i(TAG, "subscriber view is added to parent view!");
}
super.run();
Expand Down Expand Up @@ -550,12 +555,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo

// publisher methods
} else if (action.equals("setCameraPosition")) {
String cameraId = args.getString(0);
if (cameraId.equals("front")) {
myPublisher.mPublisher.setCameraId(1);
} else if (cameraId.equals("back")) {
myPublisher.mPublisher.setCameraId(0);
}
myPublisher.mPublisher.cycleCamera();
} else if (action.equals("publishAudio")) {
String val = args.getString(0);
boolean publishAudio = true;
Expand Down
8 changes: 7 additions & 1 deletion src/ios/OpenTokPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ - (void)subscriberVideoDisableWarningLifted:(OTSubscriberKit*)sub{
- (void)subscriberVideoEnabled:(OTSubscriberKit*)sub reason:(OTSubscriberVideoEventReason)reason{
NSMutableDictionary* eventData = [[NSMutableDictionary alloc] init];
NSString* reasonData = [self validateReason: reason];

[eventData setObject: reasonData forKey:@"reason"];
[self triggerJSEvent: @"subscriberEvents" withType: @"videoEnabled" withData: eventData];
}
Expand Down Expand Up @@ -616,6 +616,12 @@ - (void)sessionDidDisconnect:(OTSession*)session{
if( _publisher ){
[_publisher.view removeFromSuperview];
}
// Remove session observers
for ( id key in streamDictionary ) {
[self removeObserversFromStream: [streamDictionary objectForKey:key]];
}

[streamDictionary removeAllObjects];

// Setting up event object
NSMutableDictionary* eventData = [[NSMutableDictionary alloc] init];
Expand Down
2 changes: 1 addition & 1 deletion src/js/OTPublisher.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TBPublisher
eventReceived: (response) =>
@[response.eventType](response.data)
streamCreated: (event) =>
@stream = new TBStream( event.stream, @session.sessionConnection )
@stream = new TBStream( event.stream, @session.sessionConnected )
streamEvent = new TBEvent("streamCreated")
streamEvent.stream = @stream
@dispatchEvent(streamEvent)
Expand Down
13 changes: 12 additions & 1 deletion src/js/OTSession.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -69,41 +69,49 @@ class TBSession
# stream,domId, properties, completionHandler
subscriber = new TBSubscriber(one, two, three)
@subscriberCallbacks[one.streamId] = four
@subscribers[one.streamId] = subscriber
return subscriber
if( three? )
# stream, domId, properties || stream, domId, completionHandler || stream, properties, completionHandler
if( (typeof(two) == "string" || two.nodeType == 1 || two instanceof Element) && typeof(three) == "object" )
console.log("stream, domId, props")
subscriber = new TBSubscriber(one, two, three)
@subscribers[one.streamId] = subscriber
return subscriber
if( (typeof(two) == "string" || two.nodeType == 1 || two instanceof Element) && typeof(three) == "function" )
console.log("stream, domId, completionHandler")
@subscriberCallbacks[one.streamId]=three
subscriber = new TBSubscriber(one, two, {})
@subscribers[one.streamId] = subscriber
return subscriber
if(typeof(two) == "object" && typeof(three) == "function" )
console.log("stream, props, completionHandler")
@subscriberCallbacks[one.streamId] = three
domId = TBGenerateDomHelper()
subscriber = new TBSubscriber( one, domId, two )
@subscribers[one.streamId] = subscriber
return subscriber
if( two? )
# stream, domId || stream, properties || stream,completionHandler
if( (typeof(two) == "string" || two.nodeType == 1 || two instanceof Element) )
subscriber = new TBSubscriber(one, two, {})
@subscribers[one.streamId] = subscriber
return subscriber
if( typeof(two) == "object" )
domId = TBGenerateDomHelper()
subscriber = new TBSubscriber(one, domId, two)
@subscribers[one.streamId] = subscriber
return subscriber
if( typeof(two) == "function" )
@subscriberCallbacks[one.streamId] = two
domId = TBGenerateDomHelper()
subscriber = new TBSubscriber(one, domId, {})
@subscribers[one.streamId] = subscriber
return subscriber
# stream
domId = TBGenerateDomHelper()
subscriber = new TBSubscriber(one, domId, {})
@subscribers[one.streamId] = subscriber
return subscriber
unpublish:() ->
@alreadyPublishing = false
Expand All @@ -129,6 +137,7 @@ class TBSession
@apiKey = @apiKey.toString()
@connections = {}
@streams = {}
@subscribers = {}
@alreadyPublishing = false
OT.getHelper().eventing(@)
Cordova.exec(TBSuccess, TBSuccess, OTPlugin, "initSession", [@apiKey, @sessionId] )
Expand Down Expand Up @@ -219,8 +228,10 @@ class TBSession
return @
streamPropertyChanged: (event) ->
stream = new TBStream(event.stream, @connections[event.stream.connectionId])
if(stream.streamId == "TBPublisher")
if(@publisher && @publisher.stream && @publisher.stream.streamId == stream.streamId)
@publisher.stream = stream
else if(@subscribers[stream.streamId])
@subscribers[stream.streamId].stream = stream
@streams[stream.streamId] = stream

streamEvent = new TBEvent("streamPropertyChanged")
Expand Down
1 change: 1 addition & 0 deletions src/js/OTSubscriber.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class TBSubscriber
@element = document.getElementById(divObject)

@streamId = stream.streamId
@stream = stream
if(properties? && properties.width=="100%" && properties.height == "100%")
@element.style.width="100%"
@element.style.height="100%"
Expand Down
16 changes: 14 additions & 2 deletions www/opentok.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ TBPublisher = (function() {

TBPublisher.prototype.streamCreated = function(event) {
var streamEvent;
this.stream = new TBStream(event.stream, this.session.sessionConnection);
this.stream = new TBStream(event.stream, this.session.sessionConnected);
streamEvent = new TBEvent("streamCreated");
streamEvent.stream = this.stream;
this.dispatchEvent(streamEvent);
Expand Down Expand Up @@ -605,47 +605,55 @@ TBSession = (function() {
if ((four != null)) {
subscriber = new TBSubscriber(one, two, three);
this.subscriberCallbacks[one.streamId] = four;
this.subscribers[one.streamId] = subscriber;
return subscriber;
}
if ((three != null)) {
if ((typeof two === "string" || two.nodeType === 1 || two instanceof Element) && typeof three === "object") {
console.log("stream, domId, props");
subscriber = new TBSubscriber(one, two, three);
this.subscribers[one.streamId] = subscriber;
return subscriber;
}
if ((typeof two === "string" || two.nodeType === 1 || two instanceof Element) && typeof three === "function") {
console.log("stream, domId, completionHandler");
this.subscriberCallbacks[one.streamId] = three;
subscriber = new TBSubscriber(one, two, {});
this.subscribers[one.streamId] = subscriber;
return subscriber;
}
if (typeof two === "object" && typeof three === "function") {
console.log("stream, props, completionHandler");
this.subscriberCallbacks[one.streamId] = three;
domId = TBGenerateDomHelper();
subscriber = new TBSubscriber(one, domId, two);
this.subscribers[one.streamId] = subscriber;
return subscriber;
}
}
if ((two != null)) {
if (typeof two === "string" || two.nodeType === 1 || two instanceof Element) {
subscriber = new TBSubscriber(one, two, {});
this.subscribers[one.streamId] = subscriber;
return subscriber;
}
if (typeof two === "object") {
domId = TBGenerateDomHelper();
subscriber = new TBSubscriber(one, domId, two);
this.subscribers[one.streamId] = subscriber;
return subscriber;
}
if (typeof two === "function") {
this.subscriberCallbacks[one.streamId] = two;
domId = TBGenerateDomHelper();
subscriber = new TBSubscriber(one, domId, {});
this.subscribers[one.streamId] = subscriber;
return subscriber;
}
}
domId = TBGenerateDomHelper();
subscriber = new TBSubscriber(one, domId, {});
this.subscribers[one.streamId] = subscriber;
return subscriber;
};

Expand Down Expand Up @@ -696,6 +704,7 @@ TBSession = (function() {
this.apiKey = this.apiKey.toString();
this.connections = {};
this.streams = {};
this.subscribers = {};
this.alreadyPublishing = false;
OT.getHelper().eventing(this);
Cordova.exec(TBSuccess, TBSuccess, OTPlugin, "initSession", [this.apiKey, this.sessionId]);
Expand Down Expand Up @@ -827,8 +836,10 @@ TBSession = (function() {
TBSession.prototype.streamPropertyChanged = function(event) {
var stream, streamEvent;
stream = new TBStream(event.stream, this.connections[event.stream.connectionId]);
if (stream.streamId === "TBPublisher") {
if (this.publisher && this.publisher.stream && this.publisher.stream.streamId === stream.streamId) {
this.publisher.stream = stream;
} else if (this.subscribers[stream.streamId]) {
this.subscribers[stream.streamId].stream = stream;
}
this.streams[stream.streamId] = stream;
streamEvent = new TBEvent("streamPropertyChanged");
Expand Down Expand Up @@ -990,6 +1001,7 @@ TBSubscriber = (function() {
this.element = document.getElementById(divObject);
}
this.streamId = stream.streamId;
this.stream = stream;
if ((properties != null) && properties.width === "100%" && properties.height === "100%") {
this.element.style.width = "100%";
this.element.style.height = "100%";
Expand Down

0 comments on commit 4c71d67

Please sign in to comment.