standardized transport API on frontend (added on_error hook, on_message now receives full event)
This commit is contained in:
parent
2047803276
commit
f3e3707593
2 changed files with 8 additions and 8 deletions
|
@ -13,8 +13,8 @@ const on_open = function () {
|
||||||
FRAMEROCK_UTILS.transport_send_bytes(new TextEncoder().encode('Hello from client!'))
|
FRAMEROCK_UTILS.transport_send_bytes(new TextEncoder().encode('Hello from client!'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const on_message = function (data) {
|
const on_message = function (event) {
|
||||||
console.log(['Client received message:', new TextDecoder().decode(data)])
|
console.log(['Client received message:', new TextDecoder().decode(event.data)])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
FRAMEROCK_UTILS.setup_transport({ on_open, on_message })
|
FRAMEROCK_UTILS.setup_transport({ on_open, on_message })
|
||||||
|
@ -35,4 +35,3 @@ const config = {
|
||||||
|
|
||||||
async_run({ config, jsbuild_app_frontend, handle_transport_bytes }).then(()=>{}).catch(console.error)
|
async_run({ config, jsbuild_app_frontend, handle_transport_bytes }).then(()=>{}).catch(console.error)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ class FramerockUtils {
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
_setup_transport ({ on_open, on_close, on_message }) {
|
_setup_transport ({ on_open, on_close, on_message, on_error }) {
|
||||||
|
|
||||||
console.debug('SETUP TRANSPORT')
|
console.debug('SETUP TRANSPORT')
|
||||||
|
|
||||||
|
@ -38,9 +38,9 @@ class FramerockUtils {
|
||||||
const ws = this._ws
|
const ws = this._ws
|
||||||
ws.binaryType = 'arraybuffer'
|
ws.binaryType = 'arraybuffer'
|
||||||
|
|
||||||
const func_on_open = () => {
|
const func_on_open = (event) => {
|
||||||
console.debug('WS OPEN')
|
console.debug('WS OPEN')
|
||||||
on_open && on_open()
|
on_open && on_open(event)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const func_on_close = (event) => {
|
const func_on_close = (event) => {
|
||||||
|
@ -51,15 +51,16 @@ class FramerockUtils {
|
||||||
const func_on_message = (event) => {
|
const func_on_message = (event) => {
|
||||||
console.debug('WS MESSAGE', event)
|
console.debug('WS MESSAGE', event)
|
||||||
if (on_message !== undefined) {
|
if (on_message !== undefined) {
|
||||||
on_message(event.data)
|
on_message(event)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.warn(['Unhandled message', event])
|
console.warn(['Unhandled message', event])
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const func_on_error = () => {
|
const func_on_error = (event) => {
|
||||||
console.debug('WS ERROR')
|
console.debug('WS ERROR')
|
||||||
|
on_error && on_error(event)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue