Live video on the AT Protocol
at v0.9.9 68 lines 1.8 kB view raw
1import admin from "firebase-admin"; 2import fs from "fs"; 3 4const serviceAccount = JSON.parse( 5 fs.readFileSync(`${process.env.AQKEYS}/firebase-admin.json`, "utf8"), 6); 7 8admin.initializeApp({ 9 credential: admin.credential.cert(serviceAccount), 10}); 11 12// const tokens = JSON.parse(process.argv.slice(2)) 13// console.log(tokens) 14// process.exit(0) 15 16// curl -H "Authorization: Bearer $SP_ADMIN" https://stream.place/api/notification 17 18const delay = (ms) => new Promise((r) => setTimeout(r, ms)); 19const blast = async (body) => { 20 const tokensRes = await fetch("https://stream.place/api/notification", { 21 headers: { 22 Authorization: `Bearer ${process.env.SP_ADMIN}`, 23 }, 24 }); 25 const fullTokens = await tokensRes.json(); 26 const tokens = fullTokens.map((t) => t.Token); 27 const notification = { 28 tokens: tokens, 29 notification: { 30 title: "🔴 @iame.li is LIVE!", 31 body: body, 32 // imageUrl: "https://my-cdn.com/app-logo.png", 33 }, 34 apns: { 35 headers: { 36 "apns-priority": "10", 37 }, 38 payload: { 39 aps: { 40 sound: "default", 41 }, 42 }, 43 }, 44 android: { 45 priority: "high", 46 notification: { 47 sound: "default", 48 }, 49 }, 50 priority: "high", 51 }; 52 console.log(JSON.stringify(notification.notification, null, 2)); 53 // console.log("launching in 5 sec") 54 // await delay(5000) 55 const res = await admin.messaging().sendEachForMulticast(notification); 56 console.log(JSON.stringify(res)); 57}; 58export default blast; 59 60import { resolve } from "path"; 61import { fileURLToPath } from "url"; 62 63const pathToThisFile = resolve(fileURLToPath(import.meta.url)); 64const pathPassedToNode = resolve(process.argv[1]); 65const isThisFileBeingRunViaCLI = pathToThisFile.includes(pathPassedToNode); 66if (isThisFileBeingRunViaCLI) { 67 blast(process.argv[2]); 68}