{"id":16288514,"url":"https://github.com/jirihybek/unity-websocket-webgl","last_synced_at":"2025-04-07T12:06:44.909Z","repository":{"id":47499094,"uuid":"146045777","full_name":"jirihybek/unity-websocket-webgl","owner":"jirihybek","description":"Hybrid WebSocket implementation for Unity 3D with support of native and browser client.","archived":false,"fork":false,"pushed_at":"2023-09-24T13:04:56.000Z","size":22,"stargazers_count":254,"open_issues_count":12,"forks_count":63,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-31T10:08:23.359Z","etag":null,"topics":["unity3d","webgl","websocket"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jirihybek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2018-08-24T22:35:11.000Z","updated_at":"2025-03-26T15:07:58.000Z","dependencies_parsed_at":"2024-01-13T23:17:46.712Z","dependency_job_id":"cea41e72-109b-4f5e-8d78-ed7fce6ba9b8","html_url":"https://github.com/jirihybek/unity-websocket-webgl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jirihybek%2Funity-websocket-webgl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jirihybek%2Funity-websocket-webgl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jirihybek%2Funity-websocket-webgl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jirihybek%2Funity-websocket-webgl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jirihybek","download_url":"https://codeload.github.com/jirihybek/unity-websocket-webgl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648977,"owners_count":20972945,"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":["unity3d","webgl","websocket"],"created_at":"2024-10-10T19:48:32.369Z","updated_at":"2025-04-07T12:06:44.872Z","avatar_url":"https://github.com/jirihybek.png","language":"C#","funding_links":[],"categories":["NetWork"],"sub_categories":[],"readme":"# unity-websocket-webgl\n\n## Maintainers Wanted\n\nI've created this library as a Hobby project when I was experimenting with Unity. I haven't used Unity for over 2 years and I'm not able to maintain the repo. If you want to become a maintainer a keep this project running, send me an e-mail or create an issue. Thank you for understanding.\n\n---\n\nHybrid event-driven WebSocket implementation for Unity 3D.\n\nIt automatically compiles browser or native implementation based on project's target platform. Native implementation is using [WebSocketSharp](https://github.com/sta/websocket-sharp) library (must be downloaded separately - see below). For the browser implementation the custom emscripten JSLIB is used.\n\n**Warning:** WebSocket client is intended to support only binary messages. So if you want to send or receive string messages you must convert it to/from byte array in your code.\n\n## Downloading WebSocketSharp\n\nYou can get `WebSocketSharp.dll` from NuGet package manager. See [NuGet Gallery: websocket-sharp](http://www.nuget.org/packages/WebSocketSharp).\n\nLibrary can be installed manually. Just download the NuGet package. Then rename the file extension from `.nupkg` to `.zip` and extract it. Now you can copy `lib/websocket-sharp.dll` file to your Unity project into the `Assets/Plugins` directory.\n\nFor more info please visit official [WebSocketSharp GitHub repo](https://github.com/sta/websocket-sharp).\n\n## Installing plugin\n\nTo install this plugin just copy the contents of `Plugins` directory to your Unity project's `Assets/Plugins` directory.\n\n## Usage\n\nFor example usage see `Scripts/WebSocketDemo.cs` file. You can import it to your project and assign it to any GameObject. Then run your project and check the console.\n\n```csharp\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Text;\nusing UnityEngine;\n\n// Use plugin namespace\nusing HybridWebSocket;\n\npublic class WebSocketDemo : MonoBehaviour {\n\n    // Use this for initialization\n    void Start () {\n\n        // Create WebSocket instance\n        WebSocket ws = WebSocketFactory.CreateInstance(\"ws://echo.websocket.org\");\n\n        // Add OnOpen event listener\n        ws.OnOpen += () =\u003e\n        {\n            Debug.Log(\"WS connected!\");\n            Debug.Log(\"WS state: \" + ws.GetState().ToString());\n\n            ws.Send(Encoding.UTF8.GetBytes(\"Hello from Unity 3D!\"));\n        };\n\n        // Add OnMessage event listener\n        ws.OnMessage += (byte[] msg) =\u003e\n        {\n            Debug.Log(\"WS received message: \" + Encoding.UTF8.GetString(msg));\n\n            ws.Close();\n        };\n\n        // Add OnError event listener\n        ws.OnError += (string errMsg) =\u003e\n        {\n            Debug.Log(\"WS error: \" + errMsg);\n        };\n\n        // Add OnClose event listener\n        ws.OnClose += (WebSocketCloseCode code) =\u003e\n        {\n            Debug.Log(\"WS closed with code: \" + code.ToString());\n        };\n\n        // Connect to the server\n        ws.Connect();\n\n    }\n    \n    // Update is called once per frame\n    void Update () {\n        \n    }\n}\n```\n\n## Error Handling\n\nWhen any error occours during method call then the `WebSocketException` is thrown. Unified both for native and browser client so you can catch it in your C# code.\n\n## License Apache 2.0\n\nCopyright 2018 Jiri Hybek \u003cjiri@hybek.cz\u003e\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at\n\n```\nhttp://www.apache.org/licenses/LICENSE-2.0\n```\n\nUnless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjirihybek%2Funity-websocket-webgl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjirihybek%2Funity-websocket-webgl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjirihybek%2Funity-websocket-webgl/lists"}