[RN] Add ability to skip the welcome page

Also expose this in the native SDKs.
This commit is contained in:
Saúl Ibarra Corretgé 2017-06-09 12:30:59 +02:00 committed by Lyubo Marinov
parent 79d51bc379
commit 4687c1f465
13 changed files with 182 additions and 10 deletions

View File

@ -85,10 +85,17 @@ public class MainActivity extends AppCompatActivity {
This class encapsulates a high level API in the form of an Android `Activity` This class encapsulates a high level API in the form of an Android `Activity`
which displays a single `JitsiMeetView`. which displays a single `JitsiMeetView`.
#### getWelcomePageDisabled()
See JitsiMeetView.getWelcomePageDisabled.
#### loadURL(url) #### loadURL(url)
See JitsiMeetView.loadURL. See JitsiMeetView.loadURL.
#### setWelcomePageDisabled(disabled)
See JitsiMeetView.setWelcomePageDisabled.
### JitsiMeetView ### JitsiMeetView
@ -99,6 +106,11 @@ display a Jitsi Meet conference (or a welcome page).
Returns the `JitsiMeetViewListener` instance attached to the view. Returns the `JitsiMeetViewListener` instance attached to the view.
#### getWelcomePageDisabled()
Returns true if the welcome page is disable,d false if not. If the welcome page
is disabled, a black empty view will be rendered when not in a conference.
#### loadURL(url) #### loadURL(url)
Loads the given URL and joins the room. If `null` is specified, the welcome page Loads the given URL and joins the room. If `null` is specified, the welcome page
@ -109,6 +121,13 @@ is displayed instead.
Sets the given listener (class implementing the `JitsiMeetViewListener` Sets the given listener (class implementing the `JitsiMeetViewListener`
interface) on the view. interface) on the view.
#### setWelcomePageDisabled(disabled)
Sets if the welcome page should be disabled or not. See `getWelcomePageDisabled`
for more info.
NOTE: This function must be called before `loadURL` for it to take effect.
#### onBackPressed() #### onBackPressed()
Helper method which should be called from the activity's `onBackPressed` method. Helper method which should be called from the activity's `onBackPressed` method.

View File

@ -50,6 +50,13 @@ public class JitsiMeetActivity extends AppCompatActivity {
*/ */
private JitsiMeetView view; private JitsiMeetView view;
/**
* See {@JitsiMeetView.getWelcomePageDisabled}.
*/
public boolean getWelcomePageDisabled() {
return view != null && view.getWelcomePageDisabled();
}
/** /**
* Loads the given URL and displays the conference. If the specified URL is * Loads the given URL and displays the conference. If the specified URL is
* null, the welcome page is displayed instead. * null, the welcome page is displayed instead.
@ -60,6 +67,15 @@ public class JitsiMeetActivity extends AppCompatActivity {
view.loadURL(url); view.loadURL(url);
} }
/**
* See {@JitsiMeetView.setWelcomePageDisabled}.
*/
public void setWelcomePageDisabled(boolean disabled) {
if (view != null) {
view.setWelcomePageDisabled(disabled);
}
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@ -58,6 +58,11 @@ public class JitsiMeetView extends FrameLayout {
*/ */
private JitsiMeetViewListener listener; private JitsiMeetViewListener listener;
/**
* Indicates if the welcome page should be disabled or not.
*/
private boolean welcomePageDisabled;
/** /**
* React Native root view. * React Native root view.
*/ */
@ -105,6 +110,13 @@ public class JitsiMeetView extends FrameLayout {
return listener; return listener;
} }
/**
* @return - true if the welcome page is disabled, false if not.
*/
public boolean getWelcomePageDisabled() {
return welcomePageDisabled;
}
/** /**
* Internal method to initialize the React Native instance manager. We * Internal method to initialize the React Native instance manager. We
* create a single instance in order to load the JavaScript bundle a single * create a single instance in order to load the JavaScript bundle a single
@ -145,6 +157,8 @@ public class JitsiMeetView extends FrameLayout {
props.putString("url", url.toString()); props.putString("url", url.toString());
} }
props.putBoolean("disableWelcomePage", welcomePageDisabled);
// TODO: ReactRootView#setAppProperties is only available on React // TODO: ReactRootView#setAppProperties is only available on React
// Native 0.45, so destroy the current root view and create a new one. // Native 0.45, so destroy the current root view and create a new one.
if (reactRootView != null) { if (reactRootView != null) {
@ -170,6 +184,16 @@ public class JitsiMeetView extends FrameLayout {
this.listener = listener; this.listener = listener;
} }
/**
* Sets if the welcome page should be enabled or not. Must be called before calling loadURL or
* it won't take effect.
*
* @param disabled - set to true for disabling the welcome page, false not to do so.
*/
public void setWelcomePageDisabled(boolean disabled) {
welcomePageDisabled = disabled;
}
/** /**
* Activity lifecycle method which should be called from * Activity lifecycle method which should be called from
* <tt>Activity.onBackPressed</tt> so we can do the required internal * <tt>Activity.onBackPressed</tt> so we can do the required internal

View File

@ -32,6 +32,22 @@ To get started:
The `JitsiMeetView` class is the entry point to the SDK. It a subclass of The `JitsiMeetView` class is the entry point to the SDK. It a subclass of
`UIView` which renders a full conference in the designated area. `UIView` which renders a full conference in the designated area.
#### delegate
Property for getting / setting the delegate (instance of `JitsiMeetViewDelegate`
in the view.
#### disableWelcomePage
Property for setting the welcome page as disabled (or not). It default to NO, so
a welcome page would be shown. When the welcome page is set to disabled, an
empty black view is rendered.
NOTE: This property must be set before calling `loadURL` in order for it to take
effect.
#### loadURL(url)
```objc ```objc
[meetView loadURL:[NSURL URLWithString:@"https://meet.jit.si/test123"]]; [meetView loadURL:[NSURL URLWithString:@"https://meet.jit.si/test123"]];
``` ```

View File

@ -22,6 +22,7 @@
@interface JitsiMeetView : UIView @interface JitsiMeetView : UIView
@property (nonatomic, weak, nullable) id<JitsiMeetViewDelegate> delegate; @property (nonatomic, weak, nullable) id<JitsiMeetViewDelegate> delegate;
@property (nonatomic) BOOL disableWelcomePage;
+ (BOOL)application:(UIApplication *)application + (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity continueUserActivity:(NSUserActivity *)userActivity

View File

@ -106,7 +106,13 @@ static JitsiMeetView *instance;
* is null, the welcome page is shown. * is null, the welcome page is shown.
*/ */
- (void)loadURL:(NSURL *)url { - (void)loadURL:(NSURL *)url {
NSDictionary *props = url ? @{ url : url.absoluteString } : nil; NSMutableDictionary *props = [[NSMutableDictionary alloc] init];
if (url) {
[props setObject:url.absoluteString forKey:@"url"];
}
[props setObject:@(self.disableWelcomePage) forKey:@"disableWelcomePage"];
if (rootView == nil) { if (rootView == nil) {
rootView rootView

View File

@ -1,6 +1,19 @@
/** /**
* The type of the actions which signals that a specific App will mount (in the * The type of (Redux) action which configures if the welcome page should be
* terms of React). * disabled or not.
*
* {
* type: APP_SET_WELCOME_PAGE_DISABLED,
* app: App,
* disabled: boolean
* }
*/
export const APP_SET_WELCOME_PAGE_DISABLED
= Symbol('APP_SET_WELCOME_PAGE_DISABLED');
/**
* The type of (Redux) action which signals that a specific App will mount (in
* React terms).
* *
* { * {
* type: APP_WILL_MOUNT, * type: APP_WILL_MOUNT,
@ -10,8 +23,8 @@
export const APP_WILL_MOUNT = Symbol('APP_WILL_MOUNT'); export const APP_WILL_MOUNT = Symbol('APP_WILL_MOUNT');
/** /**
* The type of the actions which signals that a specific App will unmount (in * The type of (Redux) action which signals that a specific App will unmount (in
* the terms of React). * React terms).
* *
* { * {
* type: APP_WILL_UNMOUNT, * type: APP_WILL_UNMOUNT,

View File

@ -3,7 +3,11 @@ import { setLocationURL } from '../base/connection';
import { setConfig } from '../base/config'; import { setConfig } from '../base/config';
import { loadConfig } from '../base/lib-jitsi-meet'; import { loadConfig } from '../base/lib-jitsi-meet';
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes'; import {
APP_SET_WELCOME_PAGE_DISABLED,
APP_WILL_MOUNT,
APP_WILL_UNMOUNT
} from './actionTypes';
import { _getRouteToRender, _parseURIString } from './functions'; import { _getRouteToRender, _parseURIString } from './functions';
declare var APP: Object; declare var APP: Object;
@ -156,6 +160,26 @@ function _appNavigateToOptionalLocation(
_appNavigateToMandatoryLocation(dispatch, getState, location); _appNavigateToMandatoryLocation(dispatch, getState, location);
} }
/**
* Configures the welcome page display for this app.
*
* @param {App} app - The App being configured.
* @param {boolean} disabled - Set to true if the welcome page should be
* disabled, false if it shouldn't.
* @returns {{
* type: APP_SET_WELCOME_PAGE_DISABLED,
* app: App,
* disabled: boolean
* }}
*/
export function appSetWelcomePageDisabled(app, disabled) {
return {
type: APP_SET_WELCOME_PAGE_DISABLED,
app,
disabled
};
}
/** /**
* Signals that a specific App will mount (in the terms of React). * Signals that a specific App will mount (in the terms of React).
* *

View File

@ -370,7 +370,7 @@ export class AbstractApp extends Component {
*/ */
_onRouteEnter(route, ...args) { _onRouteEnter(route, ...args) {
// Notify the route that it is about to be entered. // Notify the route that it is about to be entered.
const onEnter = route.onEnter; const onEnter = route && route.onEnter;
if (typeof onEnter === 'function') { if (typeof onEnter === 'function') {
onEnter(...args); onEnter(...args);

View File

@ -1,5 +1,6 @@
/* global __DEV__ */ /* global __DEV__ */
import React from 'react';
import { Linking } from 'react-native'; import { Linking } from 'react-native';
import { Platform } from '../../base/react'; import { Platform } from '../../base/react';
@ -11,6 +12,7 @@ import '../../mobile/proximity';
import '../../mobile/wake-lock'; import '../../mobile/wake-lock';
import { AbstractApp } from './AbstractApp'; import { AbstractApp } from './AbstractApp';
import { appSetWelcomePageDisabled } from '../actions';
/** /**
* Root application component. * Root application component.
@ -23,7 +25,15 @@ export class App extends AbstractApp {
* *
* @static * @static
*/ */
static propTypes = AbstractApp.propTypes; static propTypes = {
...AbstractApp.propTypes,
/**
* Indicates if the welcome page should be shown when not in a
* conference.
*/
disableWelcomePage: React.PropTypes.bool
};
/** /**
* Initializes a new App instance. * Initializes a new App instance.
@ -56,6 +66,13 @@ export class App extends AbstractApp {
super.componentWillMount(); super.componentWillMount();
Linking.addEventListener('url', this._onLinkingURL); Linking.addEventListener('url', this._onLinkingURL);
// Store the desire to use the welcome page or not in the Redux store.
const dispatch = this._getStore().dispatch;
dispatch(
appSetWelcomePageDisabled(
this, Boolean(this.props.disableWelcomePage)));
} }
/** /**

View File

@ -142,9 +142,14 @@ export function _getRouteToRender(stateOrGetState) {
= typeof stateOrGetState === 'function' = typeof stateOrGetState === 'function'
? stateOrGetState() ? stateOrGetState()
: stateOrGetState; : stateOrGetState;
const { disableWelcomePage } = state['features/app'];
const { room } = state['features/base/conference']; const { room } = state['features/base/conference'];
const component = isRoomValid(room) ? Conference : WelcomePage; const component = isRoomValid(room) ? Conference : WelcomePage;
if (component === WelcomePage && disableWelcomePage) {
return null;
}
return RouteRegistry.getRouteByComponent(component); return RouteRegistry.getRouteByComponent(component);
} }

View File

@ -1,9 +1,21 @@
import { ReducerRegistry } from '../base/redux'; import { ReducerRegistry } from '../base/redux';
import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from './actionTypes'; import {
APP_SET_WELCOME_PAGE_DISABLED,
APP_WILL_MOUNT,
APP_WILL_UNMOUNT
} from './actionTypes';
ReducerRegistry.register('features/app', (state = {}, action) => { ReducerRegistry.register('features/app', (state = {}, action) => {
switch (action.type) { switch (action.type) {
case APP_SET_WELCOME_PAGE_DISABLED:
if (state.app === action.app) {
return {
...state,
disableWelcomePage: action.disabled
};
}
break;
case APP_WILL_MOUNT: case APP_WILL_MOUNT:
if (state.app !== action.app) { if (state.app !== action.app) {
return { return {

View File

@ -12,6 +12,24 @@ import { App } from './features/app';
* @extends Component * @extends Component
*/ */
class Root extends Component { class Root extends Component {
/**
* Root component's property types.
*
* @static
*/
static propTypes = {
/**
* Indicates if the welcome page should be shown when not in a
* conference.
*/
disableWelcomePage: React.PropTypes.bool,
/**
* The URL, if any, with which the app was launched.
*/
url: React.PropTypes.string
};
/** /**
* Initializes a new Root instance. * Initializes a new Root instance.
* *
@ -32,7 +50,7 @@ class Root extends Component {
* *
* @type {string} * @type {string}
*/ */
url: undefined url: this.props.url
}; };
// Handle the URL, if any, with which the app was launched. // Handle the URL, if any, with which the app was launched.
@ -64,6 +82,7 @@ class Root extends Component {
return ( return (
<App <App
disableWelcomePage = { this.props.disableWelcomePage }
url = { this.state.url } /> url = { this.state.url } />
); );
} }