Skip to content

Commit

Permalink
Merge pull request #223 from openbitapp/master
Browse files Browse the repository at this point in the history
Added option that allows to specify path
  • Loading branch information
danielrbrowne authored Jan 15, 2021
2 parents 33acb9c + d3182e1 commit 1ef8aac
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Sources/Models/PusherClientOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum AuthMethod {
public let autoReconnect: Bool
public let host: String
public let port: Int
public let path: String?
public let useTLS: Bool
public let activityTimeout: TimeInterval?

Expand All @@ -36,13 +37,15 @@ public enum AuthMethod {
autoReconnect: Bool = true,
host: PusherHost = .host(Constants.API.defaultHost),
port: Int? = nil,
path: String? = nil,
useTLS: Bool = true,
activityTimeout: TimeInterval? = nil
) {
self.authMethod = authMethod
self.attemptToReturnJSONObject = attemptToReturnJSONObject
self.autoReconnect = autoReconnect
self.host = host.stringValue
self.path = path
self.port = port ?? (useTLS ? 443 : 80)
self.useTLS = useTLS
self.activityTimeout = activityTimeout
Expand Down
6 changes: 3 additions & 3 deletions Sources/PusherSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ let CLIENT_NAME = "pusher-websocket-swift"
*/
func constructUrl(key: String, options: PusherClientOptions) -> String {
var url = ""

let additionalPathComponents = options.path ?? ""
if options.useTLS {
url = "wss://\(options.host):\(options.port)/app/\(key)"
url = "wss://\(options.host):\(options.port)\(additionalPathComponents)/app/\(key)"
} else {
url = "ws://\(options.host):\(options.port)/app/\(key)"
url = "ws://\(options.host):\(options.port)\(additionalPathComponents)/app/\(key)"
}
return "\(url)?client=\(CLIENT_NAME)&version=\(VERSION)&protocol=\(PROTOCOL)"
}

0 comments on commit 1ef8aac

Please sign in to comment.