Widgets: Make sure we have a scalar token before opening one (#1723).

Make the build of the true widget URL asynchronous and build it only when necessary.
This commit is contained in:
manuroe
2018-01-04 11:49:39 +01:00
parent 78d19e7334
commit 83a51295aa
10 changed files with 125 additions and 82 deletions
@@ -44,41 +44,65 @@ static const NSString *kJitsiServerUrl = @"https://jitsi.riot.im/";
return jitsiViewController;
}
- (BOOL)openWidget:(Widget*)widget withVideo:(BOOL)aVideo
- (void)openWidget:(Widget*)widget withVideo:(BOOL)aVideo
success:(void (^)())success
failure:(void (^)(NSError *error))failure
{
video = aVideo;
_widget = widget;
// Extract the jitsi conference id from the widget url
NSString *confId;
NSURL *url = [NSURL URLWithString:_widget.url];
if (url)
{
NSURLComponents *components = [[NSURLComponents new] initWithURL:url resolvingAgainstBaseURL:NO];
NSArray *queryItems = [components queryItems];
[_widget widgetUrl:^(NSString * _Nonnull widgetUrl) {
for (NSURLQueryItem *item in queryItems)
// Extract the jitsi conference id from the widget url
NSString *confId;
NSURL *url = [NSURL URLWithString:widgetUrl];
if (url)
{
if ([item.name isEqualToString:@"confId"])
NSURLComponents *components = [[NSURLComponents new] initWithURL:url resolvingAgainstBaseURL:NO];
NSArray *queryItems = [components queryItems];
for (NSURLQueryItem *item in queryItems)
{
confId = item.value;
break;
if ([item.name isEqualToString:@"confId"])
{
confId = item.value;
break;
}
}
// And build from it the url to use in jitsi-meet sdk
if (confId)
{
jitsiUrl = [NSString stringWithFormat:@"%@%@", kJitsiServerUrl, confId];
}
}
// And build from it the url to use in jitsi-meet sdk
if (confId)
if (jitsiUrl)
{
jitsiUrl = [NSString stringWithFormat:@"%@%@", kJitsiServerUrl, confId];
if (success)
{
success();
}
}
}
else
{
NSLog(@"[JitsiVC] Failed to load widget: %@. Widget event: %@", widget, widget.widgetEvent);
if (!jitsiUrl)
{
NSLog(@"[JitsiVC] Failed to load widget: %@. Widget event: %@", widget, widget.widgetEvent);
}
if (failure)
{
failure(nil);
}
}
return (jitsiUrl != nil);
} failure:^(NSError * _Nonnull error) {
NSLog(@"[JitsiVC] Failed to load widget 2: %@. Widget event: %@", widget, widget.widgetEvent);
if (failure)
{
failure(nil);
}
}];
}
- (void)hangup