diff --git a/vlib/net/websocket/LICENSE b/vlib/net/websocket/LICENSE deleted file mode 100644 index 8d6d593bcb..0000000000 --- a/vlib/net/websocket/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 Abdullah Atta - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/vlib/net/websocket/README.md b/vlib/net/websocket/README.md index 283647a258..25acafd487 100644 --- a/vlib/net/websocket/README.md +++ b/vlib/net/websocket/README.md @@ -1,5 +1,7 @@ # WebSockets Library for V +Originally located at [thecodrr/vws](https://github.com/thecodrr/vws) (contains example usage) + **This is still work-in-progress!** Heavily inspired (and used **very** liberally) from [cwebsockets](https://github.com/jeremyhahn/cwebsocket). @@ -16,13 +18,3 @@ The websockets library itself is ready and working (passes all tests of AutoBahn 1. SSL (either make the VSChannel work or OpenSSL) General code cleanup etc. is also needed. - -## Contributors - -Anyone and everyone is welcome to contribute. I don't have time for working on this completely but I will review and merge Pull Requests ASAP. So if anyone is interested, know that I am interested too. - -If anyone has any questions regarding design etc. please open an Issue or contact me on Discord. - -## Future Planning: - -This is supposed to be merged into V stdlib but it's not ready for that yet. As soon as it is, I will open a PR. diff --git a/vlib/net/websocket/ws/events.v b/vlib/net/websocket/events.v similarity index 98% rename from vlib/net/websocket/ws/events.v rename to vlib/net/websocket/events.v index d4b0fa521d..d09714d35e 100644 --- a/vlib/net/websocket/ws/events.v +++ b/vlib/net/websocket/events.v @@ -1,4 +1,4 @@ -module ws +module websocket import ( eventbus diff --git a/vlib/net/websocket/main.v b/vlib/net/websocket/examples/client.v similarity index 70% rename from vlib/net/websocket/main.v rename to vlib/net/websocket/examples/client.v index 5a30e05129..761295ac56 100644 --- a/vlib/net/websocket/main.v +++ b/vlib/net/websocket/examples/client.v @@ -1,7 +1,7 @@ module main import ( - ws + net.websocket eventbus time readline @@ -32,17 +32,17 @@ fn main(){ bm.stop() println( bm.total_message('remarks about the benchmark') ) } */ - mut websocket := ws.new("ws://localhost:9001/getCaseCount") + mut ws := websocket.new("ws://localhost:9001/getCaseCount") //defer { } - websocket.subscriber.subscribe("on_open", on_open) - websocket.subscriber.subscribe("on_message", on_message) - websocket.subscriber.subscribe("on_error", on_error) - websocket.subscriber.subscribe("on_close", on_close) + ws.subscriber.subscribe("on_open", on_open) + ws.subscriber.subscribe("on_message", on_message) + ws.subscriber.subscribe("on_error", on_error) + ws.subscriber.subscribe("on_close", on_close) //go - websocket.connect() - websocket.read() + ws.connect() + ws.read() //time.usleep(2000000) - //go websocket.listen() + //go ws.listen() //term.erase_clear() /* text := read_line("[client]:") if text == "close" { @@ -56,7 +56,7 @@ fn main(){ //ws.close(1005, "done") /* */ - //websocket.close(1005, "done") + //ws.close(1005, "done") //read_line("wait") } @@ -73,7 +73,7 @@ fn read_line(text string) string { } fn on_open(params eventbus.Params){ - println("Websocket opened.") + println("websocket opened.") } fn on_message(params eventbus.Params){ @@ -98,27 +98,27 @@ fn on_message(params eventbus.Params){ } } -fn start_tests(websocket mut ws.Client, num int) { +fn start_tests(ws mut ws.Client, num int) { for i := 1; i < num; i++ { println("Running test: " + i.str()) - websocket.uri = "ws://localhost:9001/runCase?case=${i.str()}&agent=vws/1.0a" - if websocket.connect() >= 0 { - websocket.listen() + ws.uri = "ws://localhost:9001/runCase?case=${i.str()}&agent=vws/1.0a" + if ws.connect() >= 0 { + ws.listen() } } println("Done!") - websocket.uri = "ws://localhost:9001/updateReports?agent=vws/1.0a" - if websocket.connect() >= 0 { - websocket.read() - websocket.close(1000, "disconnecting...") + ws.uri = "ws://localhost:9001/updateReports?agent=vws/1.0a" + if ws.connect() >= 0 { + ws.read() + ws.close(1000, "disconnecting...") } exit(0) } fn on_close(params eventbus.Params){ - println("Websocket closed.") + println("websocket closed.") } fn on_error(params eventbus.Params){ println("we have an error.") -} +} \ No newline at end of file diff --git a/vlib/net/websocket/utf8.h b/vlib/net/websocket/examples/utf8.h similarity index 100% rename from vlib/net/websocket/utf8.h rename to vlib/net/websocket/examples/utf8.h diff --git a/vlib/net/websocket/ws/handshake.v b/vlib/net/websocket/handshake.v similarity index 99% rename from vlib/net/websocket/ws/handshake.v rename to vlib/net/websocket/handshake.v index 6bfdd12c70..9450261b4c 100644 --- a/vlib/net/websocket/ws/handshake.v +++ b/vlib/net/websocket/handshake.v @@ -1,4 +1,4 @@ -module ws +module websocket fn (ws mut Client) read_handshake(seckey string){ l.d("reading handshake...") diff --git a/vlib/net/websocket/ws/io.v b/vlib/net/websocket/io.v similarity index 96% rename from vlib/net/websocket/ws/io.v rename to vlib/net/websocket/io.v index e344c2e918..4f67a10af4 100644 --- a/vlib/net/websocket/ws/io.v +++ b/vlib/net/websocket/io.v @@ -1,4 +1,4 @@ -module ws +module websocket fn C.write() int diff --git a/vlib/net/websocket/ws/ssl.v b/vlib/net/websocket/ssl.v similarity index 98% rename from vlib/net/websocket/ws/ssl.v rename to vlib/net/websocket/ssl.v index 23da7c8382..e9323c6eb0 100644 --- a/vlib/net/websocket/ws/ssl.v +++ b/vlib/net/websocket/ssl.v @@ -1,4 +1,4 @@ -module ws +module websocket #flag -lssl #include diff --git a/vlib/net/websocket/ws/utf8.v b/vlib/net/websocket/utf8.v similarity index 99% rename from vlib/net/websocket/ws/utf8.v rename to vlib/net/websocket/utf8.v index 9c4d0cc6d0..85395df6d8 100644 --- a/vlib/net/websocket/ws/utf8.v +++ b/vlib/net/websocket/utf8.v @@ -1,4 +1,4 @@ -module ws +module websocket pub fn utf8_validate_str(str string) bool { return utf8_validate(str.str, str.len) diff --git a/vlib/net/websocket/ws/utils.v b/vlib/net/websocket/utils.v similarity index 98% rename from vlib/net/websocket/ws/utils.v rename to vlib/net/websocket/utils.v index 2c1d9718e7..3863dec0d4 100644 --- a/vlib/net/websocket/ws/utils.v +++ b/vlib/net/websocket/utils.v @@ -1,4 +1,4 @@ -module ws +module websocket import ( time diff --git a/vlib/net/websocket/ws/ws.v b/vlib/net/websocket/ws.v similarity index 99% rename from vlib/net/websocket/ws/ws.v rename to vlib/net/websocket/ws.v index 619204bfb9..d048f6cbe9 100644 --- a/vlib/net/websocket/ws/ws.v +++ b/vlib/net/websocket/ws.v @@ -1,4 +1,4 @@ -module ws +module websocket import ( net