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

dispatch session error event #155

Open
wants to merge 1 commit into
base: 3.4.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/android/OpenTokAndroidPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions src/ios/OpenTokPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 6 additions & 0 deletions src/js/OTSession.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions www/opentok.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down