{"id":20399847,"url":"https://github.com/kitware/wslink","last_synced_at":"2025-04-09T05:12:39.987Z","repository":{"id":21497132,"uuid":"90787393","full_name":"Kitware/wslink","owner":"Kitware","description":"Python/JavaScript library for communicating over WebSocket","archived":false,"fork":false,"pushed_at":"2024-09-16T21:08:47.000Z","size":2535,"stargazers_count":84,"open_issues_count":8,"forks_count":28,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-12-30T11:44:20.177Z","etag":null,"topics":["javascript-client","javascript-library","paraviewweb","python-library","python-server","rpc","rpc-call","vtk","websockets"],"latest_commit_sha":null,"homepage":"https://kitware.github.io/wslink/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kitware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://www.kitware.com/contact-us/"}},"created_at":"2017-05-09T20:08:23.000Z","updated_at":"2024-12-04T19:00:17.000Z","dependencies_parsed_at":"2024-05-10T14:43:32.805Z","dependency_job_id":"881b377f-b03a-4ead-8328-2ca57590a376","html_url":"https://github.com/Kitware/wslink","commit_stats":{"total_commits":207,"total_committers":20,"mean_commits":10.35,"dds":0.6811594202898551,"last_synced_commit":"bf724a5d20edb4da786d8989a01b8f49f7d71bcf"},"previous_names":[],"tags_count":69,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitware%2Fwslink","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitware%2Fwslink/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitware%2Fwslink/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kitware%2Fwslink/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kitware","download_url":"https://codeload.github.com/Kitware/wslink/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980844,"owners_count":21027808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript-client","javascript-library","paraviewweb","python-library","python-server","rpc","rpc-call","vtk","websockets"],"created_at":"2024-11-15T04:34:22.200Z","updated_at":"2025-04-09T05:12:39.966Z","avatar_url":"https://github.com/Kitware.png","language":"Python","readme":"# wslink\n\nWslink allows easy, bi-directional communication between a python server and a\njavascript or C++ client over a [websocket]. The client can make remote procedure\ncalls (RPC) to the server, and the server can publish messages to topics that\nthe client can subscribe to. The server can include binary attachments in\nthese messages, which are communicated as a binary websocket message, avoiding\nthe overhead of encoding and decoding.\n\n## RPC and publish/subscribe\n\nThe initial users of wslink driving its development are [VTK] and [ParaView].\nParaViewWeb and vtkWeb require:\n* RPC - a remote procedure call that can be fired by the client and return\n  sometime later with a response from the server, possibly an error.\n\n* Publish/subscribe - client can subscribe to a topic provided by the server,\n  possibly with a filter on the parts of interest. When the topic has updated\n  results, the server publishes them to the client, without further action on\n  the client's part.\n\nWslink is replacing a communication layer based on Autobahn WAMP, and so one\nof the goals is to be fairly compatible with WAMP, but simplify the interface\nto the point-to-point communication we actually use.\n\n## Examples\n\n* Set up a Python (3.3+) [virtualenv] using requirements.txt. Roughly:\n  - `cd wslink/python`\n  - `pip install virtualenv`\n  - `virtualenv runtime`\n  - `source runtime/Scripts/activate` (on Windows)\n  - `pip install -e .` (to use current wslink for development)\n* Install node.js 10+ for the javascript client\n* `cd wslink/js`\n* `npm run test`\n  - or:\n* `npm run build:example`\n* `cd ../tests/simple`\n* `python server/simple.py`\n  - starts a webserver at [localhost](http://localhost:8080/) with buttons to test RPC and pub/sub methods\n\n## Existing API\n\nExisting ParaViewWeb applications use these code patterns:\n* @exportRPC decorator in Python server code to register a method as being remotely callable\n* session.call(\"method.uri\", [args]) in the JavaScript client to make an RPC call. Usually wrapped as an object method so it appears to be a normal class method.\n* session.subscribe(\"method.uri\", callback) in JS client to initiate a pub/sub relationship.\n    * server calls self.publish(\"method.uri\", result) to push info back to the client\n\nWe don't support introspection or initial handshake about which methods are\nsupported - the client and server must be in sync.\n\nMessage format:\n```javascript\n{\nconst request = {\n    wslink: 1.0,\n    id: `rpc:${clientId}:${count}`,\n    method: 'myapp.render.window.image',\n    args: [],\n    kwargs: { w: 512, h: 512 }\n};\n\nconst response = {\n    wslink: 1.0,\n    id: `rpc:${clientId}:${count}`,\n    result: {}, // either result or error, not both\n    error: {}\n};\n\n// types used as prefix for id.\nconst types = ['rpc', 'publish', 'system'];\n}\n```\n\n```python\n# add a binary attachment\ndef getImage(self):\n    return {\n        \"size\": [512, 512],\n        \"blob\": session.addAttachment(memoryview(dataArray)),\n        \"mtime\": dataArray.getMTime()\n    }\n```\n\n### Binary attachments\n\nsession.addAttachment() takes binary data and stores it, returning a string key\nthat will be associated with the attachment. When a message is sent that uses\nthe attachment key, a text header message and a binary message is sent\nbeforehand with each attachment. The client will then substitute the binary\nbuffer for the string key when it receives the final message.\n\n### Subscribe\n\nThe client tracks subscriptions - the server currently blindly sends out\nmessages for any data it produces which might be subscribed to. This is not\nvery efficient - if the client notifies the server of a subscription, it can\nsend the data only when someone is listening. The ParaViewWeb app Visualizer\nmakes an RPC call after subscribing to tell the server to start publishing.\n\n### Handshake\n\nWhen the client initially connects, it sends a 'hello' to authenticate with\nthe server, so the server knows this client can handle the messages it sends,\nand the server can provide the client with a unique client ID - which the\nclient must embed in the rpc \"id\" field of its messages to the server.\n\n* The first message the client sends should be hello, with the secret key provided by its launcher.\n* Server authenticates the key, and responds with the client ID.\n* If the client sends the wrong key or no key, the server responds with an authentication error message.\n\n### Design\n\nMore extensive discussion in the [design](design.md) document.\n\n[ParaView]: https://www.paraview.org/web/\n[virtualenv]: https://virtualenv.pypa.io/\n[VTK]: http://www.vtk.org/\n[websocket]: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket\n","funding_links":["https://www.kitware.com/contact-us/"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkitware%2Fwslink","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkitware%2Fwslink","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkitware%2Fwslink/lists"}