mirror of https://github.com/jitsi/jitsi-meet
The current implementation doesn't use the API and Transport modules. This is due to the fact that they are too tied to APP at the moment, which is web only. Once API is refactored and moved into the Redux store this will be adjusted, though it's unlikely that the lowest level React Native module (ExternalAPI) changes drastically. This commit also introduces a stopgap limitation of only allowing a single instance for JitsiMeetView objects on both Android and iOS. React Native doesn't really play well with having multiple instances of the same modules on the same bridge, since they behave a bit like singletons. Even if we were to use multiple bridges, some features depend on system-level global state, such as the AVAudioSession mode or Android's immersive mode. Further attempts will be made at lifting this limitation in the future, though.pull/1633/merge
parent
ddea60efe9
commit
a075f24000
@ -0,0 +1,108 @@ |
||||
/* |
||||
* Copyright @ 2017-present Atlassian Pty Ltd |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.jitsi.meet.sdk.externalapi; |
||||
|
||||
import com.facebook.react.bridge.ReactApplicationContext; |
||||
import com.facebook.react.bridge.ReactContextBaseJavaModule; |
||||
import com.facebook.react.bridge.ReactMethod; |
||||
import com.facebook.react.bridge.ReadableMap; |
||||
|
||||
import org.jitsi.meet.sdk.JitsiMeetView; |
||||
|
||||
import java.util.HashMap; |
||||
|
||||
|
||||
/** |
||||
* Module implementing a simple API to enable a proximity sensor-controlled |
||||
* wake lock. When the lock is held, if the proximity sensor detects a nearby |
||||
* object it will dim the screen and disable touch controls. The functionality |
||||
* is used with the conference audio-only mode. |
||||
*/ |
||||
public class ExternalAPIModule extends ReactContextBaseJavaModule { |
||||
/** |
||||
* React Native module name. |
||||
*/ |
||||
private static final String MODULE_NAME = "ExternalAPI"; |
||||
|
||||
/** |
||||
* Initializes a new module instance. There shall be a single instance of |
||||
* this module throughout the lifetime of the application. |
||||
* |
||||
* @param reactContext the {@link ReactApplicationContext} where this module |
||||
* is created. |
||||
*/ |
||||
public ExternalAPIModule(ReactApplicationContext reactContext) { |
||||
super(reactContext); |
||||
} |
||||
|
||||
/** |
||||
* Gets the name of this module to be used in the React Native bridge. |
||||
* |
||||
* @return The name of this module to be used in the React Native bridge. |
||||
*/ |
||||
@Override |
||||
public String getName() { |
||||
return MODULE_NAME; |
||||
} |
||||
|
||||
/** |
||||
* Dispatches an event that occurred on JavaScript to the view's listener. |
||||
* @param name - Event name. |
||||
* @param data - Ancillary data for the event. |
||||
*/ |
||||
@ReactMethod |
||||
public void sendEvent(final String name, ReadableMap data) { |
||||
JitsiMeetView view = JitsiMeetView.getInstance(); |
||||
JitsiMeetView.Listener listener = view != null ? view.getListener() : null; |
||||
|
||||
if (listener == null) { |
||||
return; |
||||
} |
||||
|
||||
// TODO: Sigh, converting a ReadableMap to a HashMap is not supported until React Native
|
||||
// 0.46.
|
||||
final HashMap<String, Object> dataMap = new HashMap<>(); |
||||
|
||||
try { |
||||
switch (name) { |
||||
case "CONFERENCE_FAILED": |
||||
dataMap.put("error", data.getString("error")); |
||||
dataMap.put("url", data.getString("url")); |
||||
listener.onConferenceFailed(dataMap); |
||||
break; |
||||
case "CONFERENCE_JOINED": |
||||
dataMap.put("url", data.getString("url")); |
||||
listener.onConferenceJoined(dataMap); |
||||
break; |
||||
case "CONFERENCE_LEFT": |
||||
dataMap.put("url", data.getString("url")); |
||||
listener.onConferenceLeft(dataMap); |
||||
break; |
||||
case "CONFERENCE_WILL_JOIN": |
||||
dataMap.put("url", data.getString("url")); |
||||
listener.onConferenceWillJoin(dataMap); |
||||
break; |
||||
case "CONFERENCE_WILL_LEAVE": |
||||
dataMap.put("url", data.getString("url")); |
||||
listener.onConferenceWillLeave(dataMap); |
||||
break; |
||||
} |
||||
} catch (UnsupportedOperationException e) { |
||||
// Allow partial interface implementations.
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,64 @@ |
||||
/* |
||||
* Copyright @ 2017-present Atlassian Pty Ltd |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.jitsi.meet.sdk.externalapi; |
||||
|
||||
import com.facebook.react.ReactPackage; |
||||
import com.facebook.react.bridge.JavaScriptModule; |
||||
import com.facebook.react.bridge.NativeModule; |
||||
import com.facebook.react.bridge.ReactApplicationContext; |
||||
import com.facebook.react.uimanager.ViewManager; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* Implements {@link ReactPackage} for {@link ExternalAPIModule}. |
||||
*/ |
||||
public class ExternalAPIPackage implements ReactPackage { |
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public List<Class<? extends JavaScriptModule>> createJSModules() { |
||||
return Collections.emptyList(); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
* |
||||
* @return List of native modules to be exposed by React Native. |
||||
*/ |
||||
@Override |
||||
public List<NativeModule> createNativeModules( |
||||
ReactApplicationContext reactContext) { |
||||
List<NativeModule> modules = new ArrayList<>(); |
||||
|
||||
modules.add(new ExternalAPIModule(reactContext)); |
||||
|
||||
return modules; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritDoc} |
||||
*/ |
||||
@Override |
||||
public List<ViewManager> createViewManagers( |
||||
ReactApplicationContext reactContext) { |
||||
return Collections.emptyList(); |
||||
} |
||||
} |
@ -0,0 +1,66 @@ |
||||
/* |
||||
* Copyright @ 2017-present Atlassian Pty Ltd |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
#import "RCTBridgeModule.h" |
||||
|
||||
#import "JitsiMeetView.h" |
||||
|
||||
|
||||
@interface ExternalAPI : NSObject<RCTBridgeModule> |
||||
@end |
||||
|
||||
@implementation ExternalAPI |
||||
|
||||
RCT_EXPORT_MODULE(); |
||||
|
||||
/** |
||||
* Dispatches an event that occurred on JavaScript to the view's delegate. |
||||
* |
||||
* - name: name of the event. |
||||
* - data: dictionary (JSON object in JS) with data associated with the event. |
||||
*/ |
||||
RCT_EXPORT_METHOD(sendEvent:(NSString*)name data:(NSDictionary *) data) { |
||||
JitsiMeetView *view = [JitsiMeetView getInstance]; |
||||
id delegate = view != nil ? view.delegate : nil; |
||||
|
||||
if (delegate == nil) { |
||||
return; |
||||
} |
||||
|
||||
if ([name isEqualToString:@"CONFERENCE_FAILED"] && |
||||
[delegate respondsToSelector:@selector(conferenceFailed:)]) { |
||||
|
||||
[delegate conferenceFailed:data]; |
||||
} else if ([name isEqualToString:@"CONFERENCE_JOINED"] && |
||||
[delegate respondsToSelector:@selector(conferenceJoined:)]) { |
||||
|
||||
[delegate conferenceJoined:data]; |
||||
} else if ([name isEqualToString:@"CONFERENCE_LEFT"] && |
||||
[delegate respondsToSelector:@selector(conferenceLeft:)]) { |
||||
|
||||
[delegate conferenceLeft:data]; |
||||
} else if ([name isEqualToString:@"CONFERENCE_WILL_JOIN"] && |
||||
[delegate respondsToSelector:@selector(conferenceWillJoin:)]) { |
||||
|
||||
[delegate conferenceWillJoin:data]; |
||||
} else if ([name isEqualToString:@"CONFERENCE_WILL_LEAVE"] && |
||||
[delegate respondsToSelector:@selector(conferenceWillLeave:)]) { |
||||
|
||||
[delegate conferenceWillLeave:data]; |
||||
} |
||||
} |
||||
|
||||
@end |
@ -0,0 +1 @@ |
||||
import './middleware'; |
@ -0,0 +1,75 @@ |
||||
/* @flow */ |
||||
|
||||
import { NativeModules } from 'react-native'; |
||||
|
||||
import { getInviteURL } from '../../base/connection'; |
||||
import { |
||||
CONFERENCE_FAILED, |
||||
CONFERENCE_JOINED, |
||||
CONFERENCE_LEFT, |
||||
CONFERENCE_WILL_JOIN, |
||||
CONFERENCE_WILL_LEAVE |
||||
} from '../../base/conference'; |
||||
import { MiddlewareRegistry } from '../../base/redux'; |
||||
|
||||
|
||||
/** |
||||
* Middleware that captures Redux actions and uses the ExternalAPI module to |
||||
* turn them into native events so the application knows about them. |
||||
* |
||||
* @param {Store} store - Redux store. |
||||
* @returns {Function} |
||||
*/ |
||||
MiddlewareRegistry.register(store => next => action => { |
||||
const eventData = {}; |
||||
|
||||
switch (action.type) { |
||||
case CONFERENCE_FAILED: { |
||||
eventData.error = action.error; |
||||
eventData.url = getInviteURL(store.getState()); |
||||
_sendEvent('CONFERENCE_FAILED', eventData); |
||||
break; |
||||
} |
||||
|
||||
case CONFERENCE_JOINED: { |
||||
eventData.url = getInviteURL(store.getState()); |
||||
_sendEvent('CONFERENCE_JOINED', eventData); |
||||
break; |
||||
} |
||||
|
||||
case CONFERENCE_LEFT: { |
||||
eventData.url = getInviteURL(store.getState()); |
||||
_sendEvent('CONFERENCE_LEFT', eventData); |
||||
break; |
||||
} |
||||
|
||||
case CONFERENCE_WILL_JOIN: { |
||||
eventData.url = getInviteURL(store.getState()); |
||||
_sendEvent('CONFERENCE_WILL_JOIN', eventData); |
||||
break; |
||||
} |
||||
|
||||
case CONFERENCE_WILL_LEAVE: { |
||||
eventData.url = getInviteURL(store.getState()); |
||||
_sendEvent('CONFERENCE_WILL_LEAVE', eventData); |
||||
break; |
||||
} |
||||
|
||||
} |
||||
|
||||
return next(action); |
||||
}); |
||||
|
||||
/** |
||||
* Sends the given event to the native side of the application. Applications can |
||||
* then listen to the events using the mechanisms provided by the Jitsi Meet |
||||
* SDK. |
||||
* |
||||
* @param {string} name - Event name. |
||||
* @param {Object} data - Ancillary data for the event. |
||||
* @private |
||||
* @returns {void} |
||||
*/ |
||||
function _sendEvent(name: string, data: Object) { |
||||
NativeModules.ExternalAPI.sendEvent(name, data); |
||||
} |
Loading…
Reference in new issue