diff --git a/src/snek/static/app.js b/src/snek/static/app.js index 1d56076..a2d45d4 100644 --- a/src/snek/static/app.js +++ b/src/snek/static/app.js @@ -148,9 +148,17 @@ class Chat extends EventHandler { const me = this return new Promise(async (resolve, reject) => { me._wait_connect = resolve - me._socket = new WebSocket(me._url) console.debug("Connecting..") + try { + me._socket = new WebSocket(me._url) + }catch(e){ + console.warning(e) + setTimeout(()=>{ + me.ensureConnection() + },1000) + } + me._socket.onconnect = () => { me._connected() me._wait_socket(me) @@ -210,6 +218,7 @@ class Socket extends EventHandler { isConnecting = null url = null connectPromises = [] + ensureTimer = null constructor() { super() this.url = window.location.hostname == 'localhost' ? 'ws://localhost:8081/rpc.ws' : 'wss://' + window.location.hostname + '/rpc.ws' @@ -236,6 +245,14 @@ class Socket extends EventHandler { return proxy } ensureConnection() { + if(this.ensureTimer) + return this.connect() + const me = this + this.ensureTimer = setInterval(()=>{ + if (me.isConnecting) + me.isConnecting = false + me.connect() + },5000) return this.connect() } generateUniqueId() { @@ -256,9 +273,11 @@ class Socket extends EventHandler { } return new Promise((resolve, reject) => { me.connectPromises.push(resolve) - + console.debug("Connecting..") + const ws = new WebSocket(this.url) - ws.onopen = (event) => { + + ws.onopen = (event) => { me.ws = ws me.isConnected = true me.isConnecting = false @@ -269,6 +288,9 @@ class Socket extends EventHandler { me.onClose() } + ws.onerror = (event)=>{ + me.onClose() + } me.connectPromises.forEach(resolve => { resolve(me) }) @@ -290,6 +312,7 @@ class Socket extends EventHandler { api.ws.send(JSON.stringify(data)) }) } + async call(method, ...args) { const call = { callId: this.generateUniqueId(), diff --git a/src/snek/static/base.css b/src/snek/static/base.css index 6fffd16..4f702b6 100644 --- a/src/snek/static/base.css +++ b/src/snek/static/base.css @@ -125,9 +125,9 @@ message-list { align-items: flex-start; margin-bottom: 15px; padding: 10px; - background: #222; + /*background: #222;*/ border-radius: 8px; - box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3); + /* box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);*/ } .chat-messages .message .avatar { diff --git a/src/snek/static/chat-window.js b/src/snek/static/chat-window.js index c5e3d61..0d008ee 100644 --- a/src/snek/static/chat-window.js +++ b/src/snek/static/chat-window.js @@ -22,6 +22,16 @@ class ChatWindowElement extends HTMLElement { const chatHeader = document.createElement("div") chatHeader.classList.add("chat-header") + let installPrompt = null + window.addEventListener("beforeinstallprompt", async(event) => { + event.preventDefault(); + installPrompt = event; + const result = await installPrompt.prompt() + console.info(result.outcome) + //installButton.removeAttribute("hidden"); + }); + + const chatTitle = document.createElement('h2') chatTitle.classList.add("chat-title") chatTitle.innerText = "Loading..." diff --git a/src/snek/templates/web.html b/src/snek/templates/web.html index 05ef008..c2b27ee 100644 --- a/src/snek/templates/web.html +++ b/src/snek/templates/web.html @@ -12,6 +12,8 @@ + +