Pusher
public class Pusher
Manages operations when interacting with the Pusher Channels HTTP API.
-
Creates a Pusher Channels HTTP API client configured using some
PusherClientOptions
.Declaration
Swift
public init(options: PusherClientOptions)
Parameters
options
Configuration options used to managing the connection.
-
Fetches an array of
ChannelSummary
records for any occupied channels.Declaration
Swift
public func channels(withFilter filter: ChannelFilter = .any, attributeOptions: ChannelAttributeFetchOptions = [], callback: @escaping (Result<[ChannelSummary], PusherError>) -> Void)
Parameters
filter
A filter to apply to the returned results.
attributeOptions
A set of attributes that should be returned in each
ChannelSummary
.callback
A closure that returns a
Result
containing an array ofChannelSummary
instances, or aPusherError
if the operation fails for some reason. -
Fetches the
ChannelInfo
for a given occupied channel.Declaration
Swift
public func channelInfo(for channel: Channel, attributeOptions: ChannelAttributeFetchOptions = [], callback: @escaping (Result<ChannelInfo, PusherError>) -> Void)
Parameters
channel
The channel to inspect.
attributeOptions
A set of attributes that should be returned for the
channel
.callback
A closure that returns a
Result
containing aChannelInfo
instance, or aPusherError
if the operation fails for some reason. -
Fetches an array of
User
records currently subscribed to a given occupied presenceChannel
.Users can only be fetched from presence channels. Using a channel with a
ChannelType
other thanpresence
is invalid and will result in an error.Declaration
Swift
public func users(for channel: Channel, callback: @escaping (Result<[User], PusherError>) -> Void)
Parameters
channel
The presence channel to inspect.
callback
A closure that returns a
Result
containing an array ofUser
instances subscribed to thechannel
, or aPusherError
if the operation fails for some reason.
-
Triggers an
Event
on one or moreChannel
instances.The channel (or channels) that the event should be triggered on, (as well as the attributes to fetch for each channel) are specified when initializing
event
.Declaration
Swift
public func trigger(event: Event, callback: @escaping (Result<[ChannelSummary], PusherError>) -> Void)
Parameters
event
The event to trigger.
callback
A closure that returns a
Result
containing an array ofChannelSummary
instances, or aPusherError
if the operation fails for some reason. If theattributeOptions
on theevent
are not set, an empty channel array will be returned. -
Triggers multiple events, each on a specific
Channel
.The channel that the event should be triggered on, (as well as the attributes to fetch for the each channel) are specified when initializing
event
.Any event in
events
that specifies more than one channel to trigger on will result in an error. Providing an array of more than 10 events to trigger will also result in an error.Declaration
Swift
public func trigger(events: [Event], callback: @escaping (Result<[ChannelInfo], PusherError>) -> Void)
Parameters
events
An array of events to trigger.
callback
A closure that returns a
Result
containing an array ofChannelInfo
instances (where the instance at indexi
corresponds to the channel forevents[i]
, or aPusherError
if the operation fails for some reason. If theattributeOptions
on theevent
are not set, an empty information array will be returned.
-
Verifies that a received Webhook request is genuine and was received from Pusher.
Webhook endpoints are accessible to the global internet. Therefore, verifying that a Webhook request originated from Pusher is important. Valid Webhooks contain special headers that contain a copy of your application key and a HMAC signature of the Webhook payload (i.e. its body).
Declaration
Swift
public func verifyWebhook(request: URLRequest, callback: @escaping (Result<Webhook, PusherError>) -> Void)
Parameters
request
The received Webhook request.
callback
A closure that returns a
Result
containing a verifiedWebhook
and the events that were sent with it (which are decrypted if needed), or aPusherError
if the operation fails for some reason.
-
Generates an authentication token that can be returned to a user client that is attempting to subscribe to a private or presence
Channel
, which requires authentication with the server.Declaration
Swift
public func authenticate(channel: Channel, socketId: String, userData: PresenceUserData? = nil, callback: @escaping (Result<AuthenticationToken, PusherError>) -> Void)
Parameters
channel
The channel for which to generate the authentication token.
socketId
The socket identifier for the connected user.
userData
The data to generate an authentication token for a subscription attempt to a presence channel. (This is required when autenticating a presence channel, and should otherwise be
nil
).callback
A closure that returns a
Result
containing aAuthenticationToken
for subscribing to a private or presence channel, or aPusherError
if the operation fails for some reason.