Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.1.0",
"short_description": "Video tips/animations/webhooks",
"tile": "/copilot/static/bitcoin-streaming.png",
"min_lnbits_version": "1.7.0-rc1",
"min_lnbits_version": "1.7.0",
"contributors": [
{
"name": "Ben Arc",
Expand Down
4 changes: 2 additions & 2 deletions static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ window.app = Vue.createApp({
this.getCopilot(copilot_id)
let params =
'scrollbars=no, resizable=no,status=no,location=no,toolbar=no,menubar=no,width=1200,height=644,left=410,top=100'
open('../copilot/cp/', '_blank', params)
open('/copilot/cp', '_blank', params)
},
openCopilotPanel(copilot_id) {
this.getCopilot(copilot_id)
let params =
'scrollbars=no, resizable=no,status=no,location=no,toolbar=no,menubar=no,width=300,height=450,left=10,top=400'
open('../copilot/pn/', '_blank', params)
open('/copilot/pn', '_blank', params)
},
deleteCopilotLink(copilotId) {
const link = _.findWhere(this.copilotLinks, {id: copilotId})
Expand Down
5 changes: 3 additions & 2 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from lnbits.core.services import websocket_updater
from lnbits.helpers import get_current_extension_name
from lnbits.tasks import register_invoice_listener
from lnbits.utils.safe_http import SafeHttpClient
from loguru import logger

from .crud import get_copilot
Expand Down Expand Up @@ -46,7 +47,7 @@ async def on_invoice_paid(payment: Payment) -> None:
data = copilot.animation3
webhook = copilot.animation1webhook
if webhook:
async with httpx.AsyncClient() as client:
async with SafeHttpClient(read_body=False) as client:
try:
r = await client.post(
webhook,
Expand All @@ -60,7 +61,7 @@ async def on_invoice_paid(payment: Payment) -> None:
)
r.raise_for_status()
payment.extra["wh_status"] = r.status_code
except (httpx.ConnectError, httpx.RequestError):
except (httpx.HTTPError, httpx.InvalidURL, ValueError):
payment.extra["wh_status"] = -1
finally:
await update_payment(payment)
Expand Down
33 changes: 22 additions & 11 deletions templates/copilot/compose.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<video
autoplay="true"
id="videoCamera"
muted
playsinline
@vue:mounted="initCamera($event.el)"
@vue:before-unmount="stopCamera($event.el)"
style="width: 100%"
class="fixed-bottom-right"
></video>
Expand All @@ -23,6 +27,7 @@
<div class="row">
<div class="col" style="max-width: 100px">
<lnbits-qrcode
v-if="fullChatLink"
:value="fullChatLink"
class="rounded-borders"
:show-buttons="false"
Expand Down Expand Up @@ -170,7 +175,8 @@
trollbox: [],
chatUrl: '',
chat_id: '',
chatLink: ''
chatLink: '',
fullChatLink: ''
}
},
computed: {
Expand All @@ -194,18 +200,24 @@
openURL(url) {
return Quasar.utils.openURL(url)
},
initCamera() {
const video = document.querySelector('#videoCamera')

if (navigator.mediaDevices.getUserMedia) {
initCamera(video) {
if (navigator.mediaDevices?.getUserMedia) {
navigator.mediaDevices
.getUserMedia({video: true})
.then(stream => {
if (!video.isConnected) {
stream.getTracks().forEach(track => track.stop())
return
}
video.srcObject = stream
})
.catch(LNbits.utils.notifyApiError)
}
},
stopCamera(video) {
video.srcObject?.getTracks().forEach(track => track.stop())
video.srcObject = null
},
initScreenShare() {
const video = document.querySelector('#videoScreen')
navigator.mediaDevices
Expand Down Expand Up @@ -251,8 +263,9 @@
pushAnim(content) {
document.getElementById('animations').style.width = content[0]
document.getElementById('animations').src = content[1]
if (content[2] != 'none') {
this.showNotif(content[2])
const comment = (content[2] || '').trim()
if (comment && comment !== 'none') {
this.showNotif(comment)
}
setTimeout(() => {
document.getElementById('animations').src = ''
Expand Down Expand Up @@ -299,9 +312,6 @@
.catch(LNbits.utils.notifyApiError)
}
},
mounted() {
this.initCamera()
},
created() {
$(() => {
$('#draggableqr').draggable()
Expand Down Expand Up @@ -361,7 +371,8 @@
this.connection = new WebSocket(localUrl)
this.connection.onmessage = e => {
console.log(e)
res = e.data.replace(' ', '').split('-')
const [event, ...commentParts] = e.data.split('-')
const res = [event.trim(), commentParts.join('-').trim()]
if (res[0] == 'rocket') {
addTask(['40%', '/copilot/static/rocket.gif', res[1]])
}
Expand Down
2 changes: 1 addition & 1 deletion templates/copilot/panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
openCompose() {
let params =
'scrollbars=no, resizable=no,status=no,location=no,toolbar=no,menubar=no,width=1200,height=644,left=410,top=100'
open('../cp/', 'test', params)
open('/copilot/cp', 'test', params)
},
animationBTN(name) {
LNbits.api
Expand Down
4 changes: 2 additions & 2 deletions views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ async def index(request: Request, user: User = Depends(check_user_exists)):
)


@copilot_generic_router.get("/cp/", response_class=HTMLResponse)
@copilot_generic_router.get("/cp", response_class=HTMLResponse)
async def compose(request: Request):
return copilot_renderer().TemplateResponse(
"copilot/compose.html", {"request": request}
)


@copilot_generic_router.get("/pn/", response_class=HTMLResponse)
@copilot_generic_router.get("/pn", response_class=HTMLResponse)
async def panel(request: Request):
return copilot_renderer().TemplateResponse(
"copilot/panel.html", {"request": request}
Expand Down
11 changes: 9 additions & 2 deletions views_lnurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@


@copilot_lnurl_router.get(
"/lnurl/{cp_id}", response_class=HTMLResponse, name="copilot.lnurl_response"
"/lnurl/{cp_id}",
response_class=HTMLResponse,
name="copilot.lnurl_response",
openapi_extra={"x-lnbits-local-lnurl": True},
)
async def lnurl_response(req: Request, cp_id: str):
cp = await get_copilot(cp_id)
Expand All @@ -35,7 +38,11 @@ async def lnurl_response(req: Request, cp_id: str):
return json.dumps(pay_response)


@copilot_lnurl_router.get("/lnurl/cb/{cp_id}", name="copilot.lnurl_callback")
@copilot_lnurl_router.get(
"/lnurl/cb/{cp_id}",
name="copilot.lnurl_callback",
openapi_extra={"x-lnbits-local-lnurl": True},
)
async def lnurl_callback(
cp_id: str, amount: str = Query(None), comment: str = Query(None)
):
Expand Down
Loading