api server

pull/1/head
adb 4 years ago
parent 6849cf1a0f
commit 16afd7e156

@ -0,0 +1,33 @@
const ws = require('ws')
//WS server
const wss = new ws.Server({
port: 8081,
perMessageDeflate: {
zlibDeflateOptions: {
// See zlib defaults.
chunkSize: 1024,
memLevel: 7,
level: 3
},
zlibInflateOptions: {
chunkSize: 10 * 1024
},
// Other options settable:
clientNoContextTakeover: true, // Defaults to negotiated value.
serverNoContextTakeover: true, // Defaults to negotiated value.
serverMaxWindowBits: 10, // Defaults to negotiated value.
// Below options specified as default values.
concurrencyLimit: 10, // Limits zlib concurrency for perf.
threshold: 1024 // Size (in bytes) below which messages
// should not be compressed.
}
});
//WS handler
wss.on('connection', ws => {
ws.on('message', message => {
if (message.split(';', 2)[0] === 'message') wss.clients.forEach(clients => clients.send(message))
})
ws.send('websocket connected')
})

@ -44,6 +44,26 @@ export default {
newMessage
}
}
const wsurl = 'ws://127.0.0.1:8081'
const socket = new WebSocket(wsurl)
socket.onopen = () => {
socket.send('new session')
}
socket.onerror = (error) => {
console.log(`WebSocket error: ${error}`)
}
//socket.onclose = () => show_error('session timed out (refresh)')
/*socket.onmessage = (e) => {
console.log(e.data)
let msg = e.data.split(";", 2)
if (msg[0] === 'error') show_error(msg[1])
else if (msg[0] === 'surl') {
document.getElementById('surl-input').value = msg[1]
document.getElementById('surl-popup').style.display = 'block'
}
}*/
</script>
<style>

@ -1,7 +1,7 @@
<template>
<div class="newMessageBanner">
<textarea name="input" id="newMessageInput" class="newMessageInput" placeholder="type a message ..." type="text" v-model="content" />
<icon style="position: absolute; right: 1rem; bottom: 0.5rem;" ic="./sym/ic_send_white_24px.svg" />
<icon style="position: absolute; right: 1rem; bottom: 0.5rem;" ic="../sym/ic_send_white_24px.svg" />
</div>
</template>
@ -14,7 +14,7 @@ export default {
icon
},
props: {
content: String,
content: String
},
mounted() {
ResizeListener(document.getElementById("newMessageInput"));

Loading…
Cancel
Save