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
optionsConfiguration options used to managing the connection.
-
Fetches an array of
ChannelSummaryrecords for any occupied channels.Declaration
Swift
public func channels(withFilter filter: ChannelFilter = .any, attributeOptions: ChannelAttributeFetchOptions = [], callback: @escaping (Result<[ChannelSummary], PusherError>) -> Void)Parameters
filterA filter to apply to the returned results.
attributeOptionsA set of attributes that should be returned in each
ChannelSummary.callbackA closure that returns a
Resultcontaining an array ofChannelSummaryinstances, or aPusherErrorif the operation fails for some reason. -
Fetches the
ChannelInfofor a given occupied channel.Declaration
Swift
public func channelInfo(for channel: Channel, attributeOptions: ChannelAttributeFetchOptions = [], callback: @escaping (Result<ChannelInfo, PusherError>) -> Void)Parameters
channelThe channel to inspect.
attributeOptionsA set of attributes that should be returned for the
channel.callbackA closure that returns a
Resultcontaining aChannelInfoinstance, or aPusherErrorif the operation fails for some reason. -
Fetches an array of
Userrecords currently subscribed to a given occupied presenceChannel.Users can only be fetched from presence channels. Using a channel with a
ChannelTypeother thanpresenceis invalid and will result in an error.Declaration
Swift
public func users(for channel: Channel, callback: @escaping (Result<[User], PusherError>) -> Void)Parameters
channelThe presence channel to inspect.
callbackA closure that returns a
Resultcontaining an array ofUserinstances subscribed to thechannel, or aPusherErrorif the operation fails for some reason.
-
Triggers an
Eventon one or moreChannelinstances.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
eventThe event to trigger.
callbackA closure that returns a
Resultcontaining an array ofChannelSummaryinstances, or aPusherErrorif the operation fails for some reason. If theattributeOptionson theeventare 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
eventsthat 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
eventsAn array of events to trigger.
callbackA closure that returns a
Resultcontaining an array ofChannelInfoinstances (where the instance at indexicorresponds to the channel forevents[i], or aPusherErrorif the operation fails for some reason. If theattributeOptionson theeventare 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
requestThe received Webhook request.
callbackA closure that returns a
Resultcontaining a verifiedWebhookand the events that were sent with it (which are decrypted if needed), or aPusherErrorif 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
channelThe channel for which to generate the authentication token.
socketIdThe socket identifier for the connected user.
userDataThe 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).callbackA closure that returns a
Resultcontaining aAuthenticationTokenfor subscribing to a private or presence channel, or aPusherErrorif the operation fails for some reason.
View on GitHub
Pusher Class Reference