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!'))
|
||||
return
|
||||
}
|
||||
const on_message = function (data) {
|
||||
console.log(['Client received message:', new TextDecoder().decode(data)])
|
||||
const on_message = function (event) {
|
||||
console.log(['Client received message:', new TextDecoder().decode(event.data)])
|
||||
return
|
||||
}
|
||||
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)
|
||||
```
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class FramerockUtils {
|
|||
return
|
||||
|
||||
}
|
||||
_setup_transport ({ on_open, on_close, on_message }) {
|
||||
_setup_transport ({ on_open, on_close, on_message, on_error }) {
|
||||
|
||||
console.debug('SETUP TRANSPORT')
|
||||
|
||||
|
@ -38,9 +38,9 @@ class FramerockUtils {
|
|||
const ws = this._ws
|
||||
ws.binaryType = 'arraybuffer'
|
||||
|
||||
const func_on_open = () => {
|
||||
const func_on_open = (event) => {
|
||||
console.debug('WS OPEN')
|
||||
on_open && on_open()
|
||||
on_open && on_open(event)
|
||||
return
|
||||
}
|
||||
const func_on_close = (event) => {
|
||||
|
@ -51,15 +51,16 @@ class FramerockUtils {
|
|||
const func_on_message = (event) => {
|
||||
console.debug('WS MESSAGE', event)
|
||||
if (on_message !== undefined) {
|
||||
on_message(event.data)
|
||||
on_message(event)
|
||||
}
|
||||
else {
|
||||
console.warn(['Unhandled message', event])
|
||||
}
|
||||
return
|
||||
}
|
||||
const func_on_error = () => {
|
||||
const func_on_error = (event) => {
|
||||
console.debug('WS ERROR')
|
||||
on_error && on_error(event)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue