pushreceiver

package module
v0.0.0-...-92c6586 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 26 Imported by: 0

README

go-push-receiver

GoDoc Go Report Card MIT License Github Actions

A library to subscribe to GCM/FCM and receive notifications.

(Forked from crow-misia/go-push-receiver with GCM checkin optional)

This library was developed inspired by push-receiver (https://github.com/MatthieuLemoine/push-receiver/).

Build

install protoc

$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
$ protoc -I=proto --go_out=pb/mcs proto/mcs.proto
$ protoc -I=proto --go_out=pb/checkin proto/checkin.proto
$ protoc -I=proto --go_out=pb/checkin proto/android_checkin.proto
$ go build

License

MIT License

proto file is licensed by is The Chromium Authors. (BSD-style lisense) (copied it from https://chromium.googlesource.com/chromium/chromium/+/trunk/google_apis/gcm/protocol/)

Documentation

Overview

Package pushreceiver is Push Message Receiver library from FCM.

Index

Constants

This section is empty.

Variables

View Source
var ErrFcmNotEnoughData = errors.New("data Enough from FCM")

ErrFcmNotEnoughData is error that data is not enough data from FCM.

View Source
var ErrGcmAuthorization = errors.New("GCM authorization error")

ErrGcmAuthorization is authorization error of GCM.

View Source
var ErrNotFoundInAppData = errors.New("key not found")

ErrNotFoundInAppData is error that key not found in app data.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {
	// contains filtered or unexported fields
}

Backoff with jitter sleep to prevent overloaded conditions during intervals https://www.awsarchitectureblog.com/2015/03/backoff.html

func NewBackoff

func NewBackoff(base time.Duration, max time.Duration) *Backoff

NewBackoff creates Backoff instance.

type Client

type Client struct {
	Events chan Event
	// contains filtered or unexported fields
}

Client is FCM Push receive client.

func New

func New(senderID string, options ...ClientOption) *Client

New returns a new FCM push receive client instance.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context)

Subscribe subscribe to FCM.

type ClientOption

type ClientOption func(*Client)

ClientOption type

func WithBackoff

func WithBackoff(b *Backoff) ClientOption

WithBackoff is Backoff setter

func WithCreds

func WithCreds(creds *FCMCredentials) ClientOption

WithCreds is credentials setter

func WithDialer

func WithDialer(dialer *net.Dialer) ClientOption

WithDialer is net.Dialer setter

func WithGCMCheckin

func WithGCMCheckin(checkin bool) ClientOption

WithGCMCheckin is gcmCheckin setter

func WithHTTPClient

func WithHTTPClient(c httpClient) ClientOption

WithHTTPClient is http.Client setter

func WithHeartbeatPeriod

func WithHeartbeatPeriod(period time.Duration) ClientOption

WithHeartbeatPeriod is Heartbeat period setter

func WithLogger

func WithLogger(logger logger) ClientOption

WithLogger is logger setter

func WithReceivedPersistentID

func WithReceivedPersistentID(ids []string) ClientOption

WithReceivedPersistentID is received persistentId list setter

func WithTLSConfig

func WithTLSConfig(c *tls.Config) ClientOption

WithTLSConfig is tls.Config setter

type ConnectedEvent

type ConnectedEvent struct {
	ServerTimestamp int64
}

ConnectedEvent is connection event.

type DisconnectedEvent

type DisconnectedEvent struct {
	ErrorObj error
}

DisconnectedEvent is disconnect event.

type Event

type Event interface{}

Event type.

type FCMCredentials

type FCMCredentials struct {
	AppID         string `json:"appId"`
	AndroidID     uint64 `json:"androidId"`
	SecurityToken uint64 `json:"securityToken"`
	Token         string `json:"token"`
	PrivateKey    []byte `json:"privateKey"`
	PublicKey     []byte `json:"publicKey"`
	AuthSecret    []byte `json:"authSecret"`
}

FCMCredentials is Credentials for FCM

type Heartbeat

type Heartbeat struct {
	// contains filtered or unexported fields
}

Heartbeat sends signal for connection keep alive.

type HeartbeatError

type HeartbeatError struct {
	ErrorObj error
}

HeartbeatError is send heartbeat error.

type HeartbeatEvent

type HeartbeatEvent struct {
	Send                 bool
	Ack                  bool
	Status               int64
	LastStreamIDReceived int32
}

HeartbeatEvent is send/received heartbeat event.

type MessageEvent

type MessageEvent struct {
	PersistentID string `json:"persistentId"`
	From         string `json:"from"`
	To           string `json:"to"`
	TTL          int32  `json:"ttl"`
	Sent         int64  `json:"sent"`
	Data         []byte `json:"data"`
}

MessageEvent is receive message event.

type RetryEvent

type RetryEvent struct {
	ErrorObj   error
	RetryAfter time.Duration
}

RetryEvent is disconnect event.

type UnauthorizedError

type UnauthorizedError struct {
	ErrorObj error
}

UnauthorizedError is unauthorization error.

type UpdateCredentialsEvent

type UpdateCredentialsEvent struct {
	Credentials *FCMCredentials
}

UpdateCredentialsEvent is credentials update event.

Directories

Path Synopsis
examples
pb
mcs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL