diff --git a/Riot/ViewController/Widgets/JitsiViewController.h b/Riot/ViewController/Widgets/JitsiViewController.h new file mode 100644 index 000000000..c630aca21 --- /dev/null +++ b/Riot/ViewController/Widgets/JitsiViewController.h @@ -0,0 +1,57 @@ +/* + Copyright 2017 Vector Creations 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 + +#import + +#import "WidgetManager.h" + +/** + The `JitsiViewController` is a specific VC for handling a jitsi widget using + jitsi-meet iOS SDK instead of displaying it in a webview like other scalar widgets. + */ +@interface JitsiViewController : MXKViewController + +/** + The jitsi-meet SDK view. + */ +@property (weak, nonatomic) IBOutlet JitsiMeetView *jitsiMeetView; + +/** + Returns the `UINib` object initialized for a `JitsiViewController`. + + @return The initialized `UINib` object or `nil` if there were errors during initialization + or the nib file could not be located. + */ ++ (UINib *)nib; + +/** + Creates and returns a new `JitsiViewController` object. + + @discussion This is the designated initializer for programmatic instantiation. + + @param widget the jitsi widget containinf jitis conference information. + @return An initialized `JitsiViewController` object if successful, `nil` otherwise. + */ ++ (instancetype)jitsiViewControllerForWidget:(Widget*)widget; + +/** + The jitsi widget displayed by this `JitsiViewController`. + */ +@property (nonatomic, readonly) Widget *widget; + +@end diff --git a/Riot/ViewController/Widgets/JitsiViewController.m b/Riot/ViewController/Widgets/JitsiViewController.m new file mode 100644 index 000000000..e3cc4e10f --- /dev/null +++ b/Riot/ViewController/Widgets/JitsiViewController.m @@ -0,0 +1,91 @@ +/* + Copyright 2017 Vector Creations 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 "JitsiViewController.h" + +static const NSString *kJitsiServerUrl = @"https://jitsi.riot.im/"; + +@implementation JitsiViewController + +#pragma mark - Class methods + ++ (UINib *)nib +{ + return [UINib nibWithNibName:NSStringFromClass(self.class) + bundle:[NSBundle bundleForClass:self.class]]; +} + ++ (instancetype)jitsiViewControllerForWidget:(Widget*)widget +{ + JitsiViewController *jitsiViewController = [[[self class] alloc] initWithNibName:NSStringFromClass(self.class) + bundle:[NSBundle bundleForClass:self.class]]; + + jitsiViewController->_widget = widget; + + return jitsiViewController; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.jitsiMeetView.delegate = self; + + // Extract the jitsi conference id from the widget url + // @TODO: Consider doing this in a `JitsiWidget` class. + NSString *confId; + NSURL *url = [NSURL URLWithString:_widget.url]; + NSURLComponents *components = [[NSURLComponents new] initWithURL:url resolvingAgainstBaseURL:NO]; + NSArray *queryItems = [components queryItems]; + + for (NSURLQueryItem *item in queryItems) + { + if ([item.name isEqualToString:@"confId"]) + { + confId = item.value; + } + } + + if (confId) + { + // Pass the URL to jitsi-meet sdk + NSString *jitsiUrl = [NSString stringWithFormat:@"%@%@", kJitsiServerUrl, confId]; + [self.jitsiMeetView loadURLString:jitsiUrl]; + } + // @TODO: else +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; +} + +#pragma mark - JitsiMeetViewDelegate + +- (void)conferenceFailed:(NSDictionary *)data +{ + NSLog(@"[JitsiViewController] conferenceFailed - data: %@", data); + + // @TODO: show something to the end user +} + +- (void)conferenceLeft:(NSDictionary *)data +{ + // The conference is over. Close this view controller. + [self dismissViewControllerAnimated:YES completion:nil]; +} + +@end diff --git a/Riot/ViewController/Widgets/JitsiViewController.xib b/Riot/ViewController/Widgets/JitsiViewController.xib new file mode 100644 index 000000000..4ba6c4c70 --- /dev/null +++ b/Riot/ViewController/Widgets/JitsiViewController.xib @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +