Pusher

public class Pusher

Manages operations when interacting with the Pusher Channels HTTP API.

Lifecycle

Application state queries

Triggering events

  • Triggers an Event on one or more Channel 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 of ChannelSummary instances, or a PusherError if the operation fails for some reason. If the attributeOptions on the event 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 of ChannelInfo instances (where the instance at index i corresponds to the channel for events[i], or a PusherError if the operation fails for some reason. If the attributeOptions on the event are not set, an empty information array will be returned.

Webhook verification

  • 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 verified Webhook and the events that were sent with it (which are decrypted if needed), or a PusherError if the operation fails for some reason.

Private and presence channel subscription authentication

  • 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 a AuthenticationToken for subscribing to a private or presence channel, or a PusherError if the operation fails for some reason.