| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import QtWebSockets 1.0
- import QtQuick 2.5
- Item {
- property alias tot_slides : socket.total_slides
- function isOpen(){
- return socket.status == WebSocket.Open;
- }
- function send_obj(obj) {
- socket.sendTextMessage(JSON.stringify(obj))
- }
- function set_preg() {
- send_obj({
- type: "initpreg"
- })
- }
- function unset_preg() {
- send_obj({
- type: "stoppreg"
- })
- }
- function prev_diapo() {
- var curImage = Math.max(item1.curImage - 1, 1)
- send_obj({
- type: "command",
- commandtype: "diapo",
- PDF: item1.curPDF,
- slide: curImage
- })
- }
- function next_diapo() {
- var curImage = Math.min(item1.curImage + 1, tot_slides)
- send_obj({
- type: "command",
- commandtype: "diapo",
- PDF: item1.curPDF,
- slide: curImage
- })
- }
- function clear_path() {
- send_obj({
- type: "command",
- commandtype: "clean"
- })
- canvas.clean_path()
- }
- function send_drawing(d) {
- send_obj({
- type: "command",
- commandtype: "draw",
- points: d,
- color: canvas.curColor
- })
- }
- WebSocket {
- property int total_slides: 5
- id: socket
- url: "wss://wscasa.especificosba.com.ar"
- active: true
- onTextMessageReceived: {
- var obj = JSON.parse(message)
- switch (obj.type) {
- case "diapo":
- canvas.clean_path()
- item1.curPDF = obj.PDF
- item1.curImage = obj.slide //automagically change_image
- if (obj.total_slides === undefined){
- console.log(obj);
- total_slides = 3
- } else {
- total_slides = obj.total_slides
- }
- break
- case "preg":
- item1.addPreg(obj.text)
- break
- case "deletepreg":
- item1.pregs = []
- break
- case "draw":
- break
- case "snowmix":
- break
- default:
- console.log(JSON.stringify(obj))
- }
- }
- onStatusChanged: {
- if (socket.status == WebSocket.Open) {
- wsStatus.text = qsTr("Conectado")
- } else {
- wsStatus.text = qsTr("Desconectado\nReconectando..")
- }
- }
- }
- Timer {
- interval: 800;
- running: true;
- repeat: true;
- onTriggered: {
- if (socket.status != WebSocket.Open){//Reconnect
- socket.active = false
- socket.active = true
- console.log("Connecting... " +Date().toString())
- }
- }
- }
- }
|