Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty Jitsi default url in BuildSettings #5894

Merged
merged 7 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Config/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ final class BuildSettings: NSObject {
"https://scalar-staging.vector.im/api",
"https://scalar-staging.riot.im/scalar/api",
]
// Jitsi server used outside integrations to create conference calls from the call button in the timeline
static let jitsiServerUrl: URL = URL(string: "https://jitsi.riot.im")!
// Jitsi server used outside integrations to create conference calls from the call button in the timeline.
// Setting this to nil effectively disables Jitsi conference calls (given that there is no wellknown override).
// Note: this will not remove the conference call button, use roomScreenAllowVoIPForNonDirectRoom setting.
static let jitsiServerUrl: URL? = URL(string: "https://jitsi.riot.im")


// MARK: - Features
Expand Down
1 change: 1 addition & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ Tap the + to start adding people.";
"call_incoming_video" = "Incoming video call…";
"call_already_displayed" = "There is already a call in progress.";
"call_jitsi_error" = "Failed to join the conference call.";
"call_jitsi_unable_to_start" = "Unable to start conference call";

"call_no_stun_server_error_title" ="Call failed due to misconfigured server";
"call_no_stun_server_error_message_1" ="Please ask the administrator of your homeserver %@ to configure a TURN server in order for calls to work reliably.";
Expand Down
4 changes: 4 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,10 @@ public class VectorL10n: NSObject {
public static var callJitsiError: String {
return VectorL10n.tr("Vector", "call_jitsi_error")
}
/// Unable to start conference call
public static var callJitsiUnableToStart: String {
return VectorL10n.tr("Vector", "call_jitsi_unable_to_start")
}
/// Device Speaker
public static var callMoreActionsAudioUseDevice: String {
return VectorL10n.tr("Vector", "call_more_actions_audio_use_device")
Expand Down
3 changes: 2 additions & 1 deletion Riot/Managers/Widgets/WidgetManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ typedef enum : NSUInteger
WidgetManagerErrorCodeNoIntegrationsServerConfigured,
WidgetManagerErrorCodeDisabledIntegrationsServer,
WidgetManagerErrorCodeFailedToConnectToIntegrationsServer,
WidgetManagerErrorCodeTermsNotSigned
WidgetManagerErrorCodeTermsNotSigned,
WidgetManagerErrorCodeUnavailableJitsiURL
}
WidgetManagerErrorCode;

Expand Down
14 changes: 14 additions & 0 deletions Riot/Managers/Widgets/WidgetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ - (MXHTTPOperation *)createJitsiWidgetInRoom:(MXRoom*)room
NSString *widgetId = [NSString stringWithFormat:@"%@_%@_%@", kWidgetTypeJitsiV1, room.mxSession.myUser.userId, @((uint64_t)([[NSDate date] timeIntervalSince1970] * 1000))];

NSURL *preferredJitsiServerUrl = [room.mxSession vc_homeserverConfiguration].jitsi.serverURL;

if (!preferredJitsiServerUrl)
{
MXLogDebug(@"[WidgetManager] createJitsiWidgetInRoom: Error: No Jitsi server URL provided");
failure(self.errorForUnavailableJitsiURL);
return nil;
}

JitsiService *jitsiService = JitsiService.shared;

Expand Down Expand Up @@ -807,4 +814,11 @@ - (NSError*)errorForDisabledIntegrationManager
userInfo:@{NSLocalizedDescriptionKey: [VectorL10n widgetIntegrationManagerDisabled]}];
}

- (NSError*)errorForUnavailableJitsiURL
{
return [NSError errorWithDomain:WidgetManagerErrorDomain
code:WidgetManagerErrorCodeUnavailableJitsiURL
userInfo:@{NSLocalizedDescriptionKey: VectorL10n.callJitsiUnableToStart}];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,15 @@ final class HomeserverConfigurationBuilder: NSObject {
secureBackupSetupMethods: secureBackupSetupMethods)

// Jitsi configuration
let jitsiPreferredDomain: String
let jitsiServerURL: URL
let hardcodedJitsiServerURL: URL = BuildSettings.jitsiServerUrl
let jitsiPreferredDomain: String?
let jitsiServerURL: URL?
let hardcodedJitsiServerURL: URL? = BuildSettings.jitsiServerUrl

if let preferredDomain = vectorWellKnownJitsiConfiguration?.preferredDomain {
jitsiPreferredDomain = preferredDomain
jitsiServerURL = self.jitsiServerURL(from: preferredDomain) ?? hardcodedJitsiServerURL
} else {
guard let hardcodedJitsiDomain = hardcodedJitsiServerURL.host else {
fatalError("[HomeserverConfigurationBuilder] Fail to get Jitsi domain from hardcoded Jitsi URL")
}
jitsiPreferredDomain = hardcodedJitsiDomain
jitsiPreferredDomain = hardcodedJitsiServerURL?.host
jitsiServerURL = hardcodedJitsiServerURL
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import Foundation
/// `HomeserverJitsiConfiguration` gives Jitsi widget configuration used by homeserver
@objcMembers
final class HomeserverJitsiConfiguration: NSObject {
let serverDomain: String
let serverURL: URL
let serverDomain: String?
let serverURL: URL?

init(serverDomain: String, serverURL: URL) {
init(serverDomain: String?, serverURL: URL?) {
self.serverDomain = serverDomain
self.serverURL = serverURL

Expand Down
14 changes: 12 additions & 2 deletions Riot/Modules/Application/LegacyAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,14 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

#ifdef CALL_STACK_JINGLE
// Setup Jitsi
[JitsiService.shared configureDefaultConferenceOptionsWith:BuildSettings.jitsiServerUrl];
NSURL *jitsiServerUrl = BuildSettings.jitsiServerUrl;
if (jitsiServerUrl)
{
[JitsiService.shared configureDefaultConferenceOptionsWith:jitsiServerUrl];

[JitsiService.shared application:application didFinishLaunchingWithOptions:launchOptions];
}

[JitsiService.shared application:application didFinishLaunchingWithOptions:launchOptions];
#endif

self.majorUpdateManager = [MajorUpdateManager new];
Expand Down Expand Up @@ -932,13 +937,18 @@ - (UIAlertController*)showErrorAsAlert:(NSError*)error

NSString *title = [error.userInfo valueForKey:NSLocalizedFailureReasonErrorKey];
NSString *msg = [error.userInfo valueForKey:NSLocalizedDescriptionKey];
NSString *localizedDescription = error.localizedDescription;
if (!title)
{
if (msg)
{
title = msg;
msg = nil;
}
else if (localizedDescription.length > 0)
{
title = localizedDescription;
}
else
{
title = [VectorL10n error];
Expand Down
37 changes: 20 additions & 17 deletions Riot/Modules/Integrations/Widgets/Jitsi/JitsiService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ import Foundation
#if canImport(JitsiMeetSDK)
import JitsiMeetSDK

enum JitsiServiceError: Error {
enum JitsiServiceError: LocalizedError {
case widgetContentCreationFailed
case emptyResponse
case noWellKnown
case unknown

var errorDescription: String? {
return VectorL10n.callJitsiUnableToStart
}
}

private enum HTTPStatusCodes {
Expand Down Expand Up @@ -143,32 +147,31 @@ final class JitsiService: NSObject {
}

return self.getWellKnown(for: jitsiServerURL) { (result) in
var continueOperation: Bool = false
var authType: JitsiAuthenticationType?

func continueOperation(authType: JitsiAuthenticationType?) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting I usually use closures for that

guard let widgetContent = self.createJitsiWidgetContent(serverDomain: serverDomain,
authenticationType: authType,
roomID: roomID,
isAudioOnly: isAudioOnly)
else {
failure(JitsiServiceError.widgetContentCreationFailed)
return
}

success(widgetContent)
}

switch result {
case .success(let jitsiWellKnown):
authType = jitsiWellKnown.authenticationType
continueOperation = true
continueOperation(authType: jitsiWellKnown.authenticationType)
case .failure(let error):
MXLog.debug("[JitsiService] Fail to get Jitsi Well Known with error: \(error)")
if let error = error as? JitsiServiceError, error == .noWellKnown {
// no well-known, continue with no auth
continueOperation = true
continueOperation(authType: nil)
} else {
failure(error)
}
}

if continueOperation,
let widgetContent = self.createJitsiWidgetContent(serverDomain: serverDomain,
authenticationType: authType,
roomID: roomID,
isAudioOnly: isAudioOnly) {
success(widgetContent)
} else {
failure(JitsiServiceError.widgetContentCreationFailed)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion RiotTests/HomeserverConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class HomeserverConfigurationTests: XCTestCase {
let homeserverConfiguration = homeserverConfigurationBuilder.build(from: wellKnown)

XCTAssertEqual(homeserverConfiguration.jitsi.serverDomain, expectedJitsiServer)
XCTAssertEqual(homeserverConfiguration.jitsi.serverURL.absoluteString, expectedJitsiServerStringURL)
XCTAssertEqual(homeserverConfiguration.jitsi.serverURL?.absoluteString, expectedJitsiServerStringURL)
XCTAssertEqual(homeserverConfiguration.encryption.isE2EEByDefaultEnabled, expectedE2EEEByDefaultEnabled)
XCTAssertEqual(homeserverConfiguration.encryption.isSecureBackupRequired, expectedSecureBackupRequired)
XCTAssertEqual(homeserverConfiguration.encryption.secureBackupSetupMethods, expectedSecureBackupSetupMethods)
Expand Down
1 change: 1 addition & 0 deletions changelog.d/5837.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow empty Jitsi default URL in BuildSettings