diff --git a/app/lib/models/communicator.dart b/app/lib/models/communicator.dart index 23d35675cb..2858a1d22e 100644 --- a/app/lib/models/communicator.dart +++ b/app/lib/models/communicator.dart @@ -100,7 +100,7 @@ class SocketNotifier extends StateNotifier { state == ConnectionState.connected; } - void init(String hostname, int? port, [String? token]) { + void init(String hostname, int? port, {String? token, bool secure = false}) { if (state != null) return; if (_connectionState != ConnectionState.none) return; _connectionState = ConnectionState.connecting; @@ -112,7 +112,7 @@ class SocketNotifier extends StateNotifier { return; } - var url = "//$hostname"; + var url = secure ? "wss://$hostname" : "ws://$hostname"; if (port != null) url += ":$port"; if (token != null) url += "?token=$token"; diff --git a/app/lib/pages/connect_page.dart b/app/lib/pages/connect_page.dart index 3a2e4476b0..375211b23c 100644 --- a/app/lib/pages/connect_page.dart +++ b/app/lib/pages/connect_page.dart @@ -17,12 +17,14 @@ class ConnectPage extends HookConsumerWidget { @QueryParam("host") this.hostname = "", @QueryParam() this.port, @QueryParam() this.token = "", + @QueryParam() this.secure = false, super.key, }); final String hostname; final int? port; final String token; + final bool secure; @override Widget build(BuildContext context, WidgetRef ref) { @@ -39,9 +41,12 @@ class ConnectPage extends HookConsumerWidget { useEffect( () { final timer = Timer(1.seconds, () { - ref - .read(socketProvider.notifier) - .init(hostname, port, token.isEmpty ? null : token); + ref.read(socketProvider.notifier).init( + hostname, + port, + token: token.isEmpty ? null : token, + secure: secure, + ); }); return timer.cancel; }, diff --git a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/ui/CommunicationHandler.kt b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/ui/CommunicationHandler.kt index bb6120c492..41afdb38ff 100644 --- a/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/ui/CommunicationHandler.kt +++ b/engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/ui/CommunicationHandler.kt @@ -61,6 +61,7 @@ class CommunicationHandler : KoinComponent { ) private val websocketHostname: String? by optionalConfig("websocket.hostname") private val websocketAppendPort: Boolean? by optionalConfig("websocket.append_port") + private val websocketSecure: Boolean? by optionalConfig("websocket.secure") val authenticationEnabled: Boolean @@ -188,6 +189,7 @@ class CommunicationHandler : KoinComponent { url += "/#/connect?host=${websocketHostname ?: hostName}" if (websocketAppendPort != false) url += "&port=${webSocketPort}" if (auth == "session") url += "&token=${generateSessionToken(playerId)}" + if (websocketSecure == true) url += "&secure=true" return url }