[RN] Alternative to JitsiMeetView.loadURL w/o URL
Introduces loadURLObject in JitsiMeetView on Android and iOS which accepts a Bundle and NSDictionary, respectively, similar in structure to the JS object accepted by the constructor of Web's ExternalAPI. At this time, only the property url of the bundle/dictionary is supported. However, it allows the public API of loadURLObject to be consumed. The property url will be made optional in the future and other properties will be supported from which a URL will be constructed.
This commit is contained in:
parent
e5e7b59f43
commit
a2c2d3bee1
|
@ -93,10 +93,6 @@ See JitsiMeetView.getWelcomePageEnabled.
|
|||
|
||||
See JitsiMeetView.loadURL.
|
||||
|
||||
#### loadURLString(String)
|
||||
|
||||
See JitsiMeetView.loadURLString.
|
||||
|
||||
#### setWelcomePageEnabled(boolean)
|
||||
|
||||
See JitsiMeetView.setWelcomePageEnabled.
|
||||
|
@ -118,12 +114,22 @@ empty view will be rendered when not in a conference. Defaults to false.
|
|||
#### loadURL(URL)
|
||||
|
||||
Loads a specific URL which may identify a conference to join. If the specified
|
||||
URL is null, the Welcome page is displayed instead.
|
||||
URL is null and the Welcome page is enabled, the Welcome page is displayed
|
||||
instead.
|
||||
|
||||
#### loadURLString(String)
|
||||
|
||||
Loads a specific URL which may identify a conference to join. If the specified
|
||||
URL is null, the Welcome page is displayed instead.
|
||||
URL is null and the Welcome page is enabled, the Welcome page is displayed
|
||||
instead.
|
||||
|
||||
#### loadURLObject(Bundle)
|
||||
|
||||
Loads a specific URL which may identify a conference to join. The URL is
|
||||
specified in the form of a Bundle of properties which (1) internally are
|
||||
sufficient to construct a URL (string) while (2) abstracting the specifics of
|
||||
constructing the URL away from API clients/consumers. If the specified URL is
|
||||
null and the Welcome page is enabled, the Welcome page is displayed instead.
|
||||
|
||||
#### setListener(listener)
|
||||
|
||||
|
|
|
@ -233,21 +233,24 @@ public class JitsiMeetView extends FrameLayout {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads a specific URL {@link String} which may identify a conference to
|
||||
* join. If the specified URL {@code String} is {@code null}, the Welcome
|
||||
* page is displayed instead.
|
||||
* Loads a specific URL which may identify a conference to join. The URL is
|
||||
* specified in the form of a {@link Bundle} of properties which (1)
|
||||
* internally are sufficient to construct a URL {@code String} while (2)
|
||||
* abstracting the specifics of constructing the URL away from API
|
||||
* clients/consumers. If the specified URL is {@code null} and the Welcome
|
||||
* page is enabled, the Welcome page is displayed instead.
|
||||
*
|
||||
* @param urlString - The URL {@code String} to load which may identify a
|
||||
* conference to join.
|
||||
* @param urlObject - The URL to load which may identify a conference to
|
||||
* join.
|
||||
*/
|
||||
public void loadURLString(@Nullable String urlString) {
|
||||
public void loadURLObject(@Nullable Bundle urlObject) {
|
||||
Bundle props = new Bundle();
|
||||
|
||||
// externalAPIScope
|
||||
props.putString("externalAPIScope", externalAPIScope);
|
||||
// url
|
||||
if (urlString != null) {
|
||||
props.putString("url", urlString);
|
||||
if (urlObject != null) {
|
||||
props.putBundle("url", urlObject);
|
||||
}
|
||||
// welcomePageEnabled
|
||||
props.putBoolean("welcomePageEnabled", welcomePageEnabled);
|
||||
|
@ -266,6 +269,26 @@ public class JitsiMeetView extends FrameLayout {
|
|||
addView(reactRootView);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific URL {@link String} which may identify a conference to
|
||||
* join. If the specified URL {@code String} is {@code null}, the Welcome
|
||||
* page is displayed instead.
|
||||
*
|
||||
* @param urlString - The URL {@code String} to load which may identify a
|
||||
* conference to join.
|
||||
*/
|
||||
public void loadURLString(@Nullable String urlString) {
|
||||
Bundle urlObject;
|
||||
|
||||
if (urlString == null) {
|
||||
urlObject = null;
|
||||
} else {
|
||||
urlObject = new Bundle();
|
||||
urlObject.putString("url", urlString);
|
||||
}
|
||||
loadURLObject(urlObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a specific {@link JitsiMeetViewListener} on this
|
||||
* {@code JitsiMeetView}.
|
||||
|
|
|
@ -20,10 +20,10 @@ To get started:
|
|||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
JitsiMeetView *view = (JitsiMeetView *) self.view;
|
||||
JitsiMeetView *jitsiMeetView = (JitsiMeetView *) self.view;
|
||||
|
||||
view.delegate = self;
|
||||
[view loadURL:nil];
|
||||
jitsiMeetView.delegate = self;
|
||||
[jitsiMeetView loadURL:nil];
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -46,20 +46,40 @@ NOTE: Must be set before `loadURL:`/`loadURLString:` for it to take effect.
|
|||
#### loadURL:NSURL
|
||||
|
||||
```objc
|
||||
[meetView loadURL:[NSURL URLWithString:@"https://meet.jit.si/test123"]];
|
||||
[jitsiMeetView loadURL:[NSURL URLWithString:@"https://meet.jit.si/test123"]];
|
||||
```
|
||||
|
||||
Loads a specific URL which may identify a conference to join. If the specified
|
||||
URL is `nil`, the Welcome page is displayed instead.
|
||||
URL is `nil` and the Welcome page is enabled, the Welcome page is displayed
|
||||
instead.
|
||||
|
||||
#### loadURLObject:NSDictionary
|
||||
|
||||
```objc
|
||||
[jitsiMeetView loadURLObject:@{
|
||||
@"url": @"https://meet.jit.si/test123",
|
||||
@"configOverwrite": @{
|
||||
@"startWithAudioMuted": @YES,
|
||||
@"startWithVideoMuted": @NO
|
||||
}
|
||||
}];
|
||||
```
|
||||
|
||||
Loads a specific URL which may identify a conference to join. The URL is
|
||||
specified in the form of an `NSDictionary` of properties which (1) internally
|
||||
are sufficient to construct a URL (string) while (2) abstracting the specifics
|
||||
of constructing the URL away from API clients/consumers. If the specified URL is
|
||||
`nil` and the Welcome page is enabled, the Welcome page is displayed instead.
|
||||
|
||||
#### loadURLString:NSString
|
||||
|
||||
```objc
|
||||
[meetView loadURLString:@"https://meet.jit.si/test123"];
|
||||
[jitsiMeetView loadURLString:@"https://meet.jit.si/test123"];
|
||||
```
|
||||
|
||||
Loads a specific URL which may identify a conference to join. If the specified
|
||||
URL is `nil`, the Welcome page is displayed instead.
|
||||
URL is `nil` and the Welcome page is enabled, the Welcome page is displayed
|
||||
instead.
|
||||
|
||||
#### Universal / deep linking
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
|
||||
- (void)loadURL:(NSURL * _Nullable)url;
|
||||
|
||||
- (void)loadURLObject:(NSDictionary * _Nullable)urlObject;
|
||||
|
||||
- (void)loadURLString:(NSString * _Nullable)urlString;
|
||||
|
||||
@end
|
||||
|
|
|
@ -185,28 +185,25 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
|||
* join.
|
||||
*/
|
||||
- (void)loadURL:(NSURL *)url {
|
||||
[self loadURLString:(url ? url.absoluteString : nil)];
|
||||
[self loadURLString:url ? url.absoluteString : nil];
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific URL {@link NSString} which may identify a conference to
|
||||
* join. If the specified URL {@code NSString} is {@code nil}, the Welcome page
|
||||
* is displayed instead.
|
||||
* Loads a specific URL which may identify a conference to join. The URL is
|
||||
* specified in the form of an {@link NSDictionary} of properties which (1)
|
||||
* internally are sufficient to construct a URL {@code NSString} while (2)
|
||||
* abstracting the specifics of constructing the URL away from API
|
||||
* clients/consumers. If the specified URL is {@code nil} and the Welcome page
|
||||
* is enabled, the Welcome page is displayed instead.
|
||||
*
|
||||
* @param urlString - The URL {@code NSString} to load which may identify a
|
||||
* conference to join.
|
||||
* @param urlObject - The URL to load which may identify a conference to join.
|
||||
*/
|
||||
- (void)loadURLString:(NSString *)urlString {
|
||||
NSMutableDictionary *props = [[NSMutableDictionary alloc] init];
|
||||
|
||||
// externalAPIScope
|
||||
[props setObject:externalAPIScope forKey:@"externalAPIScope"];
|
||||
// url
|
||||
if (urlString) {
|
||||
[props setObject:urlString forKey:@"url"];
|
||||
}
|
||||
// welcomePageEnabled
|
||||
[props setObject:@(self.welcomePageEnabled) forKey:@"welcomePageEnabled"];
|
||||
- (void)loadURLObject:(NSDictionary *)urlObject {
|
||||
NSDictionary *props = @{
|
||||
@"externalAPIScope": externalAPIScope,
|
||||
@"url": urlObject,
|
||||
@"welcomePageEnabled": @(self.welcomePageEnabled)
|
||||
};
|
||||
|
||||
if (rootView == nil) {
|
||||
rootView
|
||||
|
@ -224,6 +221,18 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a specific URL {@link NSString} which may identify a conference to
|
||||
* join. If the specified URL {@code NSString} is {@code nil}, the Welcome page
|
||||
* is displayed instead.
|
||||
*
|
||||
* @param urlString - The URL {@code NSString} to load which may identify a
|
||||
* conference to join.
|
||||
*/
|
||||
- (void)loadURLString:(NSString *)urlString {
|
||||
[self loadURLObject:urlString ? @{ @"url": urlString } : nil];
|
||||
}
|
||||
|
||||
#pragma mark Private methods
|
||||
|
||||
+ (instancetype)viewForExternalAPIScope:(NSString *)externalAPIScope {
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
} from '../../base/participants';
|
||||
import { RouteRegistry } from '../../base/react';
|
||||
import { MiddlewareRegistry, ReducerRegistry } from '../../base/redux';
|
||||
import { toURLString } from '../../base/util';
|
||||
|
||||
import {
|
||||
appNavigate,
|
||||
|
@ -52,7 +53,10 @@ export class AbstractApp extends Component {
|
|||
/**
|
||||
* The URL, if any, with which the app was launched.
|
||||
*/
|
||||
url: React.PropTypes.string
|
||||
url: React.PropTypes.oneOfType([
|
||||
React.PropTypes.object,
|
||||
React.PropTypes.string
|
||||
])
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -110,7 +114,7 @@ export class AbstractApp extends Component {
|
|||
|
||||
// If a URL was explicitly specified to this React Component, then open
|
||||
// it; otherwise, use a default.
|
||||
this._openURL(this.props.url || this._getDefaultURL());
|
||||
this._openURL(toURLString(this.props.url) || this._getDefaultURL());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,9 +143,10 @@ export class AbstractApp extends Component {
|
|||
}
|
||||
|
||||
// Deal with URL changes.
|
||||
const { url } = nextProps;
|
||||
let { url } = nextProps;
|
||||
|
||||
if (this.props.url !== url) {
|
||||
url = toURLString(url);
|
||||
if (toURLString(this.props.url) !== url) {
|
||||
this._openURL(url || this._getDefaultURL());
|
||||
}
|
||||
}
|
||||
|
@ -391,12 +396,12 @@ export class AbstractApp extends Component {
|
|||
/**
|
||||
* Navigates this AbstractApp to (i.e. opens) a specific URL.
|
||||
*
|
||||
* @param {string} url - The URL to which to navigate this AbstractApp (i.e.
|
||||
* the URL to open).
|
||||
* @param {string|Object} url - The URL to navigate this AbstractApp to
|
||||
* (i.e. the URL to open).
|
||||
* @protected
|
||||
* @returns {void}
|
||||
*/
|
||||
_openURL(url) {
|
||||
this._getStore().dispatch(appNavigate(url));
|
||||
this._getStore().dispatch(appNavigate(toURLString(url)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -262,3 +262,53 @@ export function parseURIString(uri: ?string) {
|
|||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to return a {@code String} representation of a specific
|
||||
* {@code Object} which is supposed to represent a URL. Obviously, if a
|
||||
* {@code String} is specified, it is returned. If a {@code URL} is specified,
|
||||
* its {@code URL#href} is returned. Additionally, an {@code Object} similar to
|
||||
* the one accepted by the constructor of Web's ExternalAPI is supported on both
|
||||
* mobile/React Native and Web/React.
|
||||
*
|
||||
* @param {string|Object} obj - The URL to return a {@code String}
|
||||
* representation of.
|
||||
* @returns {string} - A {@code String} representation of the specified
|
||||
* {@code obj} which is supposed to represent a URL.
|
||||
*/
|
||||
export function toURLString(obj: ?(string | Object)): ?string {
|
||||
let str;
|
||||
|
||||
switch (typeof obj) {
|
||||
case 'object':
|
||||
if (obj) {
|
||||
if (obj instanceof URL) {
|
||||
str = obj.href;
|
||||
} else {
|
||||
str = _urlObjectToString(obj);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
str = String(obj);
|
||||
break;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to return a {@code String} representation of a specific
|
||||
* {@code Object} similar to the one accepted by the constructor
|
||||
* of Web's ExternalAPI.
|
||||
*
|
||||
* @param {Object} obj - The URL to return a {@code String} representation of.
|
||||
* @returns {string} - A {@code String} representation of the specified
|
||||
* {@code obj}.
|
||||
*/
|
||||
function _urlObjectToString({ url }: Object): ?string {
|
||||
// TODO Support properties other than url. Support (pretty much) all
|
||||
// properties accepted by the constructor of Web's ExternalAPI.
|
||||
return url;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue