changing to animation queue
This commit is contained in:
parent
9ce7cb4b05
commit
22fe89a5f9
5 changed files with 92 additions and 127 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
import trio # type: ignore
|
import trio # type: ignore
|
||||||
import json
|
import json
|
||||||
import httpx
|
import httpx
|
||||||
|
from quart import g, jsonify, url_for, websocket
|
||||||
|
from http import HTTPStatus
|
||||||
|
|
||||||
from lnbits.core import db as core_db
|
from lnbits.core import db as core_db
|
||||||
from lnbits.core.models import Payment
|
from lnbits.core.models import Payment
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,8 @@
|
||||||
counter: 1,
|
counter: 1,
|
||||||
colours: ['teal', 'purple', 'indigo', 'pink', 'green'],
|
colours: ['teal', 'purple', 'indigo', 'pink', 'green'],
|
||||||
copilot: {},
|
copilot: {},
|
||||||
|
animQueue: [],
|
||||||
|
queue: false,
|
||||||
lnurl: ''
|
lnurl: ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -133,36 +135,24 @@
|
||||||
console.log('Something went wrong!')
|
console.log('Something went wrong!')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getPrice: function () {
|
launch(){
|
||||||
self = this
|
self = this
|
||||||
if (self.copilot.show_price != 'None') {
|
console.log("poo")
|
||||||
LNbits.api
|
LNbits.api
|
||||||
.request('GET', 'https://api.opennode.com/v1/rates', 'filla')
|
.request(
|
||||||
.then(function (response) {
|
'GET',
|
||||||
self.price = String(
|
'/copilot/api/v1/copilot/ws/' + self.copilot.id + '/launching/rocket')
|
||||||
new Intl.NumberFormat('en-US', {
|
.then(function (response1) {
|
||||||
style: 'currency',
|
self.$q.notify({
|
||||||
currency: 'USD'
|
color: 'green',
|
||||||
}).format(response.data.data.BTCUSD.USD)
|
message: 'Sent!'
|
||||||
)
|
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
})
|
||||||
LNbits.utils.notifyApiError(error)
|
.catch(err => {
|
||||||
})
|
LNbits.utils.notifyApiError(err)
|
||||||
}
|
})
|
||||||
},
|
},
|
||||||
animation1: function () {
|
|
||||||
self = this
|
|
||||||
setTimeout(function () {
|
|
||||||
setInterval(function () {
|
|
||||||
self.connection.send('')
|
|
||||||
self.counter++
|
|
||||||
if (self.counter % 20 === 0) {
|
|
||||||
self.getPrice()
|
|
||||||
}
|
|
||||||
}, 1000)
|
|
||||||
}, 2000)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.initCamera()
|
this.initCamera()
|
||||||
|
|
@ -171,47 +161,45 @@
|
||||||
self = this
|
self = this
|
||||||
self.copilot = JSON.parse(localStorage.getItem('copilot'))
|
self.copilot = JSON.parse(localStorage.getItem('copilot'))
|
||||||
|
|
||||||
LNbits.api
|
this.connectionBitStamp = new WebSocket('wss://ws.bitstamp.net')
|
||||||
.request(
|
|
||||||
'GET',
|
const obj = JSON.stringify({
|
||||||
'/copilot/api/v1/copilot/ws/' + self.copilot.id + '/launching/rocket',
|
event: "bts:subscribe",
|
||||||
'filla'
|
data: { channel: "live_trades_btcusd" },
|
||||||
)
|
|
||||||
.then(function (response) {})
|
|
||||||
.catch(function (error) {
|
|
||||||
LNbits.utils.notifyApiError(error)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.connectionBitStamp.onmessage = function (e) {
|
||||||
|
console.log(JSON.parse(e.data).data.price)
|
||||||
|
self.price = String(
|
||||||
|
new Intl.NumberFormat('en-US', {
|
||||||
|
style: 'currency',
|
||||||
|
currency: 'USD'
|
||||||
|
}).format(JSON.parse(e.data).data.price)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
this.connectionBitStamp.onopen = () => this.connectionBitStamp.send(obj)
|
||||||
|
|
||||||
if (location.protocol !== 'http:') {
|
if (location.protocol !== 'http:') {
|
||||||
this.connection = new WebSocket(
|
localUrl = 'wss://' +
|
||||||
'wss://' +
|
|
||||||
document.domain +
|
document.domain +
|
||||||
':' +
|
':' +
|
||||||
location.port +
|
location.port +
|
||||||
'/copilot/ws/compose/' +
|
'/copilot/ws/' + self.copilot.id + '/'
|
||||||
self.copilot.id
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
this.connection = new WebSocket(
|
localUrl = 'ws://' +
|
||||||
'ws://' +
|
|
||||||
document.domain +
|
document.domain +
|
||||||
':' +
|
':' +
|
||||||
location.port +
|
location.port +
|
||||||
'/copilot/ws/compose/' +
|
'/copilot/ws/' + self.copilot.id + '/'
|
||||||
self.copilot.id
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
this.connection = new WebSocket(localUrl)
|
||||||
|
this.connection.onmessage = function (e) {
|
||||||
|
console.log(e.data)
|
||||||
|
|
||||||
this.connection.addEventListener('open', function (event) {
|
res = e.data.split('-')
|
||||||
this.connection.send('')
|
if (res[0] != this.oldRes) {
|
||||||
})
|
this.oldRes = res[0]
|
||||||
var showNotif = this.showNotif
|
if (res[0] == 'rocket') {
|
||||||
|
|
||||||
this.connection.addEventListener('message', function (event) {
|
|
||||||
res = event.data.split('-')
|
|
||||||
console.log(res[1])
|
|
||||||
if (res[0] != this.oldRes) {
|
|
||||||
this.oldRes = res[0]
|
|
||||||
if (res[1] == 'rocket') {
|
|
||||||
document.getElementById('animations').style.width = '40%'
|
document.getElementById('animations').style.width = '40%'
|
||||||
document.getElementById('animations').src =
|
document.getElementById('animations').src =
|
||||||
'/copilot/static/rocket.gif'
|
'/copilot/static/rocket.gif'
|
||||||
|
|
@ -219,7 +207,7 @@
|
||||||
document.getElementById('animations').src = ''
|
document.getElementById('animations').src = ''
|
||||||
}, 5000)
|
}, 5000)
|
||||||
}
|
}
|
||||||
if (res[1] == 'face') {
|
if (res[0] == 'face') {
|
||||||
document.getElementById('animations').style.width = '35%'
|
document.getElementById('animations').style.width = '35%'
|
||||||
document.getElementById('animations').src =
|
document.getElementById('animations').src =
|
||||||
'/copilot/static/face.gif'
|
'/copilot/static/face.gif'
|
||||||
|
|
@ -227,7 +215,7 @@
|
||||||
document.getElementById('animations').src = ''
|
document.getElementById('animations').src = ''
|
||||||
}, 5000)
|
}, 5000)
|
||||||
}
|
}
|
||||||
if (res[1] == 'bitcoin') {
|
if (res[0] == 'bitcoin') {
|
||||||
document.getElementById('animations').style.width = '30%'
|
document.getElementById('animations').style.width = '30%'
|
||||||
document.getElementById('animations').src =
|
document.getElementById('animations').src =
|
||||||
'/copilot/static/bitcoin.gif'
|
'/copilot/static/bitcoin.gif'
|
||||||
|
|
@ -235,7 +223,7 @@
|
||||||
document.getElementById('animations').src = ''
|
document.getElementById('animations').src = ''
|
||||||
}, 5000)
|
}, 5000)
|
||||||
}
|
}
|
||||||
if (res[1] == 'confetti') {
|
if (res[0] == 'confetti') {
|
||||||
document.getElementById('animations').style.width = '100%'
|
document.getElementById('animations').style.width = '100%'
|
||||||
document.getElementById('animations').style.height = '100%'
|
document.getElementById('animations').style.height = '100%'
|
||||||
document.getElementById('animations').src =
|
document.getElementById('animations').src =
|
||||||
|
|
@ -245,7 +233,7 @@
|
||||||
document.getElementById('animations').style.height = ''
|
document.getElementById('animations').style.height = ''
|
||||||
}, 5000)
|
}, 5000)
|
||||||
}
|
}
|
||||||
if (res[1] == 'martijn') {
|
if (res[0] == 'martijn') {
|
||||||
document.getElementById('animations').style.width = '40%'
|
document.getElementById('animations').style.width = '40%'
|
||||||
document.getElementById('animations').src =
|
document.getElementById('animations').src =
|
||||||
'/copilot/static/martijn.gif'
|
'/copilot/static/martijn.gif'
|
||||||
|
|
@ -253,36 +241,29 @@
|
||||||
document.getElementById('animations').src = ''
|
document.getElementById('animations').src = ''
|
||||||
}, 5000)
|
}, 5000)
|
||||||
}
|
}
|
||||||
if (res[1] == 'rick') {
|
if (res[0] == 'rick') {
|
||||||
document.getElementById('animations').style.width = '40%'
|
this.animQueue.push({size: '40%', location: '/copilot/static/rick.gif'})
|
||||||
document.getElementById('animations').src =
|
|
||||||
'/copilot/static/rick.gif'
|
|
||||||
setTimeout(function () {
|
|
||||||
document.getElementById('animations').src = ''
|
|
||||||
}, 5000)
|
|
||||||
}
|
}
|
||||||
if (res[1] == 'true') {
|
if(self.queue == false){
|
||||||
|
for()
|
||||||
|
|
||||||
|
}
|
||||||
|
if (res[0] == 'true') {
|
||||||
document.getElementById('videoCamera').style.width = '20%'
|
document.getElementById('videoCamera').style.width = '20%'
|
||||||
self.initScreenShare()
|
self.initScreenShare()
|
||||||
}
|
}
|
||||||
if (res[1] == 'false') {
|
if (res[0] == 'false') {
|
||||||
document.getElementById('videoCamera').style.width = '100%'
|
document.getElementById('videoCamera').style.width = '100%'
|
||||||
document.getElementById('videoScreen').src = null
|
document.getElementById('videoScreen').src = null
|
||||||
}
|
}
|
||||||
console.log(res[2])
|
console.log(res[1])
|
||||||
if (res[2] != 'none') {
|
if (res[1] != 'none') {
|
||||||
showNotif(res[2])
|
showNotif(res[1])
|
||||||
}
|
}
|
||||||
|
this.oldRes = ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
this.connection.onopen = () => this.launch
|
||||||
|
|
||||||
this.connection.addEventListener('close', function (event) {
|
|
||||||
console.log('The connection has been closed')
|
|
||||||
})
|
|
||||||
var animation1 = this.animation1
|
|
||||||
animation1()
|
|
||||||
var getPrice = this.getPrice
|
|
||||||
getPrice()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -110,8 +110,9 @@
|
||||||
this.connection.send(String(url))
|
this.connection.send(String(url))
|
||||||
},
|
},
|
||||||
fullscreenToggle: function () {
|
fullscreenToggle: function () {
|
||||||
|
self = this
|
||||||
console.log(this.fullscreen_cam)
|
console.log(this.fullscreen_cam)
|
||||||
this.connection.send(String(this.fullscreen_cam))
|
self.animationBTN(String(this.fullscreen_cam))
|
||||||
if (this.fullscreen_cam) {
|
if (this.fullscreen_cam) {
|
||||||
this.fullscreen_cam = false
|
this.fullscreen_cam = false
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -121,49 +122,28 @@
|
||||||
openCompose: function () {
|
openCompose: function () {
|
||||||
let params =
|
let params =
|
||||||
'scrollbars=no, resizable=no,status=no,location=no,toolbar=no,menubar=no,width=1200,height=644,left=410,top=100'
|
'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: function (name) {
|
animationBTN: function (name) {
|
||||||
this.connection.send(name)
|
self = this
|
||||||
|
LNbits.api
|
||||||
|
.request(
|
||||||
|
'GET',
|
||||||
|
'/copilot/api/v1/copilot/ws/' + self.copilot.id + '/none/' + name)
|
||||||
|
.then(function (response1) {
|
||||||
|
self.$q.notify({
|
||||||
|
color: 'green',
|
||||||
|
message: 'Sent!'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
LNbits.utils.notifyApiError(err)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
stfu: function (name) {
|
|
||||||
this.connection.send('')
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
created: function () {
|
created: function () {
|
||||||
self = this
|
self = this
|
||||||
self.copilot = JSON.parse(localStorage.getItem('copilot'))
|
self.copilot = JSON.parse(localStorage.getItem('copilot'))
|
||||||
|
|
||||||
if (location.protocol == 'https:') {
|
|
||||||
console.log(location.protocol)
|
|
||||||
self.connection = new WebSocket(
|
|
||||||
'wss://' +
|
|
||||||
document.domain +
|
|
||||||
':' +
|
|
||||||
location.port +
|
|
||||||
'/copilot/ws/panel/' +
|
|
||||||
self.copilot.id
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
self.connection = new WebSocket(
|
|
||||||
'ws://' +
|
|
||||||
document.domain +
|
|
||||||
':' +
|
|
||||||
location.port +
|
|
||||||
'/copilot/ws/panel/' +
|
|
||||||
self.copilot.id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
self.connection.addEventListener('open', function (event) {})
|
|
||||||
|
|
||||||
self.connection.addEventListener('message', function (event) {
|
|
||||||
console.log('Message from server ', event.data)
|
|
||||||
})
|
|
||||||
|
|
||||||
self.connection.addEventListener('close', function (event) {
|
|
||||||
console.log('The connection has been closed')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ connected_websockets = defaultdict(set)
|
||||||
@copilot_ext.websocket("/ws/<id>/")
|
@copilot_ext.websocket("/ws/<id>/")
|
||||||
async def wss(id):
|
async def wss(id):
|
||||||
copilot = await get_copilot(id)
|
copilot = await get_copilot(id)
|
||||||
|
print(copilot)
|
||||||
if not copilot:
|
if not copilot:
|
||||||
return "", HTTPStatus.FORBIDDEN
|
return "", HTTPStatus.FORBIDDEN
|
||||||
global connected_websockets
|
global connected_websockets
|
||||||
|
|
@ -53,6 +54,5 @@ async def updater(copilot_id, data, comment):
|
||||||
copilot = await get_copilot(copilot_id)
|
copilot = await get_copilot(copilot_id)
|
||||||
if not copilot:
|
if not copilot:
|
||||||
return
|
return
|
||||||
print(connected_websockets)
|
|
||||||
for queue in connected_websockets[copilot_id]:
|
for queue in connected_websockets[copilot_id]:
|
||||||
await queue.send(f"{data + '-' + comment}")
|
await queue.send(f"{data + '-' + comment}")
|
||||||
|
|
@ -71,14 +71,17 @@ async def api_copilots_retrieve():
|
||||||
@api_check_wallet_key("invoice")
|
@api_check_wallet_key("invoice")
|
||||||
async def api_copilot_retrieve(copilot_id):
|
async def api_copilot_retrieve(copilot_id):
|
||||||
copilot = await get_copilot(copilot_id)
|
copilot = await get_copilot(copilot_id)
|
||||||
|
|
||||||
if not copilot:
|
if not copilot:
|
||||||
return jsonify({"message": "copilot does not exist"}), HTTPStatus.NOT_FOUND
|
return jsonify({"message": "copilot does not exist"}), HTTPStatus.NOT_FOUND
|
||||||
|
if not copilot.lnurl_toggle:
|
||||||
|
return (
|
||||||
|
jsonify({**copilot._asdict()}),
|
||||||
|
HTTPStatus.OK,
|
||||||
|
)
|
||||||
return (
|
return (
|
||||||
jsonify({**copilot._asdict(), **{"lnurl": copilot.lnurl}}),
|
jsonify({**copilot._asdict(), **{"lnurl": copilot.lnurl}}),
|
||||||
HTTPStatus.OK,
|
HTTPStatus.OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@copilot_ext.route("/api/v1/copilot/<copilot_id>", methods=["DELETE"])
|
@copilot_ext.route("/api/v1/copilot/<copilot_id>", methods=["DELETE"])
|
||||||
|
|
@ -97,7 +100,6 @@ async def api_copilot_delete(copilot_id):
|
||||||
@copilot_ext.route("/api/v1/copilot/ws/<copilot_id>/<comment>/<data>", methods=["GET"])
|
@copilot_ext.route("/api/v1/copilot/ws/<copilot_id>/<comment>/<data>", methods=["GET"])
|
||||||
async def api_copilot_ws_relay(copilot_id, comment, data):
|
async def api_copilot_ws_relay(copilot_id, comment, data):
|
||||||
copilot = await get_copilot(copilot_id)
|
copilot = await get_copilot(copilot_id)
|
||||||
|
|
||||||
if not copilot:
|
if not copilot:
|
||||||
return jsonify({"message": "copilot does not exist"}), HTTPStatus.NOT_FOUND
|
return jsonify({"message": "copilot does not exist"}), HTTPStatus.NOT_FOUND
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue