Skip to content
Snippets Groups Projects
Commit 5b4d171c authored by Clément Pit-Claudel's avatar Clément Pit-Claudel
Browse files

client: Move ProtocolInfo to shared/

parent 0edcfca3
No related branches found
No related tags found
No related merge requests found
...@@ -262,16 +262,12 @@ case class AppPage(appId: AppId, uiId: UIId, instanceId: InstanceId, userId: Use ...@@ -262,16 +262,12 @@ case class AppPage(appId: AppId, uiId: UIId, instanceId: InstanceId, userId: Use
) )
maybeApp.get maybeApp.get
enum ProtocolInfo(secure: String, insecure: String):
case WebSocket extends ProtocolInfo("wss", "ws")
case Http extends ProtocolInfo("https", "http")
def proto: String = if dom.window.location.protocol.startsWith("https") then secure else insecure
def substituteInstanceInfo(endpointTemplate: String, protocolInfo: ProtocolInfo): String = def substituteInstanceInfo(endpointTemplate: String, protocolInfo: ProtocolInfo): String =
val port = dom.window.location.port val port = dom.window.location.port
val hostname = dom.window.location.hostname val hostname = dom.window.location.hostname
val tls = dom.window.location.protocol.startsWith("https")
endpointTemplate endpointTemplate
.replace("{{protocol}}", protocolInfo.proto) .replace("{{protocol}}", protocolInfo.proto(tls))
.replace("{{authority}}", hostname + (if port.nonEmpty then f":$port" else "")) .replace("{{authority}}", hostname + (if port.nonEmpty then f":$port" else ""))
.replace("{{userId}}", URLEncoder.encode(userId, "UTF-8")) .replace("{{userId}}", URLEncoder.encode(userId, "UTF-8"))
......
...@@ -45,3 +45,8 @@ object Endpoints: ...@@ -45,3 +45,8 @@ object Endpoints:
val App = "/app" val App = "/app"
val WebSocket = "/ws" val WebSocket = "/ws"
/** Known protocols */
enum ProtocolInfo(secure: String, insecure: String):
case WebSocket extends ProtocolInfo("wss", "ws")
case Http extends ProtocolInfo("https", "http")
def proto(tls: Boolean): String = if tls then secure else insecure
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment