Open mmubasher opened 5 years ago
We were also having this problem when I was trying to update our own fork of this plugin with the current master.
This is happening because of the fix for https://github.com/opentok/cordova-plugin-opentok/issues/107.
This fix does not wait for the sessionConnected
event. Instead it calls the callback instantly after the Session.connect
is called. And according to the docs:
sessionConnected
: Dispatched locally by the Session object when the connection is established. However, you can pass a completion handler function in as the second parameter of theconnect()
and use this function instead of a listener for thesessionConnected
event.
The completion handler should be called upon connecting, aka on sessionConnected
. This was the case before the fix was implemented.
I think we should partly revert the change into something like this:
OTSession.coffee:
class TBSession
connect: (@token, connectCompletionCallback) ->
if( typeof(connectCompletionCallback) != "function" and connectCompletionCallback? )
TB.showError( "Session.connect() takes a token and an optional completionHandler" )
return
if (connectCompletionCallback?)
errorCallback = (error) -> connectCompletionCallback(error)
@on('sessionConnected', connectCompletionCallback)
Cordova.exec(@eventReceived, TBError, OTPlugin, "addEvent", ["sessionEvents"] )
Cordova.exec(TBSuccess, errorCallback, OTPlugin, "connect", [@token] )
return
...
OpenTokAndroidPlugin.java:
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
...
} else if (action.equals("connect")) {
Log.i(TAG, "connect command called");
mSession.connect(args.getString(0));
} else if (action.equals("disconnect")) {
...
}
OpenTokPlugin.m:
#pragma mark Session Methods
- (void)connect:(CDVInvokedUrlCommand *)command{
NSLog(@"iOS Connecting to Session");
// Get Parameters
OTError *error = nil;
NSString* tbToken = [command.arguments objectAtIndex:0];
[_session connectWithToken:tbToken error:&error];
CDVPluginResult* pluginResult;
if (error) {
NSNumber* code = [NSNumber numberWithInt:[error code]];
NSMutableDictionary* err = [[NSMutableDictionary alloc] init];
[err setObject:error.localizedDescription forKey:@"message"];
[err setObject:code forKey:@"code"];
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:err];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
}
That way we will still have the error handling as was mentioned in https://github.com/opentok/cordova-plugin-opentok/issues/107. And when no errors happens our callback will be triggered when the session is connected, as it should be according to the docs.
What do you think @msach22?
Bug Report
Current behavior
Example Project
Steps to reproduce
What is the current bug behavior?
What is the expected correct behavior?
Relevant logs and/or screenshots Following is the current log. Also, there is no opentok related network log of this cordova application's webview
Network log
Console log
Environment information