rn: refactor conference events

Consolidate all failure cases into a single one: CONFERENCE_TERMINATED. If the
conference ended gracefully no error indicator will be present, otherwise there
will be.
This commit is contained in:
Saúl Ibarra Corretgé 2019-03-07 13:07:48 +01:00
parent f696a6dbe2
commit d39290f9fa
9 changed files with 57 additions and 168 deletions

View File

@ -376,29 +376,20 @@ This is a static method.
`JitsiMeetViewListener` provides an interface apps can implement to listen to
the state of the Jitsi Meet conference displayed in a `JitsiMeetView`.
`JitsiMeetViewAdapter`, a default implementation of the
`JitsiMeetViewListener` interface is also provided. Apps may extend the class
instead of implementing the interface in order to minimize boilerplate.
##### onConferenceFailed
Called when a joining a conference was unsuccessful or when there was an error
while in a conference.
The `data` `Map` contains an "error" key describing the error and a "url" key
with the conference URL.
#### onConferenceJoined
Called when a conference was joined.
The `data` `Map` contains a "url" key with the conference URL.
#### onConferenceLeft
#### onConferenceTerminated
Called when a conference was left.
Called when a conference was terminated either by user choice or due to a
failure.
The `data` `Map` contains a "url" key with the conference URL.
The `data` `Map` contains an "error" key with the error and a "url" key
with the conference URL. If the conference finished gracefully no `error`
key will be present.
#### onConferenceWillJoin
@ -406,20 +397,6 @@ Called before a conference is joined.
The `data` `Map` contains a "url" key with the conference URL.
#### onConferenceWillLeave
Called before a conference is left.
The `data` `Map` contains a "url" key with the conference URL.
#### onLoadConfigError
Called when loading the main configuration file from the Jitsi Meet deployment
fails.
The `data` `Map` contains an "error" key with the error and a "url" key with the
conference URL which necessitated the loading of the configuration file.
## ProGuard rules
When using the SDK on a project some proguard rules have to be added in order

View File

@ -107,18 +107,8 @@ public class MainActivity extends JitsiMeetActivity {
}
@Override
public void onConferenceFailed(Map<String, Object> data) {
Log.d(TAG, "Conference failed: " + data);
}
@Override
public void onConferenceLeft(Map<String, Object> data) {
Log.d(TAG, "Conference left: " + data);
}
@Override
public void onLoadConfigError(Map<String, Object> data) {
Log.d(TAG, "Error loading config: " + data);
public void onConferenceTerminated(Map<String, Object> data) {
Log.d(TAG, "Conference terminated: " + data);
}
// Activity lifecycle method overrides

View File

@ -154,20 +154,14 @@ public class JitsiMeetActivity extends FragmentActivity
// JitsiMeetViewListener
//
@Override
public void onConferenceFailed(Map<String, Object> data) {
Log.d(TAG, "Conference failed: " + data);
finish();
}
@Override
public void onConferenceJoined(Map<String, Object> data) {
Log.d(TAG, "Conference joined: " + data);
}
@Override
public void onConferenceLeft(Map<String, Object> data) {
Log.d(TAG, "Conference left: " + data);
public void onConferenceTerminated(Map<String, Object> data) {
Log.d(TAG, "Conference terminated: " + data);
finish();
}
@ -175,15 +169,4 @@ public class JitsiMeetActivity extends FragmentActivity
public void onConferenceWillJoin(Map<String, Object> data) {
Log.d(TAG, "Conference will join: " + data);
}
@Override
public void onConferenceWillLeave(Map<String, Object> data) {
Log.d(TAG, "Conference will leave: " + data);
}
@Override
public void onLoadConfigError(Map<String, Object> data) {
Log.d(TAG, "Error loading config: " + data);
finish();
}
}

View File

@ -186,9 +186,7 @@ public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener> {
this.url = url;
break;
case "CONFERENCE_FAILED":
case "CONFERENCE_WILL_LEAVE":
case "LOAD_CONFIG_ERROR":
case "CONFERENCE_TERMINATED":
if (url != null && url.equals(this.url)) {
this.url = null;
}

View File

@ -22,15 +22,6 @@ import java.util.Map;
* Interface for listening to events coming from Jitsi Meet.
*/
public interface JitsiMeetViewListener {
/**
* Called when joining a conference fails or an ongoing conference is
* interrupted due to a failure.
*
* @param data Map with an "error" key describing the problem, and a "url"
* key with the conference URL.
*/
void onConferenceFailed(Map<String, Object> data);
/**
* Called when a conference was joined.
*
@ -39,11 +30,14 @@ public interface JitsiMeetViewListener {
void onConferenceJoined(Map<String, Object> data);
/**
* Called when the conference was left, typically after hanging up.
* Called when the active conference ends, be it because of user choice or
* because of a failure.
*
* @param data Map with a "url" key with the conference URL.
* @param data Map with an "error" key with the error and a "url" key with
* the conference URL. If the conference finished gracefully no `error`
* key will be present.
*/
void onConferenceLeft(Map<String, Object> data);
void onConferenceTerminated(Map<String, Object> data);
/**
* Called before the conference is joined.
@ -51,21 +45,4 @@ public interface JitsiMeetViewListener {
* @param data Map with a "url" key with the conference URL.
*/
void onConferenceWillJoin(Map<String, Object> data);
/**
* Called before the conference is left.
*
* @param data Map with a "url" key with the conference URL.
*/
void onConferenceWillLeave(Map<String, Object> data);
/**
* Called when loading the main configuration file from the Jitsi Meet
* deployment fails.
*
* @param data Map with an "error" key with the error and a "url" key with
* the conference URL which necessitated the loading of the configuration
* file.
*/
void onLoadConfigError(Map<String, Object> data);
}

View File

@ -128,25 +128,20 @@ fail?
All methods in this delegate are optional.
##### conferenceFailed
Called when a joining a conference was unsuccessful or when there was an error
while in a conference.
The `data` dictionary contains an "error" key describing the error and a "url"
key with the conference URL.
#### conferenceJoined
Called when a conference was joined.
The `data` dictionary contains a "url" key with the conference URL.
#### conferenceLeft
#### conferenceTerminated
Called when a conference was left.
Called when a conference was terminated either by user choice or due to a
failure.
The `data` dictionary contains a "url" key with the conference URL.
The `data` dictionary contains an "error" key with the error and a "url" key
with the conference URL. If the conference finished gracefully no `error`
key will be present.
#### conferenceWillJoin
@ -154,12 +149,6 @@ Called before a conference is joined.
The `data` dictionary contains a "url" key with the conference URL.
#### conferenceWillLeave
Called before a conference is left.
The `data` dictionary contains a "url" key with the conference URL.
#### enterPictureInPicture
Called when entering Picture-in-Picture is requested by the user. The app should
@ -170,15 +159,6 @@ associated with Picture-in-Picture.)
The `data` dictionary is empty.
#### loadConfigError
Called when loading the main configuration file from the Jitsi Meet deployment
fails.
The `data` dictionary contains an "error" key with the error and a "url" key
with the conference URL which necessitated the loading of the configuration
file.
### Picture-in-Picture
`JitsiMeetView` will automatically adjust its UI when presented in a

View File

@ -54,10 +54,6 @@
#endif
}
- (void)conferenceFailed:(NSDictionary *)data {
[self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_FAILED" withData:data];
}
- (void)conferenceJoined:(NSDictionary *)data {
[self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_JOINED" withData:data];
@ -92,20 +88,12 @@
}
- (void)conferenceLeft:(NSDictionary *)data {
[self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_LEFT" withData:data];
- (void)conferenceTerminated:(NSDictionary *)data {
[self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_TERMINATED" withData:data];
}
- (void)conferenceWillJoin:(NSDictionary *)data {
[self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_WILL_JOIN" withData:data];
}
- (void)conferenceWillLeave:(NSDictionary *)data {
[self _onJitsiMeetViewDelegateEvent:@"CONFERENCE_WILL_LEAVE" withData:data];
}
- (void)loadConfigError:(NSDictionary *)data {
[self _onJitsiMeetViewDelegateEvent:@"LOAD_CONFIG_ERROR" withData:data];
}
@end

View File

@ -18,15 +18,6 @@
@optional
/**
* Called when a joining a conference was unsuccessful or when there was an
* error while in a conference.
*
* The `data` dictionary contains an `error` key describing the error and a
* `url` key with the conference URL.
*/
- (void)conferenceFailed:(NSDictionary *)data;
/**
* Called when a conference was joined.
*
@ -35,11 +26,14 @@
- (void)conferenceJoined:(NSDictionary *)data;
/**
* Called when a conference was left.
* Called when the active conference ends, be it because of user choice or
* because of a failure.
*
* The `data` dictionary contains a `url` key with the conference URL.
* The `data` dictionary contains an `error` key with the error and a `url` key
* with the conference URL. If the conference finished gracefully no `error`
* key will be present.
*/
- (void)conferenceLeft:(NSDictionary *)data;
- (void)conferenceTerminated:(NSDictionary *)data;
/**
* Called before a conference is joined.
@ -48,13 +42,6 @@
*/
- (void)conferenceWillJoin:(NSDictionary *)data;
/**
* Called before a conference is left.
*
* The `data` dictionary contains a `url` key with the conference URL.
*/
- (void)conferenceWillLeave:(NSDictionary *)data;
/**
* Called when entering Picture-in-Picture is requested by the user. The app
* should now activate its Picture-in-Picture implementation (and resize the
@ -66,14 +53,4 @@
*/
- (void)enterPictureInPicture:(NSDictionary *)data;
/**
* Called when loading the main configuration file from the Jitsi Meet
* deployment file.
*
* The `data` dictionary contains an `error` key with the error and a `url` key
* with the conference URL which necessitated the loading of the configuration
* file.
*/
- (void)loadConfigError:(NSDictionary *)data;
@end

View File

@ -5,7 +5,6 @@ import {
CONFERENCE_JOINED,
CONFERENCE_LEFT,
CONFERENCE_WILL_JOIN,
CONFERENCE_WILL_LEAVE,
JITSI_CONFERENCE_URL_KEY,
SET_ROOM,
forEachConference,
@ -19,6 +18,12 @@ import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture';
import { sendEvent } from './functions';
/**
* Event which will be emitted on the native side to indicate the conference
* has ended either by user request or because an error was produced.
*/
const CONFERENCE_TERMINATED = 'CONFERENCE_TERMINATED';
/**
* Middleware that captures Redux actions and uses the ExternalAPI module to
* turn them into native events so the application knows about them.
@ -55,7 +60,6 @@ MiddlewareRegistry.register(store => next => action => {
case CONFERENCE_JOINED:
case CONFERENCE_LEFT:
case CONFERENCE_WILL_JOIN:
case CONFERENCE_WILL_LEAVE:
_sendConferenceEvent(store, action);
break;
@ -73,7 +77,7 @@ MiddlewareRegistry.register(store => next => action => {
sendEvent(
store,
getSymbolDescription(type),
CONFERENCE_TERMINATED,
/* data */ {
error: _toErrorString(error),
url: toURLString(locationURL)
@ -159,12 +163,27 @@ function _sendConferenceEvent(
data.url = toURLString(conference[JITSI_CONFERENCE_URL_KEY]);
}
_swallowEvent(store, action, data)
|| sendEvent(store, getSymbolDescription(type), data);
if (_swallowEvent(store, action, data)) {
return;
}
let type_;
switch (type) {
case CONFERENCE_FAILED:
case CONFERENCE_LEFT:
type_ = CONFERENCE_TERMINATED;
break;
default:
type_ = getSymbolDescription(type);
break;
}
sendEvent(store, type_, data);
}
/**
* Sends {@link CONFERENCE_FAILED} event when the {@link CONNECTION_FAILED}
* Sends {@link CONFERENCE_TERMINATED} event when the {@link CONNECTION_FAILED}
* occurs. It should be done only if the connection fails before the conference
* instance is created. Otherwise the eventual failure event is supposed to be
* emitted by the base/conference feature.
@ -186,7 +205,7 @@ function _sendConferenceFailedOnConnectionError(store, action) {
conference => conference.getConnection() !== connection)
&& sendEvent(
store,
getSymbolDescription(CONFERENCE_FAILED),
CONFERENCE_TERMINATED,
/* data */ {
url: toURLString(locationURL),
error: action.error.name