Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active May 27, 2019 19:44
Show Gist options
  • Save jirawatee/1d8750bdd93c22b1e621e26796fcf80e to your computer and use it in GitHub Desktop.
Save jirawatee/1d8750bdd93c22b1e621e26796fcf80e to your computer and use it in GitHub Desktop.
Live Score - UCL
exports.liveScore = functions.region(region).runWith(runtimeOpts)
.database.ref('ucl/score')
.onWrite(async (change, context) => {
let latest = change.after.val(); // ดึงค่าล่าสุดหลังการอัพเดทของ score ออกมา
// ดึงข้อมูลผู้ใช้ที่ subscribe ทั้งหมด
let userIds = await admin.database().ref('ucl/uid').once('value')
Object.keys(userIds.val()).forEach(userId => {
push(userId, latest, null) // ส่งข้อความแจ้งผลบอล
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment