1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

websocket: fix compilation of client.v

This commit is contained in:
Delyan Angelov 2020-05-28 01:38:54 +03:00
parent f6bdb3ae81
commit 04ca7efc0c

View File

@ -2,16 +2,13 @@ module main
import net.websocket import net.websocket
import eventbus import eventbus
import time
import readline import readline
import term
import benchmark
const ( const (
eb = eventbus.new() eb = eventbus.new()
) )
#flag -I $PWD #flag -I @VROOT/vlib/net/websocket/examples
#include "utf8.h" #include "utf8.h"
fn C.utf8_validate_str() bool fn C.utf8_validate_str() bool
@ -75,29 +72,25 @@ fn read_line(text string) string {
return output return output
} }
fn on_open(params eventbus.Params) { fn on_open(sender voidptr, ws &websocket.Client, x voidptr) {
println('websocket opened.') println('websocket opened.')
} }
fn on_message(params eventbus.Params) { fn on_message(sender voidptr, mut ws websocket.Client, msg websocket.Message) {
println('Message recieved. Sending it back.') println('Message recieved. Sending it back.')
typ := params.get_string('type') typ := msg.opcode
len := params.get_int('len') if typ == .text_frame {
mut ws := params.get_caller(websocket.Client{})
if typ == 'string' {
message := params.get_string('payload')
if ws.uri.ends_with('getCaseCount') { if ws.uri.ends_with('getCaseCount') {
num := message.int() num := int(msg.payload)
ws.close(1005, 'done') ws.close(1005, 'done')
start_tests(mut ws, num) start_tests(mut ws, num)
return return
} }
// println("Message: " + message) // println("Message: $msg")
ws.write(message.str, len, .text_frame) ws.write(msg.payload, msg.payload_len, .text_frame)
} else { } else {
println('Binary message.') println('Binary message.')
message := params.get_raw('payload') ws.write(msg.payload, msg.payload_len, .binary_frame)
ws.write(message, len, .binary_frame)
} }
} }
@ -118,10 +111,10 @@ fn start_tests(ws mut websocket.Client, num int) {
exit(0) exit(0)
} }
fn on_close(params eventbus.Params) { fn on_close(sender voidptr, ws &websocket.Client, x voidptr) {
println('websocket closed.') println('websocket closed.')
} }
fn on_error(params eventbus.Params) { fn on_error(sender voidptr, ws &websocket.Client, x voidptr) {
println('we have an error.') println('we have an error.')
} }