Browse Source
* First pass at browser, discord, twilio notifications * Commit updated Javascript packages * Remove twilio notification support * Email notifications/smtp support * Fix Firefox notification support, remove chrome checks * WIP more email work * Add support for twitter notifications * Add stream title to discord and twitter notifications * Update notification registration modal * Fix hide/show email section * Commit updated API documentation * Commit updated Javascript packages * Fix post-rebase missing var * Remove unused var * Handle unsubscribe errors for browser push * Standardize email config prop names * Allow overriding go live email template * Some notifications cleanup * Commit updated Javascript packages * Remove email/smtp/mailjet support * Remove more references to email notifications Co-authored-by: Owncast <owncast@owncast.online>pull/1789/head
39 changed files with 2208 additions and 3312 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,85 @@ |
|||||||
|
package admin |
||||||
|
|
||||||
|
import ( |
||||||
|
"encoding/json" |
||||||
|
"net/http" |
||||||
|
|
||||||
|
"github.com/owncast/owncast/controllers" |
||||||
|
"github.com/owncast/owncast/core/data" |
||||||
|
"github.com/owncast/owncast/models" |
||||||
|
) |
||||||
|
|
||||||
|
// SetDiscordNotificationConfiguration will set the discord notification configuration.
|
||||||
|
func SetDiscordNotificationConfiguration(w http.ResponseWriter, r *http.Request) { |
||||||
|
if !requirePOST(w, r) { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
type request struct { |
||||||
|
Value models.DiscordConfiguration `json:"value"` |
||||||
|
} |
||||||
|
|
||||||
|
decoder := json.NewDecoder(r.Body) |
||||||
|
var config request |
||||||
|
if err := decoder.Decode(&config); err != nil { |
||||||
|
controllers.WriteSimpleResponse(w, false, "unable to update discord config with provided values") |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
if err := data.SetDiscordConfig(config.Value); err != nil { |
||||||
|
controllers.WriteSimpleResponse(w, false, "unable to update discord config with provided values") |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
controllers.WriteSimpleResponse(w, true, "updated discord config with provided values") |
||||||
|
} |
||||||
|
|
||||||
|
// SetBrowserNotificationConfiguration will set the browser notification configuration.
|
||||||
|
func SetBrowserNotificationConfiguration(w http.ResponseWriter, r *http.Request) { |
||||||
|
if !requirePOST(w, r) { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
type request struct { |
||||||
|
Value models.BrowserNotificationConfiguration `json:"value"` |
||||||
|
} |
||||||
|
|
||||||
|
decoder := json.NewDecoder(r.Body) |
||||||
|
var config request |
||||||
|
if err := decoder.Decode(&config); err != nil { |
||||||
|
controllers.WriteSimpleResponse(w, false, "unable to update browser push config with provided values") |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
if err := data.SetBrowserPushConfig(config.Value); err != nil { |
||||||
|
controllers.WriteSimpleResponse(w, false, "unable to update browser push config with provided values") |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
controllers.WriteSimpleResponse(w, true, "updated browser push config with provided values") |
||||||
|
} |
||||||
|
|
||||||
|
// SetTwitterConfiguration will set the browser notification configuration.
|
||||||
|
func SetTwitterConfiguration(w http.ResponseWriter, r *http.Request) { |
||||||
|
if !requirePOST(w, r) { |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
type request struct { |
||||||
|
Value models.TwitterConfiguration `json:"value"` |
||||||
|
} |
||||||
|
|
||||||
|
decoder := json.NewDecoder(r.Body) |
||||||
|
var config request |
||||||
|
if err := decoder.Decode(&config); err != nil { |
||||||
|
controllers.WriteSimpleResponse(w, false, "unable to update twitter config with provided values") |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
if err := data.SetTwitterConfiguration(config.Value); err != nil { |
||||||
|
controllers.WriteSimpleResponse(w, false, "unable to update twitter config with provided values") |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
controllers.WriteSimpleResponse(w, true, "updated twitter config with provided values") |
||||||
|
} |
||||||
@ -0,0 +1,50 @@ |
|||||||
|
package controllers |
||||||
|
|
||||||
|
import ( |
||||||
|
"encoding/json" |
||||||
|
"net/http" |
||||||
|
|
||||||
|
"github.com/owncast/owncast/notifications" |
||||||
|
|
||||||
|
"github.com/owncast/owncast/utils" |
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus" |
||||||
|
) |
||||||
|
|
||||||
|
// RegisterForLiveNotifications will register a channel + destination to be
|
||||||
|
// notified when a stream goes live.
|
||||||
|
func RegisterForLiveNotifications(w http.ResponseWriter, r *http.Request) { |
||||||
|
if r.Method != POST { |
||||||
|
WriteSimpleResponse(w, false, r.Method+" not supported") |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
type request struct { |
||||||
|
// Channel is the notification channel (browser, sms, etc)
|
||||||
|
Channel string `json:"channel"` |
||||||
|
// Destination is the target of the notification in the above channel.
|
||||||
|
Destination string `json:"destination"` |
||||||
|
} |
||||||
|
|
||||||
|
decoder := json.NewDecoder(r.Body) |
||||||
|
var req request |
||||||
|
if err := decoder.Decode(&req); err != nil { |
||||||
|
log.Errorln(err) |
||||||
|
WriteSimpleResponse(w, false, "unable to register for notifications") |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
// Make sure the requested channel is one we want to handle.
|
||||||
|
validTypes := []string{notifications.BrowserPushNotification} |
||||||
|
_, validChannel := utils.FindInSlice(validTypes, req.Channel) |
||||||
|
if !validChannel { |
||||||
|
WriteSimpleResponse(w, false, "invalid notification channel: "+req.Channel) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
if err := notifications.AddNotification(req.Channel, req.Destination); err != nil { |
||||||
|
log.Errorln(err) |
||||||
|
WriteSimpleResponse(w, false, "unable to save notification") |
||||||
|
return |
||||||
|
} |
||||||
|
} |
||||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,27 @@ |
|||||||
|
package models |
||||||
|
|
||||||
|
// DiscordConfiguration represents the configuration for the discord
|
||||||
|
// notification service.
|
||||||
|
type DiscordConfiguration struct { |
||||||
|
Enabled bool `json:"enabled"` |
||||||
|
Webhook string `json:"webhook,omitempty"` |
||||||
|
GoLiveMessage string `json:"goLiveMessage,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
// BrowserNotificationConfiguration represents the configuration for
|
||||||
|
// browser notifications.
|
||||||
|
type BrowserNotificationConfiguration struct { |
||||||
|
Enabled bool `json:"enabled"` |
||||||
|
GoLiveMessage string `json:"goLiveMessage,omitempty"` |
||||||
|
} |
||||||
|
|
||||||
|
// TwitterConfiguration represents the configuration for Twitter access.
|
||||||
|
type TwitterConfiguration struct { |
||||||
|
Enabled bool `json:"enabled"` |
||||||
|
APIKey string `json:"apiKey"` // aka consumer key
|
||||||
|
APISecret string `json:"apiSecret"` // aka consumer secret
|
||||||
|
AccessToken string `json:"accessToken"` |
||||||
|
AccessTokenSecret string `json:"accessTokenSecret"` |
||||||
|
BearerToken string `json:"bearerToken"` |
||||||
|
GoLiveMessage string `json:"goLiveMessage,omitempty"` |
||||||
|
} |
||||||
@ -0,0 +1,83 @@ |
|||||||
|
package browser |
||||||
|
|
||||||
|
import ( |
||||||
|
"encoding/json" |
||||||
|
|
||||||
|
"github.com/SherClockHolmes/webpush-go" |
||||||
|
"github.com/owncast/owncast/core/data" |
||||||
|
"github.com/pkg/errors" |
||||||
|
) |
||||||
|
|
||||||
|
// Browser is an instance of the Browser service.
|
||||||
|
type Browser struct { |
||||||
|
datastore *data.Datastore |
||||||
|
privateKey string |
||||||
|
publicKey string |
||||||
|
} |
||||||
|
|
||||||
|
// New will create a new instance of the Browser service.
|
||||||
|
func New(datastore *data.Datastore, publicKey, privateKey string) (*Browser, error) { |
||||||
|
return &Browser{ |
||||||
|
datastore: datastore, |
||||||
|
privateKey: privateKey, |
||||||
|
publicKey: publicKey, |
||||||
|
}, nil |
||||||
|
} |
||||||
|
|
||||||
|
// GenerateBrowserPushKeys will create the VAPID keys required for web push notifications.
|
||||||
|
func GenerateBrowserPushKeys() (string, string, error) { |
||||||
|
privateKey, publicKey, err := webpush.GenerateVAPIDKeys() |
||||||
|
if err != nil { |
||||||
|
return "", "", errors.Wrap(err, "error generating web push keys") |
||||||
|
} |
||||||
|
|
||||||
|
return privateKey, publicKey, nil |
||||||
|
} |
||||||
|
|
||||||
|
// Send will send a browser push notification to the given subscription.
|
||||||
|
func (b *Browser) Send( |
||||||
|
subscription string, |
||||||
|
title string, |
||||||
|
body string, |
||||||
|
) (bool, error) { |
||||||
|
type message struct { |
||||||
|
Title string `json:"title"` |
||||||
|
Body string `json:"body"` |
||||||
|
Icon string `json:"icon"` |
||||||
|
} |
||||||
|
|
||||||
|
m := message{ |
||||||
|
Title: title, |
||||||
|
Body: body, |
||||||
|
Icon: "/logo/external", |
||||||
|
} |
||||||
|
|
||||||
|
d, err := json.Marshal(m) |
||||||
|
if err != nil { |
||||||
|
return false, errors.Wrap(err, "error marshalling web push message") |
||||||
|
} |
||||||
|
|
||||||
|
// Decode subscription
|
||||||
|
s := &webpush.Subscription{} |
||||||
|
if err := json.Unmarshal([]byte(subscription), s); err != nil { |
||||||
|
return false, errors.Wrap(err, "error decoding destination subscription") |
||||||
|
} |
||||||
|
|
||||||
|
// Send Notification
|
||||||
|
resp, err := webpush.SendNotification(d, s, &webpush.Options{ |
||||||
|
VAPIDPublicKey: b.publicKey, |
||||||
|
VAPIDPrivateKey: b.privateKey, |
||||||
|
Topic: "owncast-go-live", |
||||||
|
TTL: 10, |
||||||
|
// Not really the subscriber, but a contact point for the sender.
|
||||||
|
Subscriber: "owncast@owncast.online", |
||||||
|
}) |
||||||
|
if resp.StatusCode == 410 { |
||||||
|
return true, nil |
||||||
|
} else if err != nil { |
||||||
|
return false, errors.Wrap(err, "error sending browser push notification") |
||||||
|
} |
||||||
|
defer resp.Body.Close() |
||||||
|
|
||||||
|
return false, err |
||||||
|
} |
||||||
@ -0,0 +1,6 @@ |
|||||||
|
package notifications |
||||||
|
|
||||||
|
const ( |
||||||
|
// BrowserPushNotification represents a push notification for a browser.
|
||||||
|
BrowserPushNotification = "BROWSER_PUSH_NOTIFICATION" |
||||||
|
) |
||||||
@ -0,0 +1,61 @@ |
|||||||
|
package discord |
||||||
|
|
||||||
|
import ( |
||||||
|
"bytes" |
||||||
|
"encoding/json" |
||||||
|
"net/http" |
||||||
|
|
||||||
|
"github.com/pkg/errors" |
||||||
|
) |
||||||
|
|
||||||
|
// Discord is an instance of the Discord service.
|
||||||
|
type Discord struct { |
||||||
|
name string |
||||||
|
avatar string |
||||||
|
webhookURL string |
||||||
|
} |
||||||
|
|
||||||
|
// New will create a new instance of the Discord service.
|
||||||
|
func New(name, avatar, webhook string) (*Discord, error) { |
||||||
|
return &Discord{ |
||||||
|
name: name, |
||||||
|
avatar: avatar, |
||||||
|
webhookURL: webhook, |
||||||
|
}, nil |
||||||
|
} |
||||||
|
|
||||||
|
// Send will send a message to a Discord channel via a webhook.
|
||||||
|
func (t *Discord) Send(content string) error { |
||||||
|
type message struct { |
||||||
|
Username string `json:"username"` |
||||||
|
Content string `json:"content"` |
||||||
|
Avatar string `json:"avatar_url"` |
||||||
|
} |
||||||
|
|
||||||
|
msg := message{ |
||||||
|
Username: t.name, |
||||||
|
Content: content, |
||||||
|
Avatar: t.avatar, |
||||||
|
} |
||||||
|
|
||||||
|
jsonText, err := json.Marshal(msg) |
||||||
|
if err != nil { |
||||||
|
return errors.Wrap(err, "error marshalling discord message to json") |
||||||
|
} |
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", t.webhookURL, bytes.NewReader(jsonText)) |
||||||
|
if err != nil { |
||||||
|
return errors.Wrap(err, "error creating discord webhook request") |
||||||
|
} |
||||||
|
|
||||||
|
req.Header.Set("Content-Type", "application/json") |
||||||
|
|
||||||
|
client := &http.Client{} |
||||||
|
|
||||||
|
resp, err := client.Do(req) |
||||||
|
if err != nil { |
||||||
|
return errors.Wrap(err, "error executing discord webhook") |
||||||
|
} |
||||||
|
|
||||||
|
return resp.Body.Close() |
||||||
|
} |
||||||
@ -0,0 +1,193 @@ |
|||||||
|
package notifications |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"strings" |
||||||
|
|
||||||
|
"github.com/owncast/owncast/config" |
||||||
|
"github.com/owncast/owncast/core/data" |
||||||
|
"github.com/owncast/owncast/models" |
||||||
|
"github.com/owncast/owncast/notifications/browser" |
||||||
|
"github.com/owncast/owncast/notifications/discord" |
||||||
|
"github.com/owncast/owncast/notifications/twitter" |
||||||
|
"github.com/owncast/owncast/utils" |
||||||
|
"github.com/pkg/errors" |
||||||
|
log "github.com/sirupsen/logrus" |
||||||
|
) |
||||||
|
|
||||||
|
// Notifier is an instance of the live stream notifier.
|
||||||
|
type Notifier struct { |
||||||
|
datastore *data.Datastore |
||||||
|
browser *browser.Browser |
||||||
|
discord *discord.Discord |
||||||
|
twitter *twitter.Twitter |
||||||
|
} |
||||||
|
|
||||||
|
// Setup will perform any pre-use setup for the notifier.
|
||||||
|
func Setup(datastore *data.Datastore) { |
||||||
|
createNotificationsTable(datastore.DB) |
||||||
|
initializeBrowserPushIfNeeded() |
||||||
|
} |
||||||
|
|
||||||
|
func initializeBrowserPushIfNeeded() { |
||||||
|
pubKey, _ := data.GetBrowserPushPublicKey() |
||||||
|
privKey, _ := data.GetBrowserPushPrivateKey() |
||||||
|
|
||||||
|
// We need browser push keys so people can register for pushes.
|
||||||
|
if pubKey == "" || privKey == "" { |
||||||
|
browserPrivateKey, browserPublicKey, err := browser.GenerateBrowserPushKeys() |
||||||
|
if err != nil { |
||||||
|
log.Errorln("unable to initialize browser push notification keys", err) |
||||||
|
} |
||||||
|
|
||||||
|
if err := data.SetBrowserPushPrivateKey(browserPrivateKey); err != nil { |
||||||
|
log.Errorln("unable to set browser push private key", err) |
||||||
|
} |
||||||
|
|
||||||
|
if err := data.SetBrowserPushPublicKey(browserPublicKey); err != nil { |
||||||
|
log.Errorln("unable to set browser push public key", err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Enable browser push notifications by default.
|
||||||
|
if !data.GetHasPerformedInitialNotificationsConfig() { |
||||||
|
_ = data.SetBrowserPushConfig(models.BrowserNotificationConfiguration{Enabled: true, GoLiveMessage: config.GetDefaults().FederationGoLiveMessage}) |
||||||
|
_ = data.SetHasPerformedInitialNotificationsConfig(true) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// New creates a new instance of the Notifier.
|
||||||
|
func New(datastore *data.Datastore) (*Notifier, error) { |
||||||
|
notifier := Notifier{ |
||||||
|
datastore: datastore, |
||||||
|
} |
||||||
|
|
||||||
|
if err := notifier.setupBrowserPush(); err != nil { |
||||||
|
log.Error(err) |
||||||
|
} |
||||||
|
if err := notifier.setupDiscord(); err != nil { |
||||||
|
log.Error(err) |
||||||
|
} |
||||||
|
if err := notifier.setupTwitter(); err != nil { |
||||||
|
log.Errorln(err) |
||||||
|
} |
||||||
|
|
||||||
|
return ¬ifier, nil |
||||||
|
} |
||||||
|
|
||||||
|
func (n *Notifier) setupBrowserPush() error { |
||||||
|
if data.GetBrowserPushConfig().Enabled { |
||||||
|
publicKey, err := data.GetBrowserPushPublicKey() |
||||||
|
if err != nil || publicKey == "" { |
||||||
|
return errors.Wrap(err, "browser notifier disabled, failed to get browser push public key") |
||||||
|
} |
||||||
|
|
||||||
|
privateKey, err := data.GetBrowserPushPrivateKey() |
||||||
|
if err != nil || privateKey == "" { |
||||||
|
return errors.Wrap(err, "browser notifier disabled, failed to get browser push private key") |
||||||
|
} |
||||||
|
|
||||||
|
browserNotifier, err := browser.New(n.datastore, publicKey, privateKey) |
||||||
|
if err != nil { |
||||||
|
return errors.Wrap(err, "error creating browser notifier") |
||||||
|
} |
||||||
|
n.browser = browserNotifier |
||||||
|
} |
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
func (n *Notifier) notifyBrowserPush() { |
||||||
|
destinations, err := GetNotificationDestinationsForChannel(BrowserPushNotification) |
||||||
|
if err != nil { |
||||||
|
log.Errorln("error getting browser push notification destinations", err) |
||||||
|
} |
||||||
|
for _, destination := range destinations { |
||||||
|
unsubscribed, err := n.browser.Send(destination, data.GetServerName(), data.GetBrowserPushConfig().GoLiveMessage) |
||||||
|
if unsubscribed { |
||||||
|
// If the error is "unsubscribed", then remove the destination from the database.
|
||||||
|
if err := RemoveNotificationForChannel(BrowserPushNotification, destination); err != nil { |
||||||
|
log.Errorln(err) |
||||||
|
} |
||||||
|
} else if err != nil { |
||||||
|
log.Errorln(err) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func (n *Notifier) setupDiscord() error { |
||||||
|
discordConfig := data.GetDiscordConfig() |
||||||
|
if discordConfig.Enabled && discordConfig.Webhook != "" { |
||||||
|
var image string |
||||||
|
if serverURL := data.GetServerURL(); serverURL != "" { |
||||||
|
image = serverURL + "/images/owncast-logo.png" |
||||||
|
} |
||||||
|
discordNotifier, err := discord.New( |
||||||
|
data.GetServerName(), |
||||||
|
image, |
||||||
|
discordConfig.Webhook, |
||||||
|
) |
||||||
|
if err != nil { |
||||||
|
return errors.Wrap(err, "error creating discord notifier") |
||||||
|
} |
||||||
|
n.discord = discordNotifier |
||||||
|
} |
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
func (n *Notifier) notifyDiscord() { |
||||||
|
goLiveMessage := data.GetDiscordConfig().GoLiveMessage |
||||||
|
streamTitle := data.GetStreamTitle() |
||||||
|
if streamTitle != "" { |
||||||
|
goLiveMessage += "\n" + streamTitle |
||||||
|
} |
||||||
|
message := fmt.Sprintf("%s\n\n%s", goLiveMessage, data.GetServerURL()) |
||||||
|
|
||||||
|
if err := n.discord.Send(message); err != nil { |
||||||
|
log.Errorln("error sending discord message", err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func (n *Notifier) setupTwitter() error { |
||||||
|
if twitterConfig := data.GetTwitterConfiguration(); twitterConfig.Enabled { |
||||||
|
if t, err := twitter.New(twitterConfig.APIKey, twitterConfig.APISecret, twitterConfig.AccessToken, twitterConfig.AccessTokenSecret, twitterConfig.BearerToken); err == nil { |
||||||
|
n.twitter = t |
||||||
|
} else if err != nil { |
||||||
|
return errors.Wrap(err, "error creating twitter notifier") |
||||||
|
} |
||||||
|
} |
||||||
|
return nil |
||||||
|
} |
||||||
|
|
||||||
|
func (n *Notifier) notifyTwitter() { |
||||||
|
goLiveMessage := data.GetTwitterConfiguration().GoLiveMessage |
||||||
|
streamTitle := data.GetStreamTitle() |
||||||
|
if streamTitle != "" { |
||||||
|
goLiveMessage += "\n" + streamTitle |
||||||
|
} |
||||||
|
tagString := "" |
||||||
|
for _, tag := range utils.ShuffleStringSlice(data.GetServerMetadataTags()) { |
||||||
|
tagString = fmt.Sprintf("%s #%s", tagString, tag) |
||||||
|
} |
||||||
|
tagString = strings.TrimSpace(tagString) |
||||||
|
|
||||||
|
message := fmt.Sprintf("%s\n%s\n\n%s", goLiveMessage, data.GetServerURL(), tagString) |
||||||
|
|
||||||
|
if err := n.twitter.Notify(message); err != nil { |
||||||
|
log.Errorln("error sending twitter message", err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Notify will fire the different notification channels.
|
||||||
|
func (n *Notifier) Notify() { |
||||||
|
if n.browser != nil { |
||||||
|
n.notifyBrowserPush() |
||||||
|
} |
||||||
|
|
||||||
|
if n.discord != nil { |
||||||
|
n.notifyDiscord() |
||||||
|
} |
||||||
|
|
||||||
|
if n.twitter != nil { |
||||||
|
n.notifyTwitter() |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,60 @@ |
|||||||
|
package notifications |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"database/sql" |
||||||
|
|
||||||
|
"github.com/owncast/owncast/core/data" |
||||||
|
"github.com/owncast/owncast/db" |
||||||
|
"github.com/pkg/errors" |
||||||
|
log "github.com/sirupsen/logrus" |
||||||
|
) |
||||||
|
|
||||||
|
func createNotificationsTable(db *sql.DB) { |
||||||
|
log.Traceln("Creating federation followers table...") |
||||||
|
|
||||||
|
createTableSQL := `CREATE TABLE IF NOT EXISTS notifications ( |
||||||
|
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, |
||||||
|
"channel" TEXT NOT NULL, |
||||||
|
"destination" TEXT NOT NULL, |
||||||
|
"created_at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP); |
||||||
|
CREATE INDEX channel_index ON notifications (channel);` |
||||||
|
|
||||||
|
stmt, err := db.Prepare(createTableSQL) |
||||||
|
if err != nil { |
||||||
|
log.Fatal(err) |
||||||
|
} |
||||||
|
defer stmt.Close() |
||||||
|
_, err = stmt.Exec() |
||||||
|
if err != nil { |
||||||
|
log.Warnln("error executing sql creating followers table", createTableSQL, err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// AddNotification saves a new user notification destination.
|
||||||
|
func AddNotification(channel, destination string) error { |
||||||
|
return data.GetDatastore().GetQueries().AddNotification(context.Background(), db.AddNotificationParams{ |
||||||
|
Channel: channel, |
||||||
|
Destination: destination, |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
// RemoveNotificationForChannel removes a notification destination..
|
||||||
|
func RemoveNotificationForChannel(channel, destination string) error { |
||||||
|
log.Println("Removing notification for channel", channel) |
||||||
|
return data.GetDatastore().GetQueries().RemoveNotificationDestinationForChannel(context.Background(), db.RemoveNotificationDestinationForChannelParams{ |
||||||
|
Channel: channel, |
||||||
|
Destination: destination, |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
// GetNotificationDestinationsForChannel will return a collection of
|
||||||
|
// destinations to notify for a given channel.
|
||||||
|
func GetNotificationDestinationsForChannel(channel string) ([]string, error) { |
||||||
|
result, err := data.GetDatastore().GetQueries().GetNotificationDestinationsForChannel(context.Background(), channel) |
||||||
|
if err != nil { |
||||||
|
return nil, errors.Wrap(err, "unable to query notification destinations for channel "+channel) |
||||||
|
} |
||||||
|
|
||||||
|
return result, nil |
||||||
|
} |
||||||
@ -0,0 +1,78 @@ |
|||||||
|
package twitter |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"errors" |
||||||
|
"fmt" |
||||||
|
"net/http" |
||||||
|
|
||||||
|
"github.com/dghubble/oauth1" |
||||||
|
"github.com/g8rswimmer/go-twitter/v2" |
||||||
|
) |
||||||
|
|
||||||
|
/* |
||||||
|
1. developer.twitter.com. Apply to be a developer if needed. |
||||||
|
2. Projects and apps -> Your project name |
||||||
|
3. Settings. |
||||||
|
4. Scroll down to"User authentication settings" Edit |
||||||
|
5. Enable OAuth 1.0a with Read/Write permissions. |
||||||
|
6. Fill out the form with your information. Callback can be anything. |
||||||
|
7. Go to your project "Keys and tokens" |
||||||
|
8. Generate API key and secret. |
||||||
|
9. Generate access token and secret. Verify it says "Read and write permissions." |
||||||
|
10. Generate bearer token. |
||||||
|
*/ |
||||||
|
|
||||||
|
type authorize struct { |
||||||
|
Token string |
||||||
|
} |
||||||
|
|
||||||
|
func (a authorize) Add(req *http.Request) { |
||||||
|
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", a.Token)) |
||||||
|
} |
||||||
|
|
||||||
|
// Twitter is an instance of the Twitter notifier.
|
||||||
|
type Twitter struct { |
||||||
|
apiKey string |
||||||
|
apiSecret string |
||||||
|
accessToken string |
||||||
|
accessTokenSecret string |
||||||
|
bearerToken string |
||||||
|
} |
||||||
|
|
||||||
|
// New returns a new instance of the Twitter notifier.
|
||||||
|
func New(apiKey, apiSecret, accessToken, accessTokenSecret, bearerToken string) (*Twitter, error) { |
||||||
|
if apiKey == "" || apiSecret == "" || accessToken == "" || accessTokenSecret == "" || bearerToken == "" { |
||||||
|
return nil, errors.New("missing some or all of the required twitter configuration values") |
||||||
|
} |
||||||
|
|
||||||
|
return &Twitter{ |
||||||
|
apiKey: apiKey, |
||||||
|
apiSecret: apiSecret, |
||||||
|
accessToken: accessToken, |
||||||
|
accessTokenSecret: accessTokenSecret, |
||||||
|
bearerToken: bearerToken, |
||||||
|
}, nil |
||||||
|
} |
||||||
|
|
||||||
|
// Notify will send a notification to Twitter with the supplied text.
|
||||||
|
func (t *Twitter) Notify(text string) error { |
||||||
|
config := oauth1.NewConfig(t.apiKey, t.apiSecret) |
||||||
|
token := oauth1.NewToken(t.accessToken, t.accessTokenSecret) |
||||||
|
httpClient := config.Client(oauth1.NoContext, token) |
||||||
|
|
||||||
|
client := &twitter.Client{ |
||||||
|
Authorizer: authorize{ |
||||||
|
Token: t.bearerToken, |
||||||
|
}, |
||||||
|
Client: httpClient, |
||||||
|
Host: "https://api.twitter.com", |
||||||
|
} |
||||||
|
|
||||||
|
req := twitter.CreateTweetRequest{ |
||||||
|
Text: text, |
||||||
|
} |
||||||
|
|
||||||
|
_, err := client.CreateTweet(context.Background(), req) |
||||||
|
return err |
||||||
|
} |
||||||
@ -0,0 +1,487 @@ |
|||||||
|
<!DOCTYPE html> |
||||||
|
<html |
||||||
|
lang="en" |
||||||
|
xmlns="http://www.w3.org/1999/xhtml" |
||||||
|
xmlns:v="urn:schemas-microsoft-com:vml" |
||||||
|
xmlns:o="urn:schemas-microsoft-com:office:office" |
||||||
|
> |
||||||
|
<head> |
||||||
|
<meta charset="utf-8" /> |
||||||
|
<!-- utf-8 works for most cases --> |
||||||
|
<meta name="viewport" content="width=device-width" /> |
||||||
|
<!-- Forcing initial-scale shouldn't be necessary --> |
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> |
||||||
|
<!-- Use the latest (edge) version of IE rendering engine --> |
||||||
|
<meta name="x-apple-disable-message-reformatting" /> |
||||||
|
<!-- Disable auto-scale in iOS 10 Mail entirely --> |
||||||
|
<title></title> |
||||||
|
<!-- The title tag shows in email notifications, like Android 4.4. --> |
||||||
|
|
||||||
|
<link |
||||||
|
href="https://fonts.googleapis.com/css?family=Lato:300,400,700" |
||||||
|
rel="stylesheet" |
||||||
|
/> |
||||||
|
|
||||||
|
<!-- CSS Reset : BEGIN --> |
||||||
|
<style> |
||||||
|
/* What it does: Remove spaces around the email design added by some email clients. */ |
||||||
|
/* Beware: It can remove the padding / margin and add a background color to the compose a reply window. */ |
||||||
|
html, |
||||||
|
body { |
||||||
|
margin: 0 auto !important; |
||||||
|
padding: 0 !important; |
||||||
|
height: 100% !important; |
||||||
|
width: 100% !important; |
||||||
|
background: #f1f1f1; |
||||||
|
} |
||||||
|
|
||||||
|
/* What it does: Stops email clients resizing small text. */ |
||||||
|
* { |
||||||
|
-ms-text-size-adjust: 100%; |
||||||
|
-webkit-text-size-adjust: 100%; |
||||||
|
} |
||||||
|
|
||||||
|
/* What it does: Centers email on Android 4.4 */ |
||||||
|
div[style*='margin: 16px 0'] { |
||||||
|
margin: 0 !important; |
||||||
|
} |
||||||
|
|
||||||
|
/* What it does: Stops Outlook from adding extra spacing to tables. */ |
||||||
|
table, |
||||||
|
td { |
||||||
|
mso-table-lspace: 0pt !important; |
||||||
|
mso-table-rspace: 0pt !important; |
||||||
|
} |
||||||
|
|
||||||
|
/* What it does: Fixes webkit padding issue. */ |
||||||
|
table { |
||||||
|
border-spacing: 0 !important; |
||||||
|
border-collapse: collapse !important; |
||||||
|
table-layout: fixed !important; |
||||||
|
margin: 0 auto !important; |
||||||
|
} |
||||||
|
|
||||||
|
/* What it does: Uses a better rendering method when resizing images in IE. */ |
||||||
|
img { |
||||||
|
-ms-interpolation-mode: bicubic; |
||||||
|
} |
||||||
|
|
||||||
|
/* What it does: Prevents Windows 10 Mail from underlining links despite inline CSS. Styles for underlined links should be inline. */ |
||||||
|
a { |
||||||
|
text-decoration: none; |
||||||
|
} |
||||||
|
|
||||||
|
/* What it does: A work-around for email clients meddling in triggered links. */ |
||||||
|
*[x-apple-data-detectors], /* iOS */ |
||||||
|
.unstyle-auto-detected-links *, |
||||||
|
.aBn { |
||||||
|
border-bottom: 0 !important; |
||||||
|
cursor: default !important; |
||||||
|
color: inherit !important; |
||||||
|
text-decoration: none !important; |
||||||
|
font-size: inherit !important; |
||||||
|
font-family: inherit !important; |
||||||
|
font-weight: inherit !important; |
||||||
|
line-height: inherit !important; |
||||||
|
} |
||||||
|
|
||||||
|
/* What it does: Prevents Gmail from displaying a download button on large, non-linked images. */ |
||||||
|
.a6S { |
||||||
|
display: none !important; |
||||||
|
opacity: 0.01 !important; |
||||||
|
} |
||||||
|
|
||||||
|
/* What it does: Prevents Gmail from changing the text color in conversation threads. */ |
||||||
|
.im { |
||||||
|
color: inherit !important; |
||||||
|
} |
||||||
|
|
||||||
|
/* If the above doesn't work, add a .g-img class to any image in question. */ |
||||||
|
img.g-img + div { |
||||||
|
display: none !important; |
||||||
|
} |
||||||
|
|
||||||
|
/* What it does: Removes right gutter in Gmail iOS app: https://github.com/TedGoas/Cerberus/issues/89 */ |
||||||
|
/* Create one of these media queries for each additional viewport size you'd like to fix */ |
||||||
|
|
||||||
|
/* iPhone 4, 4S, 5, 5S, 5C, and 5SE */ |
||||||
|
@media only screen and (min-device-width: 320px) and (max-device-width: 374px) { |
||||||
|
u ~ div .email-container { |
||||||
|
min-width: 320px !important; |
||||||
|
} |
||||||
|
} |
||||||
|
/* iPhone 6, 6S, 7, 8, and X */ |
||||||
|
@media only screen and (min-device-width: 375px) and (max-device-width: 413px) { |
||||||
|
u ~ div .email-container { |
||||||
|
min-width: 375px !important; |
||||||
|
} |
||||||
|
} |
||||||
|
/* iPhone 6+, 7+, and 8+ */ |
||||||
|
@media only screen and (min-device-width: 414px) { |
||||||
|
u ~ div .email-container { |
||||||
|
min-width: 414px !important; |
||||||
|
} |
||||||
|
} |
||||||
|
</style> |
||||||
|
|
||||||
|
<!-- CSS Reset : END --> |
||||||
|
|
||||||
|
<!-- Progressive Enhancements : BEGIN --> |
||||||
|
<style> |
||||||
|
.primary { |
||||||
|
background: #6655b3; |
||||||
|
} |
||||||
|
.bg_white { |
||||||
|
background: #ffffff; |
||||||
|
} |
||||||
|
.bg_light { |
||||||
|
background: #fafafa; |
||||||
|
} |
||||||
|
.bg_black { |
||||||
|
background: #000000; |
||||||
|
} |
||||||
|
.bg_dark { |
||||||
|
background: rgba(0, 0, 0, 0.8); |
||||||
|
} |
||||||
|
.email-section { |
||||||
|
padding: 2.5em; |
||||||
|
} |
||||||
|
|
||||||
|
/*BUTTON*/ |
||||||
|
.btn { |
||||||
|
padding: 10px 15px; |
||||||
|
display: inline-block; |
||||||
|
font-size: 1.4em; |
||||||
|
} |
||||||
|
.btn.btn-primary { |
||||||
|
border-radius: 5px; |
||||||
|
background: #6655b3; |
||||||
|
color: #ffffff; |
||||||
|
} |
||||||
|
.btn.btn-white { |
||||||
|
border-radius: 5px; |
||||||
|
background: #ffffff; |
||||||
|
color: #000000; |
||||||
|
} |
||||||
|
.btn.btn-white-outline { |
||||||
|
border-radius: 5px; |
||||||
|
background: transparent; |
||||||
|
border: 1px solid #fff; |
||||||
|
color: #fff; |
||||||
|
} |
||||||
|
.btn.btn-black-outline { |
||||||
|
border-radius: 0px; |
||||||
|
background: transparent; |
||||||
|
border: 2px solid #000; |
||||||
|
color: #000; |
||||||
|
font-weight: 700; |
||||||
|
} |
||||||
|
|
||||||
|
h1, |
||||||
|
h2, |
||||||
|
h3, |
||||||
|
h4, |
||||||
|
h5, |
||||||
|
h6 { |
||||||
|
font-family: 'Lato', sans-serif; |
||||||
|
color: #000000; |
||||||
|
margin-top: 0; |
||||||
|
font-weight: 400; |
||||||
|
} |
||||||
|
|
||||||
|
body { |
||||||
|
font-family: 'Lato', sans-serif; |
||||||
|
font-weight: 400; |
||||||
|
font-size: 15px; |
||||||
|
line-height: 1.8; |
||||||
|
color: rgba(0, 0, 0, 0.4); |
||||||
|
} |
||||||
|
|
||||||
|
a { |
||||||
|
color: #6655b3; |
||||||
|
} |
||||||
|
|
||||||
|
table { |
||||||
|
} |
||||||
|
/*LOGO*/ |
||||||
|
|
||||||
|
.logo h1 { |
||||||
|
margin: 0; |
||||||
|
} |
||||||
|
.logo h1 a { |
||||||
|
color: #6655b3; |
||||||
|
font-size: 24px; |
||||||
|
font-weight: 700; |
||||||
|
font-family: 'Lato', sans-serif; |
||||||
|
} |
||||||
|
|
||||||
|
/*HERO*/ |
||||||
|
.hero { |
||||||
|
position: relative; |
||||||
|
z-index: 0; |
||||||
|
} |
||||||
|
|
||||||
|
.hero .text { |
||||||
|
color: rgba(0, 0, 0, 0.3); |
||||||
|
} |
||||||
|
.hero .text h2 { |
||||||
|
color: #000; |
||||||
|
font-size: 40px; |
||||||
|
margin-bottom: 0; |
||||||
|
font-weight: 400; |
||||||
|
line-height: 1.4; |
||||||
|
} |
||||||
|
.hero .text h3 { |
||||||
|
font-size: 24px; |
||||||
|
font-weight: 300; |
||||||
|
} |
||||||
|
.hero .text h2 span { |
||||||
|
font-weight: 600; |
||||||
|
color: #6655b3; |
||||||
|
} |
||||||
|
|
||||||
|
/*HEADING SECTION*/ |
||||||
|
.heading-section { |
||||||
|
} |
||||||
|
.heading-section h2 { |
||||||
|
color: #000000; |
||||||
|
font-size: 28px; |
||||||
|
margin-top: 0; |
||||||
|
line-height: 1.4; |
||||||
|
font-weight: 400; |
||||||
|
} |
||||||
|
.heading-section .subheading { |
||||||
|
margin-bottom: 20px !important; |
||||||
|
display: inline-block; |
||||||
|
font-size: 13px; |
||||||
|
text-transform: uppercase; |
||||||
|
letter-spacing: 2px; |
||||||
|
color: rgba(0, 0, 0, 0.4); |
||||||
|
position: relative; |
||||||
|
} |
||||||
|
.heading-section .subheading::after { |
||||||
|
position: absolute; |
||||||
|
left: 0; |
||||||
|
right: 0; |
||||||
|
bottom: -10px; |
||||||
|
content: ''; |
||||||
|
width: 100%; |
||||||
|
height: 2px; |
||||||
|
background: #6655b3; |
||||||
|
margin: 0 auto; |
||||||
|
} |
||||||
|
|
||||||
|
.heading-section-white { |
||||||
|
color: rgba(255, 255, 255, 0.8); |
||||||
|
} |
||||||
|
.heading-section-white h2 { |
||||||
|
line-height: 1; |
||||||
|
padding-bottom: 0; |
||||||
|
} |
||||||
|
.heading-section-white h2 { |
||||||
|
color: #ffffff; |
||||||
|
} |
||||||
|
.heading-section-white .subheading { |
||||||
|
margin-bottom: 0; |
||||||
|
display: inline-block; |
||||||
|
font-size: 13px; |
||||||
|
text-transform: uppercase; |
||||||
|
letter-spacing: 2px; |
||||||
|
color: rgba(255, 255, 255, 0.4); |
||||||
|
} |
||||||
|
|
||||||
|
ul.social { |
||||||
|
padding: 0; |
||||||
|
} |
||||||
|
ul.social li { |
||||||
|
display: inline-block; |
||||||
|
margin-right: 10px; |
||||||
|
} |
||||||
|
|
||||||
|
/*FOOTER*/ |
||||||
|
|
||||||
|
.footer { |
||||||
|
border-top: 1px solid rgba(0, 0, 0, 0.05); |
||||||
|
color: rgba(0, 0, 0, 0.5); |
||||||
|
} |
||||||
|
.footer .heading { |
||||||
|
color: #000; |
||||||
|
font-size: 20px; |
||||||
|
} |
||||||
|
.footer ul { |
||||||
|
margin: 0; |
||||||
|
padding: 0; |
||||||
|
} |
||||||
|
.footer ul li { |
||||||
|
list-style: none; |
||||||
|
margin-bottom: 10px; |
||||||
|
} |
||||||
|
.footer ul li a { |
||||||
|
color: rgba(0, 0, 0, 1); |
||||||
|
} |
||||||
|
|
||||||
|
#owncast-promo { |
||||||
|
font-size: 10px; |
||||||
|
} |
||||||
|
|
||||||
|
@media screen and (max-width: 500px) { |
||||||
|
} |
||||||
|
</style> |
||||||
|
</head> |
||||||
|
|
||||||
|
<body |
||||||
|
width="100%" |
||||||
|
style=" |
||||||
|
margin: 0; |
||||||
|
padding: 0 !important; |
||||||
|
mso-line-height-rule: exactly; |
||||||
|
background-color: #f1f1f1; |
||||||
|
" |
||||||
|
> |
||||||
|
<center style="width: 100%; background-color: #f1f1f1"> |
||||||
|
<div |
||||||
|
style=" |
||||||
|
display: none; |
||||||
|
font-size: 1px; |
||||||
|
max-height: 0px; |
||||||
|
max-width: 0px; |
||||||
|
opacity: 0; |
||||||
|
overflow: hidden; |
||||||
|
mso-hide: all; |
||||||
|
font-family: sans-serif; |
||||||
|
" |
||||||
|
> |
||||||
|
‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ |
||||||
|
</div> |
||||||
|
<div style="max-width: 600px; margin: 0 auto" class="email-container"> |
||||||
|
<!-- BEGIN BODY --> |
||||||
|
<table |
||||||
|
align="center" |
||||||
|
role="presentation" |
||||||
|
cellspacing="0" |
||||||
|
cellpadding="0" |
||||||
|
border="0" |
||||||
|
width="100%" |
||||||
|
style="margin: auto" |
||||||
|
> |
||||||
|
<tr> |
||||||
|
<td |
||||||
|
valign="top" |
||||||
|
class="bg_white" |
||||||
|
style="padding: 1em 2.5em 0 2.5em" |
||||||
|
> |
||||||
|
<table |
||||||
|
role="presentation" |
||||||
|
border="0" |
||||||
|
cellpadding="0" |
||||||
|
cellspacing="0" |
||||||
|
width="100%" |
||||||
|
> |
||||||
|
<tr> |
||||||
|
<td class="logo" style="text-align: center"> |
||||||
|
<h1><a href="{{.ServerURL}}">{{.ServerName}}</a></h1> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<!-- end tr --> |
||||||
|
<tr> |
||||||
|
<td |
||||||
|
valign="middle" |
||||||
|
class="hero bg_white" |
||||||
|
style="padding: 3em 0 2em 0" |
||||||
|
> |
||||||
|
<a href="{{.ServerURL}}"> |
||||||
|
<img |
||||||
|
src="{{.Logo}}" |
||||||
|
alt="" |
||||||
|
style=" |
||||||
|
width: 100px; |
||||||
|
max-width: 600px; |
||||||
|
height: auto; |
||||||
|
margin: auto; |
||||||
|
display: block; |
||||||
|
" |
||||||
|
/> |
||||||
|
</a> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<!-- end tr --> |
||||||
|
<tr> |
||||||
|
<td |
||||||
|
valign="middle" |
||||||
|
class="hero bg_white" |
||||||
|
style="padding: 2em 0 4em 0" |
||||||
|
> |
||||||
|
<table> |
||||||
|
<tr> |
||||||
|
<td> |
||||||
|
<div |
||||||
|
class="text" |
||||||
|
style="padding: 0 2.5em; text-align: center" |
||||||
|
> |
||||||
|
<a href="{{.ServerURL}}"> |
||||||
|
<img |
||||||
|
src="{{.Thumbnail}}" |
||||||
|
alt="" |
||||||
|
style=" |
||||||
|
width: 300px; |
||||||
|
max-width: 600px; |
||||||
|
height: auto; |
||||||
|
margin: auto; |
||||||
|
display: block; |
||||||
|
" |
||||||
|
/> |
||||||
|
</a> |
||||||
|
<h2><a href="{{.ServerURL}}">{{.ServerName}}</h2></a> |
||||||
|
<h3>{{.StreamDescription}}</h3> |
||||||
|
<p> |
||||||
|
<a href="{{.ServerURL}}" class="btn btn-primary" |
||||||
|
>Watch now!</a |
||||||
|
> |
||||||
|
</p> |
||||||
|
</div> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
<!-- end tr --> |
||||||
|
<!-- 1 Column Text + Button : END --> |
||||||
|
</table> |
||||||
|
<table |
||||||
|
align="center" |
||||||
|
role="presentation" |
||||||
|
cellspacing="0" |
||||||
|
cellpadding="0" |
||||||
|
border="0" |
||||||
|
width="100%" |
||||||
|
style="margin: auto" |
||||||
|
> |
||||||
|
<!-- end: tr --> |
||||||
|
<tr> |
||||||
|
<td class="bg_light" style="text-align: center"> |
||||||
|
<p> |
||||||
|
No longer want to receive emails from {{.ServerName}}? You should |
||||||
|
<a href="[[UNSUB_LINK_EN]]" style="color: rgba(0, 0, 0, 0.8)" |
||||||
|
>unsubscribe here</a |
||||||
|
>. |
||||||
|
</p> |
||||||
|
<p id="owncast-promo"> |
||||||
|
This stream is powered by |
||||||
|
<a href="https://owncast.online" |
||||||
|
><img |
||||||
|
src="https://owncast.online/images/logo.svg" |
||||||
|
width="10px" |
||||||
|
/> Owncast</a |
||||||
|
> |
||||||
|
and you can run your own, too. |
||||||
|
</p> |
||||||
|
</td> |
||||||
|
</tr> |
||||||
|
</table> |
||||||
|
</div> |
||||||
|
</center> |
||||||
|
</body> |
||||||
|
</html> |
||||||
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 3.2 MiB |
@ -0,0 +1,405 @@ |
|||||||
|
import { h } from '/js/web_modules/preact.js'; |
||||||
|
import { useState, useEffect } from '/js/web_modules/preact/hooks.js'; |
||||||
|
|
||||||
|
import htm from '/js/web_modules/htm.js'; |
||||||
|
import { ExternalActionButton } from './external-action-modal.js'; |
||||||
|
import { |
||||||
|
registerWebPushNotifications, |
||||||
|
isPushNotificationSupported, |
||||||
|
} from '../notification/registerWeb.js'; |
||||||
|
import { |
||||||
|
URL_REGISTER_NOTIFICATION, |
||||||
|
URL_REGISTER_EMAIL_NOTIFICATION, |
||||||
|
HAS_DISPLAYED_NOTIFICATION_MODAL_KEY, |
||||||
|
USER_VISIT_COUNT_KEY, |
||||||
|
USER_DISMISSED_ANNOYING_NOTIFICATION_POPUP_KEY, |
||||||
|
} from '../utils/constants.js'; |
||||||
|
import { setLocalStorage, getLocalStorage } from '../utils/helpers.js'; |
||||||
|
|
||||||
|
const html = htm.bind(h); |
||||||
|
|
||||||
|
export function NotifyModal({ notifications, streamName, accessToken }) { |
||||||
|
const [error, setError] = useState(null); |
||||||
|
const [loaderStyle, setLoaderStyle] = useState('none'); |
||||||
|
const [emailNotificationsButtonEnabled, setEmailNotificationsButtonEnabled] = |
||||||
|
useState(false); |
||||||
|
const [emailAddress, setEmailAddress] = useState(null); |
||||||
|
const emailNotificationButtonState = emailNotificationsButtonEnabled |
||||||
|
? '' |
||||||
|
: 'cursor-not-allowed opacity-50'; |
||||||
|
const [browserPushPermissionsPending, setBrowserPushPermissionsPending] = |
||||||
|
useState(false); |
||||||
|
|
||||||
|
const { browser, email } = notifications; |
||||||
|
const { publicKey } = browser; |
||||||
|
|
||||||
|
const browserPushEnabled = browser.enabled && isPushNotificationSupported(); |
||||||
|
let emailEnabled = email.enabled; |
||||||
|
|
||||||
|
// Store that the user has opened the notifications modal at least once
|
||||||
|
// so we don't ever need to remind them to do it again.
|
||||||
|
useEffect(() => { |
||||||
|
setLocalStorage(HAS_DISPLAYED_NOTIFICATION_MODAL_KEY, true); |
||||||
|
}, []); |
||||||
|
|
||||||
|
async function saveNotificationRegistration(channel, destination) { |
||||||
|
const options = { |
||||||
|
method: 'POST', |
||||||
|
headers: { |
||||||
|
'Content-Type': 'application/json', |
||||||
|
}, |
||||||
|
body: JSON.stringify({ channel: channel, destination: destination }), |
||||||
|
}; |
||||||
|
|
||||||
|
try { |
||||||
|
await fetch( |
||||||
|
URL_REGISTER_NOTIFICATION + `?accessToken=${accessToken}`, |
||||||
|
options |
||||||
|
); |
||||||
|
} catch (e) { |
||||||
|
console.error(e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
async function startBrowserPushRegistration() { |
||||||
|
// If it's already denied or granted, don't do anything.
|
||||||
|
if (Notification.permission !== 'default') { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
setBrowserPushPermissionsPending(true); |
||||||
|
try { |
||||||
|
const subscription = await registerWebPushNotifications(publicKey); |
||||||
|
saveNotificationRegistration('BROWSER_PUSH_NOTIFICATION', subscription); |
||||||
|
setError(null); |
||||||
|
} catch (e) { |
||||||
|
setError( |
||||||
|
`Error registering for live notifications: ${e.message}. Make sure you're not inside a private browser environment or have previously disabled notifications for this stream.` |
||||||
|
); |
||||||
|
} |
||||||
|
setBrowserPushPermissionsPending(false); |
||||||
|
} |
||||||
|
|
||||||
|
async function handlePushToggleChange() { |
||||||
|
// Nothing can be done if they already denied access.
|
||||||
|
if (Notification.permission === 'denied') { |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if (!pushEnabled) { |
||||||
|
startBrowserPushRegistration(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
async function registerForEmailButtonPressed() { |
||||||
|
try { |
||||||
|
const options = { |
||||||
|
method: 'POST', |
||||||
|
headers: { |
||||||
|
'Content-Type': 'application/json', |
||||||
|
}, |
||||||
|
body: JSON.stringify({ emailAddress: emailAddress }), |
||||||
|
}; |
||||||
|
|
||||||
|
try { |
||||||
|
await fetch( |
||||||
|
URL_REGISTER_EMAIL_NOTIFICATION + `?accessToken=${accessToken}`, |
||||||
|
options |
||||||
|
); |
||||||
|
} catch (e) { |
||||||
|
console.error(e); |
||||||
|
} |
||||||
|
} catch (e) { |
||||||
|
setError(`Error registering for email notifications: ${e.message}.`); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function onEmailInput(e) { |
||||||
|
const { value } = e.target; |
||||||
|
|
||||||
|
// TODO: Add validation for email
|
||||||
|
const valid = true; |
||||||
|
|
||||||
|
setEmailAddress(value); |
||||||
|
setEmailNotificationsButtonEnabled(valid); |
||||||
|
} |
||||||
|
|
||||||
|
function getBrowserPushButtonText() { |
||||||
|
let pushNotificationButtonText = html`<span id="push-notification-arrow"
|
||||||
|
>←</span |
||||||
|
> |
||||||
|
CLICK TO ENABLE`;
|
||||||
|
if (browserPushPermissionsPending) { |
||||||
|
pushNotificationButtonText = '↑ ACCEPT THE BROWSER PERMISSIONS'; |
||||||
|
} else if (Notification.permission === 'granted') { |
||||||
|
pushNotificationButtonText = 'ENABLED'; |
||||||
|
} else if (Notification.permission === 'denied') { |
||||||
|
pushNotificationButtonText = 'DENIED. PLEASE FIX BROWSER PERMISSIONS.'; |
||||||
|
} |
||||||
|
return pushNotificationButtonText; |
||||||
|
} |
||||||
|
|
||||||
|
const pushEnabled = Notification.permission === 'granted'; |
||||||
|
|
||||||
|
return html` |
||||||
|
<div class="bg-gray-100 bg-center bg-no-repeat p-6"> |
||||||
|
<div |
||||||
|
style=${{ display: emailEnabled ? 'grid' : 'none' }} |
||||||
|
class="grid grid-cols-2 gap-10 px-5 py-8" |
||||||
|
> |
||||||
|
<div> |
||||||
|
<h2 class="text-slate-600 text-2xl mb-2 font-semibold"> |
||||||
|
Email Notifications |
||||||
|
</h2> |
||||||
|
|
||||||
|
<h2> |
||||||
|
Get notified directly to your email when this stream goes live. |
||||||
|
</h2> |
||||||
|
</div> |
||||||
|
<div> |
||||||
|
<div class="font-semibold">Enter your email address:</div> |
||||||
|
<input |
||||||
|
class="border bg-white rounded-l w-8/12 mt-2 mb-1 mr-1 py-2 px-3 text-indigo-700 leading-tight focus:outline-none focus:shadow-outline" |
||||||
|
value=${emailAddress} |
||||||
|
onInput=${onEmailInput} |
||||||
|
placeholder="streamlover42@gmail.com" |
||||||
|
/> |
||||||
|
<button |
||||||
|
class="rounded-sm inline px-3 py-2 text-base text-white bg-indigo-700 ${emailNotificationButtonState}" |
||||||
|
onClick=${registerForEmailButtonPressed} |
||||||
|
> |
||||||
|
Save |
||||||
|
</button> |
||||||
|
<div class="text-sm mt-3 text-gray-700"> |
||||||
|
Stop receiving emails any time by clicking the unsubscribe link in |
||||||
|
the email. <a href="">Learn more.</a> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<hr |
||||||
|
style=${{ display: pushEnabled && emailEnabled ? 'block' : 'none' }} |
||||||
|
/> |
||||||
|
|
||||||
|
<div |
||||||
|
class="grid grid-cols-2 gap-10 px-5 py-8" |
||||||
|
style=${{ display: browserPushEnabled ? 'grid' : 'none' }} |
||||||
|
> |
||||||
|
<div> |
||||||
|
<div> |
||||||
|
<div |
||||||
|
class="text-sm border-2 p-4 border-red-300" |
||||||
|
style=${{ |
||||||
|
display: |
||||||
|
Notification.permission === 'denied' ? 'block' : 'none', |
||||||
|
}} |
||||||
|
> |
||||||
|
Browser notification permissions were denied. Please visit your |
||||||
|
browser settings to re-enable in order to get notifications. |
||||||
|
</div> |
||||||
|
<div |
||||||
|
class="form-check form-switch" |
||||||
|
style=${{ |
||||||
|
display: |
||||||
|
Notification.permission === 'denied' ? 'none' : 'block', |
||||||
|
}} |
||||||
|
> |
||||||
|
<div |
||||||
|
class="relative inline-block w-10 align-middle select-none transition duration-200 ease-in" |
||||||
|
> |
||||||
|
<input |
||||||
|
checked=${pushEnabled || browserPushPermissionsPending} |
||||||
|
disabled=${pushEnabled} |
||||||
|
type="checkbox" |
||||||
|
name="toggle" |
||||||
|
id="toggle" |
||||||
|
onchange=${handlePushToggleChange} |
||||||
|
class="toggle-checkbox absolute block w-8 h-8 rounded-full bg-white border-4 appearance-none cursor-pointer" |
||||||
|
/> |
||||||
|
<label |
||||||
|
for="toggle" |
||||||
|
style=${{ width: '50px' }} |
||||||
|
class="toggle-label block overflow-hidden h-8 rounded-full bg-gray-300 cursor-pointer" |
||||||
|
></label> |
||||||
|
</div> |
||||||
|
<div class="ml-8 text-xs inline-block text-gray-700"> |
||||||
|
${getBrowserPushButtonText()} |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<h2 class="text-slate-600 text-2xl mt-4 mb-2 font-semibold"> |
||||||
|
Browser Notifications |
||||||
|
</h2> |
||||||
|
<h2> |
||||||
|
Get notified right in the browser each time this stream goes live. |
||||||
|
</h2> |
||||||
|
</div> |
||||||
|
<div> |
||||||
|
<div |
||||||
|
class="text-sm mt-3" |
||||||
|
style=${{ display: !pushEnabled ? 'none' : 'block' }} |
||||||
|
> |
||||||
|
To disable push notifications from ${window.location.hostname} |
||||||
|
${' '} access your browser permissions for this site and turn off |
||||||
|
notifications. |
||||||
|
<div style=${{ 'margin-top': '5px' }}> |
||||||
|
<a href="">Learn more.</a> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<div |
||||||
|
id="browser-push-preview-box" |
||||||
|
class="w-full bg-white p-4 m-2 mt-4" |
||||||
|
style=${{ display: pushEnabled ? 'none' : 'block' }} |
||||||
|
> |
||||||
|
<div class="text-lg text-gray-700 ml-2 my-2"> |
||||||
|
${window.location.toString()} wants to |
||||||
|
</div> |
||||||
|
<div class="text-sm text-gray-700 my-2"> |
||||||
|
<svg |
||||||
|
class="mr-3" |
||||||
|
style=${{ display: 'inline-block' }} |
||||||
|
width="16" |
||||||
|
height="16" |
||||||
|
viewBox="0 0 16 16" |
||||||
|
fill="none" |
||||||
|
xmlns="http://www.w3.org/2000/svg" |
||||||
|
> |
||||||
|
<path |
||||||
|
d="M14 12.3333V13H2V12.3333L3.33333 11V7C3.33333 4.93333 4.68667 3.11333 6.66667 2.52667C6.66667 2.46 6.66667 2.4 6.66667 2.33333C6.66667 1.97971 6.80714 1.64057 7.05719 1.39052C7.30724 1.14048 7.64638 1 8 1C8.35362 1 8.69276 1.14048 8.94281 1.39052C9.19286 1.64057 9.33333 1.97971 9.33333 2.33333C9.33333 2.4 9.33333 2.46 9.33333 2.52667C11.3133 3.11333 12.6667 4.93333 12.6667 7V11L14 12.3333ZM9.33333 13.6667C9.33333 14.0203 9.19286 14.3594 8.94281 14.6095C8.69276 14.8595 8.35362 15 8 15C7.64638 15 7.30724 14.8595 7.05719 14.6095C6.80714 14.3594 6.66667 14.0203 6.66667 13.6667" |
||||||
|
fill="#676670" |
||||||
|
/> |
||||||
|
</svg> |
||||||
|
|
||||||
|
Show notifications |
||||||
|
</div> |
||||||
|
<div class="flex flex-row justify-end"> |
||||||
|
<button |
||||||
|
class="bg-blue-500 py-1 px-4 mr-4 rounded-sm text-white" |
||||||
|
onClick=${startBrowserPushRegistration} |
||||||
|
> |
||||||
|
Allow |
||||||
|
</button> |
||||||
|
<button |
||||||
|
class="bg-slate-200 py-1 px-4 rounded-sm text-gray-500 cursor-not-allowed" |
||||||
|
style=${{ |
||||||
|
'outline-width': 1, |
||||||
|
'outline-color': '#e2e8f0', |
||||||
|
'outline-style': 'solid', |
||||||
|
}} |
||||||
|
> |
||||||
|
Block |
||||||
|
</button> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<p |
||||||
|
class="text-gray-700 text-sm mt-6" |
||||||
|
style=${{ display: pushEnabled ? 'none' : 'block' }} |
||||||
|
> |
||||||
|
You'll need to allow your browser to receive notifications from |
||||||
|
${' '} ${streamName}, first. |
||||||
|
</p> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
|
||||||
|
<div |
||||||
|
id="follow-loading-spinner-container" |
||||||
|
style="display: ${loaderStyle}" |
||||||
|
> |
||||||
|
<img id="follow-loading-spinner" src="/img/loading.gif" /> |
||||||
|
<p class="text-gray-700 text-lg">Contacting your server.</p> |
||||||
|
<p class="text-gray-600 text-lg">Please wait...</p> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
`;
|
||||||
|
} |
||||||
|
|
||||||
|
export function NotifyButton({ serverName, onClick }) { |
||||||
|
const hasDisplayedNotificationModal = getLocalStorage( |
||||||
|
HAS_DISPLAYED_NOTIFICATION_MODAL_KEY |
||||||
|
); |
||||||
|
|
||||||
|
const hasPreviouslyDismissedAnnoyingPopup = getLocalStorage( |
||||||
|
USER_DISMISSED_ANNOYING_NOTIFICATION_POPUP_KEY |
||||||
|
); |
||||||
|
|
||||||
|
let visits = parseInt(getLocalStorage(USER_VISIT_COUNT_KEY)); |
||||||
|
if (isNaN(visits)) { |
||||||
|
visits = 0; |
||||||
|
} |
||||||
|
|
||||||
|
// Only show the annoying popup if the user has never opened the notification
|
||||||
|
// modal previously _and_ they've visited more than 3 times.
|
||||||
|
const [showPopup, setShowPopup] = useState( |
||||||
|
!hasPreviouslyDismissedAnnoyingPopup && |
||||||
|
!hasDisplayedNotificationModal && |
||||||
|
visits > 3 |
||||||
|
); |
||||||
|
|
||||||
|
const notifyAction = { |
||||||
|
color: 'rgba(219, 223, 231, 1)', |
||||||
|
description: `Never miss a stream! Get notified when ${serverName} goes live.`, |
||||||
|
icon: '/img/notification-bell.svg', |
||||||
|
openExternally: false, |
||||||
|
}; |
||||||
|
|
||||||
|
const buttonClicked = (e) => { |
||||||
|
onClick(e); |
||||||
|
setShowPopup(false); |
||||||
|
}; |
||||||
|
|
||||||
|
const notifyPopupDismissedClicked = () => { |
||||||
|
setShowPopup(false); |
||||||
|
setLocalStorage(USER_DISMISSED_ANNOYING_NOTIFICATION_POPUP_KEY, true); |
||||||
|
}; |
||||||
|
|
||||||
|
return html` |
||||||
|
<span id="notify-button-container" class="relative"> |
||||||
|
<div |
||||||
|
id="follow-button-popup" |
||||||
|
style=${{ display: showPopup ? 'block' : 'none' }} |
||||||
|
> |
||||||
|
<svg |
||||||
|
width="192" |
||||||
|
height="113" |
||||||
|
viewBox="0 0 192 113" |
||||||
|
fill="none" |
||||||
|
xmlns="http://www.w3.org/2000/svg" |
||||||
|
> |
||||||
|
<path |
||||||
|
fill-rule="evenodd" |
||||||
|
clip-rule="evenodd" |
||||||
|
d="M8 0C3.58172 0 0 3.58172 0 8V91C0 95.4183 3.58173 99 8 99H172L188.775 112.001C190.089 113.019 192 112.082 192 110.42V99V8C192 3.58172 188.418 0 184 0H8Z" |
||||||
|
fill="#6965F0" |
||||||
|
/> |
||||||
|
<text x="20" y="55" fill="white" font-size="13px"> |
||||||
|
Click and never miss |
||||||
|
</text> |
||||||
|
<text x="20" y="75" fill="white" font-size="13px"> |
||||||
|
future streams. |
||||||
|
</text> |
||||||
|
</svg> |
||||||
|
<button |
||||||
|
class="absolute" |
||||||
|
style=${{ top: '6px', right: '6px' }} |
||||||
|
onClick=${notifyPopupDismissedClicked} |
||||||
|
> |
||||||
|
<svg |
||||||
|
width="24" |
||||||
|
height="24" |
||||||
|
viewBox="0 0 24 24" |
||||||
|
fill="none" |
||||||
|
xmlns="http://www.w3.org/2000/svg" |
||||||
|
> |
||||||
|
<path |
||||||
|
d="M17.7071 7.70711C18.0976 7.31658 18.0976 6.68342 17.7071 6.29289C17.3166 5.90237 16.6834 5.90237 16.2929 6.29289L12 10.5858L7.70711 6.29289C7.31658 5.90237 6.68342 5.90237 6.29289 6.29289C5.90237 6.68342 5.90237 7.31658 6.29289 7.70711L10.5858 12L6.29289 16.2929C5.90237 16.6834 5.90237 17.3166 6.29289 17.7071C6.68342 18.0976 7.31658 18.0976 7.70711 17.7071L12 13.4142L16.2929 17.7071C16.6834 18.0976 17.3166 18.0976 17.7071 17.7071C18.0976 17.3166 18.0976 16.6834 17.7071 16.2929L13.4142 12L17.7071 7.70711Z" |
||||||
|
fill="#A5A3F6" |
||||||
|
/> |
||||||
|
</svg> |
||||||
|
</button> |
||||||
|
</div> |
||||||
|
<${ExternalActionButton} |
||||||
|
onClick=${buttonClicked} |
||||||
|
action=${notifyAction} |
||||||
|
/> |
||||||
|
</span> |
||||||
|
`;
|
||||||
|
} |
||||||
@ -0,0 +1,30 @@ |
|||||||
|
export async function registerWebPushNotifications(vapidPublicKey) { |
||||||
|
const registration = await navigator.serviceWorker.ready; |
||||||
|
let subscription = await registration.pushManager.getSubscription(); |
||||||
|
|
||||||
|
if (!subscription) { |
||||||
|
subscription = await registration.pushManager.subscribe({ |
||||||
|
userVisibleOnly: true, |
||||||
|
applicationServerKey: urlBase64ToUint8Array(vapidPublicKey), |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
return JSON.stringify(subscription); |
||||||
|
} |
||||||
|
|
||||||
|
export function isPushNotificationSupported() { |
||||||
|
return 'serviceWorker' in navigator && 'PushManager' in window; |
||||||
|
} |
||||||
|
|
||||||
|
function urlBase64ToUint8Array(base64String) { |
||||||
|
var padding = '='.repeat((4 - (base64String.length % 4)) % 4); |
||||||
|
var base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/'); |
||||||
|
|
||||||
|
var rawData = window.atob(base64); |
||||||
|
var outputArray = new Uint8Array(rawData.length); |
||||||
|
|
||||||
|
for (var i = 0; i < rawData.length; ++i) { |
||||||
|
outputArray[i] = rawData.charCodeAt(i); |
||||||
|
} |
||||||
|
return outputArray; |
||||||
|
} |
||||||
@ -0,0 +1,5 @@ |
|||||||
|
import { options as l$1 } from '../preact.js'; |
||||||
|
|
||||||
|
var t,u,r,o=0,i=[],c=l$1.__b,f=l$1.__r,e=l$1.diffed,a=l$1.__c,v=l$1.unmount;function m(t,r){l$1.__h&&l$1.__h(u,t,o||r),o=0;var i=u.__H||(u.__H={__:[],__h:[]});return t>=i.__.length&&i.__.push({}),i.__[t]}function l(n){return o=1,p(w,n)}function p(n,r,o){var i=m(t++,2);return i.t=n,i.__c||(i.__=[o?o(r):w(void 0,r),function(n){var t=i.t(i.__[0],n);i.__[0]!==t&&(i.__=[t,i.__[1]],i.__c.setState({}));}],i.__c=u),i.__}function y(r,o){var i=m(t++,3);!l$1.__s&&k(i.__H,o)&&(i.__=r,i.__H=o,u.__H.__h.push(i));}function h(r,o){var i=m(t++,4);!l$1.__s&&k(i.__H,o)&&(i.__=r,i.__H=o,u.__h.push(i));}function s(n){return o=5,d(function(){return {current:n}},[])}function _(n,t,u){o=6,h(function(){"function"==typeof n?n(t()):n&&(n.current=t());},null==u?u:u.concat(n));}function d(n,u){var r=m(t++,7);return k(r.__H,u)&&(r.__=n(),r.__H=u,r.__h=n),r.__}function A(n,t){return o=8,d(function(){return n},t)}function F(n){var r=u.context[n.__c],o=m(t++,9);return o.c=n,r?(null==o.__&&(o.__=!0,r.sub(u)),r.props.value):n.__}function T(t,u){l$1.useDebugValue&&l$1.useDebugValue(u?u(t):t);}function q(n){var r=m(t++,10),o=l();return r.__=n,u.componentDidCatch||(u.componentDidCatch=function(n){r.__&&r.__(n),o[1](n);}),[o[0],function(){o[1](void 0);}]}function x(){for(var t;t=i.shift();)if(t.__P)try{t.__H.__h.forEach(g),t.__H.__h.forEach(j),t.__H.__h=[];}catch(u){t.__H.__h=[],l$1.__e(u,t.__v);}}l$1.__b=function(n){u=null,c&&c(n);},l$1.__r=function(n){f&&f(n),t=0;var r=(u=n.__c).__H;r&&(r.__h.forEach(g),r.__h.forEach(j),r.__h=[]);},l$1.diffed=function(t){e&&e(t);var o=t.__c;o&&o.__H&&o.__H.__h.length&&(1!==i.push(o)&&r===l$1.requestAnimationFrame||((r=l$1.requestAnimationFrame)||function(n){var t,u=function(){clearTimeout(r),b&&cancelAnimationFrame(t),setTimeout(n);},r=setTimeout(u,100);b&&(t=requestAnimationFrame(u));})(x)),u=null;},l$1.__c=function(t,u){u.some(function(t){try{t.__h.forEach(g),t.__h=t.__h.filter(function(n){return !n.__||j(n)});}catch(r){u.some(function(n){n.__h&&(n.__h=[]);}),u=[],l$1.__e(r,t.__v);}}),a&&a(t,u);},l$1.unmount=function(t){v&&v(t);var u,r=t.__c;r&&r.__H&&(r.__H.__.forEach(function(n){try{g(n);}catch(n){u=n;}}),u&&l$1.__e(u,r.__v));};var b="function"==typeof requestAnimationFrame;function g(n){var t=u,r=n.__c;"function"==typeof r&&(n.__c=void 0,r()),u=t;}function j(n){var t=u;n.__c=n.__(),u=t;}function k(n,t){return !n||n.length!==t.length||t.some(function(t,u){return t!==n[u]})}function w(n,t){return "function"==typeof t?t(n):t} |
||||||
|
|
||||||
|
export { A as useCallback, F as useContext, T as useDebugValue, y as useEffect, q as useErrorBoundary, _ as useImperativeHandle, h as useLayoutEffect, d as useMemo, p as useReducer, s as useRef, l as useState }; |
||||||
@ -0,0 +1,24 @@ |
|||||||
|
self.addEventListener('activate', (event) => { |
||||||
|
console.log('Owncast service worker activated', event); |
||||||
|
}); |
||||||
|
|
||||||
|
self.addEventListener('install', (event) => { |
||||||
|
console.log('installing Owncast service worker...', event); |
||||||
|
}); |
||||||
|
|
||||||
|
self.addEventListener('push', (event) => { |
||||||
|
const data = JSON.parse(event.data.text()); |
||||||
|
const { title, body, icon, tag } = data; |
||||||
|
const options = { |
||||||
|
title: title || 'Live!', |
||||||
|
body: body || 'This live stream has started.', |
||||||
|
icon: icon || '/logo/external', |
||||||
|
tag: tag, |
||||||
|
}; |
||||||
|
|
||||||
|
event.waitUntil(self.registration.showNotification(options.title, options)); |
||||||
|
}); |
||||||
|
|
||||||
|
self.addEventListener('notificationclick', (event) => { |
||||||
|
clients.openWindow('/'); |
||||||
|
}); |
||||||
Loading…
Reference in new issue