-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from pusher/tech/refactor-private-api
Refactoring the private API
- Loading branch information
Showing
38 changed files
with
425 additions
and
412 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Foundation | ||
|
||
extension PusherChannel { | ||
|
||
/// Determines whether or not a message should be decrypted, based on channel and event attributes. | ||
/// - Parameters: | ||
/// - name: The name of the channel. | ||
/// - eventName: The name of the event received on the channel. | ||
/// - Returns: A `Bool` indicating whether the message should be decrypted or not. | ||
static func decryptsMessage(name: String?, eventName: String) -> Bool { | ||
return isEncrypted(name: name) && !isSystemEvent(eventName: eventName) | ||
} | ||
|
||
/// Determines if a channel is a private encrypted or not, based on its name. | ||
/// - Parameter name: The name of the channel. | ||
/// - Returns: A `Bool` indicating whether the channel is encrypted or not. | ||
static func isEncrypted(name: String?) -> Bool { | ||
return name?.starts(with: "\(Constants.ChannelTypes.privateEncrypted)-") ?? false | ||
} | ||
|
||
/// Determines if an event is a system event or not, based on its name. | ||
/// - Parameter eventName: The name of the event. | ||
/// - Returns: A `Bool` indicating whether the event is a system event or not. | ||
private static func isSystemEvent(eventName: String) -> Bool { | ||
return eventName.starts(with: "\(Constants.EventTypes.pusher):") | ||
|| eventName.starts(with: "\(Constants.EventTypes.pusherInternal):") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Foundation | ||
|
||
extension URL { | ||
|
||
/// Creates a valid URL string that can be used in a connection attempt. | ||
/// - Parameters: | ||
/// - key: The app key to be inserted into the URL. | ||
/// - options: The collection of options needed to correctly construct the URL. | ||
/// - Returns: The constructed URL string, ready to use in a connection attempt. | ||
static func channelsSocketUrl(key: String, options: PusherClientOptions) -> String { | ||
var url = "" | ||
let additionalPathComponents = options.path ?? "" | ||
|
||
if options.useTLS { | ||
url = "wss://\(options.host):\(options.port)\(additionalPathComponents)/app/\(key)" | ||
} else { | ||
url = "ws://\(options.host):\(options.port)\(additionalPathComponents)/app/\(key)" | ||
} | ||
|
||
return "\(url)?client=\(CLIENT_NAME)&version=\(VERSION)&protocol=\(PROTOCOL)" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.