diff --git a/src/android/OpenTokAndroidPlugin.java b/src/android/OpenTokAndroidPlugin.java index c5be5bad..2668e28e 100644 --- a/src/android/OpenTokAndroidPlugin.java +++ b/src/android/OpenTokAndroidPlugin.java @@ -19,7 +19,6 @@ import android.os.Build; import android.content.pm.PackageManager; import android.annotation.SuppressLint; -import android.app.AlertDialog; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; @@ -710,14 +709,6 @@ public void onRequestPermissionResult(int requestCode, String[] permissions, int } } - public void alertUser(String message) { - // 1. Instantiate an AlertDialog.Builder with its constructor - AlertDialog.Builder builder = new AlertDialog.Builder(cordova.getActivity()); - builder.setMessage(message).setTitle("TokBox Message"); - AlertDialog dialog = builder.create(); - } - - // sessionListener @Override public void onConnected(Session arg0) { @@ -815,9 +806,14 @@ public void onStreamReceived(Session arg0, Stream arg1) { @Override public void onError(Session arg0, OpentokError arg1) { - // TODO Auto-generated method stub Log.e(TAG, "session exception: " + arg1.getMessage()); - alertUser("session error " + arg1.getMessage()); + JSONObject data = new JSONObject(); + try { + data.put("message", arg1.getMessage()); + data.put("code", arg1.getErrorCode()); + } catch (JSONException e) { + } + triggerJSEvent("sessionEvents", "error", data); } // connectionListener diff --git a/src/ios/OpenTokPlugin.m b/src/ios/OpenTokPlugin.m index 579ac102..e579943c 100644 --- a/src/ios/OpenTokPlugin.m +++ b/src/ios/OpenTokPlugin.m @@ -644,11 +644,8 @@ - (void)session:(OTSession*)session didFailWithError:(OTError*)error { [err setObject:error.localizedDescription forKey:@"message"]; [err setObject:code forKey:@"code"]; - if (self.exceptionId) { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary: err]; - [pluginResult setKeepCallbackAsBool:YES]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:self.exceptionId]; - } + [self triggerJSEvent: @"sessionEvents" withType: @"error" withData: err]; + } - (void)sessionDidDisconnect:(OTSession*)session{ NSString* alertMessage = [NSString stringWithFormat:@"Session disconnected: (%@)", session.sessionId]; diff --git a/src/js/OTSession.coffee b/src/js/OTSession.coffee index 60c5999d..bf9bdfa8 100644 --- a/src/js/OTSession.coffee +++ b/src/js/OTSession.coffee @@ -277,6 +277,12 @@ class TBSession streamEvent.id = event.id @dispatchEvent(streamEvent) return @ + error: (event) -> + errorEvent = new TBEvent("error") + errorEvent.message = event.message + errorEvent.code = event.code + @dispatchEvent(errorEvent) + return @ # deprecating diff --git a/www/opentok.js b/www/opentok.js index b2ad493c..f63a40e6 100644 --- a/www/opentok.js +++ b/www/opentok.js @@ -911,6 +911,15 @@ TBSession = (function() { return this; }; + TBSession.prototype.error = function(event) { + var errorEvent; + errorEvent = new TBEvent("error"); + errorEvent.message = event.message; + errorEvent.code = event.code; + this.dispatchEvent(errorEvent); + return this; + }; + TBSession.prototype.addEventListener = function(event, handler) { this.on(event, handler); return this;