├── .gitignore ├── license.txt ├── readme.md ├── src ├── WebSocketClient.xml └── web_socket_client │ ├── ByteUtil.brs │ ├── Logger.brs │ ├── TlsUtil.brs │ ├── WebSocketClient.brs │ └── WebSocketClientTask.brs ├── test ├── .gitignore ├── bright_web_socket.json.example ├── components │ ├── Main.xml │ ├── WebSocketClient.xml │ └── web_socket_client │ │ ├── ByteUtil.brs │ │ ├── Logger.brs │ │ ├── TlsUtil.brs │ │ ├── WebSocketClient.brs │ │ └── WebSocketClientTask.brs ├── images │ ├── icon_focus_hd.png │ ├── icon_focus_sd.png │ ├── icon_side_hd.png │ ├── icon_side_sd.png │ ├── splash_fhd.jpg │ ├── splash_hd.jpg │ └── splash_sd.jpg ├── locale │ └── en_US │ │ ├── manifest │ │ └── translations.xml ├── manifest └── source │ └── Main.brs └── util ├── .gitignore ├── bulk_send ├── package.json ├── readme.md └── websocket_bulk_send_server.js └── echo ├── package.json ├── readme.md └── websocket_echo_server.js /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SuitestAutomation/BrightWebSocket/3d64524354e41b0b0a06841dc53e696e685e334a/.gitignore -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | BrightWebSocket - BrightScript websocket library 4 | Copyright © 2018 Rolando Islas 5 | Copyright © 2019 Suitest s.r.o. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | this software and associated documentation files (the “Software”), to deal in 9 | the Software without restriction, including without limitation the rights to 10 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 11 | of the Software, and to permit persons to whom the Software is furnished to do 12 | so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 23 | IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # BrightWebSocket 2 | 3 | A ScreneGraph websocket client library written in BrightScript. It is written to work in a separate task to not affect the main thread of the application. 4 | 5 | Many thanks to [rolandoislas/BrightWebSocket](https://github.com/rolandoislas/BrightWebSocket) who originally developed this library. 6 | 7 | # RFC 6455 8 | 9 | Follows [RFC 6455](https://tools.ietf.org/html/rfc6455) 10 | 11 | Notes: 12 | 13 | - Uses ASCII instead of UTF-8 for string operations 14 | - Does not support secure web sockets at this time 15 | 16 | # Installation 17 | 18 | The contents of the "src" folder in the repository's root should be placed 19 | in the "components" folder of a SceneGraph Roku app. 20 | 21 | # Using the Library 22 | 23 | The client follows the 24 | [HTML WebSocket interface](https://html.spec.whatwg.org/multipage/web-sockets.html#the-websocket-interface), 25 | modified to work with BrightScript conventions. Those familiar with browser 26 | (JavaScript) WebSocket implementations should find this client similar. 27 | 28 | Example: 29 | 30 | ```brightscript 31 | function init() as void 32 | m.ws = createObject("roSGNode", "WebSocketClient") 33 | m.ws.observeField("on_open", "on_open") 34 | m.ws.observeField("on_message", "on_message") 35 | m.ws.open = "ws://echo.websocket.org/" 36 | end function 37 | 38 | function on_open(event as object) as void 39 | m.ws.send = ["Hello World"] 40 | end function 41 | 42 | function on_message(event as object) as void 43 | print event.getData().message 44 | end function 45 | ``` 46 | 47 | For a working sample app see the "test" folder. Its contents can be zipped for 48 | installation as a dev channel on a Roku. 49 | 50 | # Additional information 51 | 52 | ## A differences between `roUrlTransfer` and `roStreamSocket` 53 | 54 | The `roUrltransfer` is sending larger data faster, Roku replied to this with the following: 55 | > Could be the difference between using curlLibrary and lower-level roStreamSocket implementation. The curl library is highly optimized as we use it for all the manifest handling in streaming. 56 | 57 | The `roStreamSocket` is separated into standalone thread but still is serialized, devices handling a higher amount of data could overload a buffer for some situations and data could send for longer. 58 | 59 | We approximately measured _230KB/s_ on **4660X - Roku Ultra** and _15KB/s_ on **3500EU - Roku Stick**. 60 | 61 | To send larger amount of data we suggest to use `roUrlTransfer` instead. Won't be improved/fixed in near future. 62 | 63 | # License 64 | 65 | The MIT License. See license.txt. 66 | -------------------------------------------------------------------------------- /src/WebSocketClient.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 |