fcm

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2021 License: GPL-3.0 Imports: 14 Imported by: 5

README

FCM push adapter

This adapter sends push notifications to mobile clients and web browsers using Google FCM. As of the time of this writing it supports Android with Play Services, iOS devices, and all major web browsers excluding Safari.

This adapter requires you to obtain your own credentials from Goole Firebase. If you want to use iOS and Android mobile apps with your service, they must be recompiled with your credentials obtained from Google. If you do not want to recompile mobile clients, consider using TNPG adapter instead.

Configuring FCM adapter

Server and TinodeWeb
  1. Create a project at https://firebase.google.com/ if you have not done so already.
  2. Follow instructions at https://cloud.google.com/iam/docs/creating-managing-service-account-keys to download the credentials file.
  3. Update the server config tinode.conf, section "push" -> "name": "fcm". Do ONE of the following:
  • Either enter the path to the downloaded credentials file into "credentials_file".
  • OR copy the file contents to "credentials".

    Remove the other entry. I.e. if you have updated "credentials_file", remove "credentials" and vice versa.
  1. Update TinodeWeb config firebase-init.js: update apiKey, messagingSenderId, projectId, appId, messagingVapidKey. See more info at https://github.com/tinode/webapp/#push_notifications
iOS and Android
  1. If you are using an Android client, add google-services.json to Tindroid by following instructions at https://developers.google.com/android/guides/google-services-plugin and recompile the client. You may also optionally submit it to Google Play Store. See more info at https://github.com/tinode/tindroid/#push_notifications
  2. If you are using an iOS client, add GoogleService-Info.plist to Tinodios by following instructions at https://firebase.google.com/docs/cloud-messaging/ios/client) and recompile the client. You may optionally submit the app to Apple AppStore. See more info at https://github.com/tinode/ios/#push_notifications

Documentation

Overview

Package fcm implements push notification plugin for Google FCM backend. Push notifications for Android, iOS and web clients are sent through Google's Firebase Cloud Messaging service. Package fcm is push notification plugin using Google FCM. https://firebase.google.com/docs/cloud-messaging

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChannelsForUser added in v0.17.0

func ChannelsForUser(uid t.Uid) []string

ChannelsForUser loads user's channel subscriptions with P permission.

func DevicesForUser added in v0.16.8

func DevicesForUser(uid t.Uid) []string

DevicesForUser loads device IDs of the given user.

Types

type AndroidConfig added in v0.16.5

type AndroidConfig struct {
	Enabled bool `json:"enabled,omitempty"`

	// Configs for specific push types.
	Msg androidPayload `json:"msg,omitempty"`
	Sub androidPayload `json:"sub,omitempty"`
	// contains filtered or unexported fields
}

AndroidConfig is the configuration of AndroidNotification payload.

type Handler

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

Handler represents the push handler; implements push.PushHandler interface.

func (Handler) Channel added in v0.16.8

func (Handler) Channel() chan<- *push.ChannelReq

Channel returns a channel for subscribing/unsubscribing devices to FCM topics.

func (Handler) Init

func (Handler) Init(jsonconf string) error

Init initializes the push handler

func (Handler) IsReady

func (Handler) IsReady() bool

IsReady checks if the push handler has been initialized.

func (Handler) Push

func (Handler) Push() chan<- *push.Receipt

Push returns a channel that the server will use to send messages to. If the adapter blocks, the message will be dropped.

func (Handler) Stop

func (Handler) Stop()

Stop shuts down the handler

type MessageData added in v0.16.5

type MessageData struct {
	Uid t.Uid
	// FCM device token.
	DeviceId string
	Message  *fcm.Message
}

MessageData adds user ID and device token to push message. This is needed for error handling.

func PrepareNotifications added in v0.16.5

func PrepareNotifications(rcpt *push.Receipt, config *AndroidConfig) []MessageData

PrepareNotifications creates notification payloads ready to be posted to push notification server for the provided receipt.

Jump to

Keyboard shortcuts

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