mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
websocket: move library files to root of module
This commit is contained in:
40
vlib/net/websocket/events.v
Normal file
40
vlib/net/websocket/events.v
Normal file
@@ -0,0 +1,40 @@
|
||||
module websocket
|
||||
|
||||
import (
|
||||
eventbus
|
||||
)
|
||||
|
||||
fn (ws &Client) send_message_event(msg Message){
|
||||
mut params := eventbus.Params{}
|
||||
mut typ := ""
|
||||
if msg.opcode == .text_frame {
|
||||
params.put_string("payload", string(byteptr(msg.payload)))
|
||||
typ = 'string'
|
||||
} else if msg.opcode == .binary_frame {
|
||||
params.put_custom("payload", "binary", msg.payload)
|
||||
typ = 'binary'
|
||||
}
|
||||
params.put_string("type", typ)
|
||||
params.put_int("len", msg.payload_len)
|
||||
ws.eb.publish("on_message", params, ws)
|
||||
l.d("sending on_message event")
|
||||
}
|
||||
|
||||
fn (ws &Client) send_error_event(err string) {
|
||||
mut params := eventbus.Params{}
|
||||
params.put_string("error", err)
|
||||
ws.eb.publish("on_error", params, ws)
|
||||
l.d("sending on_error event")
|
||||
}
|
||||
|
||||
fn (ws &Client) send_close_event() {
|
||||
params := eventbus.Params{}
|
||||
ws.eb.publish("on_close", params, ws)
|
||||
l.d("sending on_close event")
|
||||
}
|
||||
|
||||
fn (ws &Client) send_open_event() {
|
||||
params := eventbus.Params{}
|
||||
ws.eb.publish("on_open", params, ws)
|
||||
l.d("sending on_open event")
|
||||
}
|
||||
Reference in New Issue
Block a user