chat: Index | Files | Directories

package push

import ""

Package push contains interfaces to be implemented by push notification plugins.


Package Files



const (
    // New message.
    ActMsg = "msg"
    // New subscription.
    ActSub = "sub"

Push actions

func ChannelSub Uses

func ChannelSub(msg *ChannelReq)

ChannelSub handles a channel (FCM topic) subscription/unsubscription request.

func Init Uses

func Init(jsconfig string) error

Init initializes registered handlers.

func Push Uses

func Push(msg *Receipt)

Push a single message to devices.

func Register Uses

func Register(name string, hnd Handler)

Register a push handler

func Stop Uses

func Stop()

Stop all pushes

type ChannelReq Uses

type ChannelReq struct {
    // Uid is the id of the user making request
    Uid t.Uid `json:"-"`
    // Channel to subscribe to or unsubscribe from.
    Channel string `json:"channel"`
    // Unsub is set to true to unsubscribe devices, otherwise subscribe them.
    Unsub bool `json:"unsub"`

ChannelReq is a request to subscribe/unsubscribe device IDs to channel (FCM topic).

type Handler Uses

type Handler interface {
    // Init initializes the handler.
    Init(jsonconf string) error

    // IsReady сhecks if the handler is initialized.
    IsReady() bool

    // Push returns a channel that the server will use to send messages to.
    // The message will be dropped if the channel blocks.
    Push() chan<- *Receipt

    // Subscribe/unsubscribe device from FCM topic (channel).
    Channel() chan<- *ChannelReq

    // Stop terminates the handler's worker and stops sending pushes.

Handler is an interface which must be implemented by handlers.

type Payload Uses

type Payload struct {
    // Action type of the push: new message (msg), new subscription (sub), etc.
    What string `json:"what"`
    // If this is a silent push: perform action but do not show a notification to the user.
    Silent bool `json:"silent"`
    // Topic which was affected by the action.
    Topic string `json:"topic"`
    // Timestamp of the action.
    Timestamp time.Time `json:"ts"`

    // Message sender 'usrXXX'
    From string `json:"from"`
    // Sequential ID of the message.
    SeqId int `json:"seq"`
    // MIME-Type of the message content, text/x-drafty or text/plain
    ContentType string `json:"mime"`
    // Actual Data.Content of the message, if requested
    Content interface{} `json:"content,omitempty"`

    // Access mode when notifying of new subscriptions.
    ModeWant  t.AccessMode `json:"want,omitempty"`
    ModeGiven t.AccessMode `json:"given,omitempty"`

Payload is content of the push.

type Receipt Uses

type Receipt struct {
    // List of individual recipients, including those who did not receive the message.
    To  map[t.Uid]Recipient `json:"to"`
    // Push topic for group notifications.
    Channel string `json:"channel"`
    // Actual content to be delivered to the client.
    Payload Payload `json:"payload"`

Receipt is the push payload with a list of recipients.

type Recipient Uses

type Recipient struct {
    // Count of user's connections that were live when the packet was dispatched from the server
    Delivered int `json:"delivered"`
    // List of user's devices that the packet was delivered to (if known). Len(Devices) >= Delivered
    Devices []string `json:"devices,omitempty"`
    // Unread count to include in the push
    Unread int `json:"unread"`

Recipient is a user targeted by the push.


fcmPackage fcm implements push notification plugin for Google FCM backend.
stdoutPackage stdout is a sample implementation of a push plugin.
tnpgPackage tnpg implements push notification plugin for Tinode Push Gateway.

Package push imports 4 packages (graph) and is imported by 16 packages. Updated 2020-10-16. Refresh now. Tools for package owners.