Merge pull request #331 from shocknet/feature/stream-notification
notifications for OBS
This commit is contained in:
commit
81d0e56b16
7 changed files with 144 additions and 4 deletions
|
|
@ -1090,12 +1090,16 @@ const sendSpontaneousPayment = async (
|
|||
const { num_satoshis: decodedAmt } = await decodePayReq(encodedInvoice)
|
||||
|
||||
if (decodedAmt !== amount.toString()) {
|
||||
throw new Error('Invoice amount mismatch')
|
||||
throw new Error(
|
||||
`Invoice amount mismatch got: ${decodedAmt} expected: ${amount.toString()}`
|
||||
)
|
||||
}
|
||||
|
||||
// double check
|
||||
if (Number(decodedAmt) !== amount) {
|
||||
throw new Error('Invoice amount mismatch')
|
||||
throw new Error(
|
||||
`Invoice amount mismatch got:${decodedAmt} expected:${amount.toString()}`
|
||||
)
|
||||
}
|
||||
|
||||
logger.info('Will now send payment through lightning')
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ const Utils = require('../utils')
|
|||
const Gun = require('gun')
|
||||
const { selfContentToken, enrollContentTokens } = require('../../../seed')
|
||||
|
||||
const TipForwarder = require('../../../tipsCallback')
|
||||
|
||||
const getUser = () => require('../../Mediator').getUser()
|
||||
|
||||
/**
|
||||
|
|
@ -278,6 +280,13 @@ const listenerForAddr = (addr, SEA) => async (order, orderID) => {
|
|||
.get('postToTipCount')
|
||||
.get(postID)
|
||||
.set(null) // each item in the set is a tip
|
||||
|
||||
TipForwarder.notifySocketIfAny(
|
||||
postID,
|
||||
order.from,
|
||||
'TIPPED YOU',
|
||||
amt + ' sats'
|
||||
)
|
||||
break
|
||||
}
|
||||
case 'spontaneousPayment': {
|
||||
|
|
|
|||
30
services/tipsCallback.js
Normal file
30
services/tipsCallback.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
//@ts-nocheck TODO- fix types
|
||||
class TipsCB {
|
||||
listeners = {}
|
||||
|
||||
addSocket(postID,socket){
|
||||
console.log("subbing new socket for post: "+postID)
|
||||
|
||||
if(!this.listeners[postID]){
|
||||
this.listeners[postID] = []
|
||||
}
|
||||
this.listeners[postID].push(socket)
|
||||
}
|
||||
|
||||
notifySocketIfAny(postID,name,message,amount){
|
||||
if(!this.listeners[postID]){
|
||||
return
|
||||
}
|
||||
this.listeners[postID].forEach(socket => {
|
||||
if(!socket.connected){
|
||||
return
|
||||
}
|
||||
socket.emit("update",{
|
||||
name,message,amount
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const TipsForwarder = new TipsCB()
|
||||
module.exports = TipsForwarder
|
||||
85
src/index.html
Normal file
85
src/index.html
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<style>
|
||||
html,
|
||||
body{
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
.main{
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
|
||||
}
|
||||
.content{
|
||||
font-size: 4rem;
|
||||
background: #333333;
|
||||
padding: 1rem;
|
||||
border-radius: 0.5rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
#content-name{
|
||||
color: #FFFFFF;
|
||||
text-shadow: 0 0 10px #FFFFFF;
|
||||
margin:0
|
||||
}
|
||||
#content-message{
|
||||
color: #FFFFFF;
|
||||
text-shadow: 4px 3px 0 #7A7A7A;
|
||||
margin:0
|
||||
|
||||
}
|
||||
#content-amount{
|
||||
color: #FFFFFF;
|
||||
text-shadow: 0 -1px 4px #FFF, 0 -2px 10px #ff0, 0 -10px 20px #ff8000, 0 -18px 40px #F00;
|
||||
margin:0
|
||||
}
|
||||
.hide{
|
||||
display:none
|
||||
}
|
||||
</style>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="main">
|
||||
<div class="content hide">
|
||||
<p id="content-name">fdsigfudfsbigbfduigbdfb</p>
|
||||
<p id="content-message">JUST TIPPED YOU!</p>
|
||||
<p id="content-amount">100sats</p>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
console.log(location.origin)
|
||||
const queryString = window.location.search;
|
||||
const urlParams = new URLSearchParams(queryString);
|
||||
const postID = urlParams.get("postID")
|
||||
var socket = io(`${location.origin}/streams`);
|
||||
socket.emit("postID",postID)
|
||||
let latestTimeout = null
|
||||
socket.on("update",(update)=>{
|
||||
const name = document.querySelector("#content-name")
|
||||
name.innerHTML = update.name
|
||||
const message = document.querySelector("#content-message")
|
||||
message.innerHTML = update.message
|
||||
const amount = document.querySelector("#content-amount")
|
||||
amount.innerHTML = update.amount
|
||||
|
||||
const content = document.querySelector(".content")
|
||||
content.classList.remove("hide")
|
||||
clearTimeout(latestTimeout)
|
||||
latestTimeout = setTimeout(()=>{
|
||||
content.classList.add("hide")
|
||||
},5000)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -15,6 +15,7 @@ const isARealUsableNumber = require('lodash/isFinite')
|
|||
const Big = require('big.js')
|
||||
const size = require('lodash/size')
|
||||
const { range, flatten, evolve } = require('ramda')
|
||||
const path = require('path')
|
||||
|
||||
const getListPage = require('../utils/paginate')
|
||||
const auth = require('../services/auth/auth')
|
||||
|
|
@ -3271,4 +3272,7 @@ module.exports = async (
|
|||
})
|
||||
}
|
||||
})
|
||||
ap.get('/api/subscribeStream', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, '/index.html'))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ const { deepDecryptIfNeeded } = require('../services/gunDB/rpc')
|
|||
const GunEvents = require('../services/gunDB/contact-api/events')
|
||||
const SchemaManager = require('../services/schema')
|
||||
const { encryptedEmit, encryptedOn } = require('../utils/ECC/socket')
|
||||
const TipsForwarder = require('../services/tipsCallback')
|
||||
/**
|
||||
* @typedef {import('../services/gunDB/Mediator').SimpleSocket} SimpleSocket
|
||||
* @typedef {import('../services/gunDB/contact-api/SimpleGUN').ValidDataValue} ValidDataValue
|
||||
|
|
@ -685,6 +686,12 @@ module.exports = (
|
|||
emit('$error', e.message)
|
||||
}
|
||||
})
|
||||
io.of('streams').on('connect', socket => {
|
||||
console.log('a user connected')
|
||||
socket.on('postID', postID => {
|
||||
TipsForwarder.addSocket(postID, socket)
|
||||
})
|
||||
})
|
||||
|
||||
return io
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ module.exports = {
|
|||
"/api/lnd/wallet/status": true,
|
||||
"/api/lnd/auth": true,
|
||||
//
|
||||
"/api/gun/auth": true
|
||||
"/api/gun/auth": true,
|
||||
"/api/subscribeStream":true,
|
||||
},
|
||||
POST: {
|
||||
"/api/lnd/connect": true,
|
||||
|
|
@ -31,5 +32,5 @@ module.exports = {
|
|||
PUT: {},
|
||||
DELETE: {}
|
||||
},
|
||||
nonEncryptedRoutes: ['/api/security/exchangeKeys', "/api/encryption/exchange", '/healthz', '/ping', '/api/lnd/wallet/status', '/api/gun/auth']
|
||||
nonEncryptedRoutes: ['/api/security/exchangeKeys', "/api/encryption/exchange", '/healthz', '/ping', '/api/lnd/wallet/status', '/api/gun/auth',"/api/subscribeStream"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue