{"id":13440271,"url":"https://github.com/actix/sockjs","last_synced_at":"2025-03-20T09:32:41.644Z","repository":{"id":57667844,"uuid":"106313376","full_name":"actix/sockjs","owner":"actix","description":"SockJS server for rust language","archived":true,"fork":false,"pushed_at":"2019-11-12T21:49:42.000Z","size":740,"stargazers_count":62,"open_issues_count":7,"forks_count":23,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-27T12:07:43.131Z","etag":null,"topics":["actix","rust","sockjs","websocket","websocket-server"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/actix.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-09T17:24:01.000Z","updated_at":"2023-09-17T04:38:42.000Z","dependencies_parsed_at":"2022-09-10T16:00:37.260Z","dependency_job_id":null,"html_url":"https://github.com/actix/sockjs","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actix%2Fsockjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actix%2Fsockjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actix%2Fsockjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/actix%2Fsockjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/actix","download_url":"https://codeload.github.com/actix/sockjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221745287,"owners_count":16873744,"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":["actix","rust","sockjs","websocket","websocket-server"],"created_at":"2024-07-31T03:01:21.228Z","updated_at":"2024-10-27T23:31:24.893Z","avatar_url":"https://github.com/actix.png","language":"Rust","funding_links":[],"categories":["Libraries","库","库 Libraries"],"sub_categories":["Web programming","网页编程","web编程 Web programming"],"readme":"# SockJS server [![Build Status](https://travis-ci.org/actix/sockjs.svg?branch=master)](https://travis-ci.org/actix/sockjs) [![codecov](https://codecov.io/gh/actix/sockjs/branch/master/graph/badge.svg)](https://codecov.io/gh/actix/sockjs) [![crates.io](http://meritbadge.herokuapp.com/sockjs)](https://crates.io/crates/sockjs)\n\n[SockJS](https://github.com/sockjs) server for [Actix framework](https://github.com/actix/actix).\n\n* [API Documentation](http://actix.github.io/sockjs/sockjs/)\n* Cargo package: [sockjs](https://crates.io/crates/sockjs)\n* SockJS is built with [Actix web](https://github.com/actix/actix-web)\n* Minimum supported Rust version: 1.21 or later\n\n---\n\nActix SockJS is licensed under the [Apache-2.0 license](http://opensource.org/licenses/APACHE-2.0).\n\n## Usage\n\nTo use `sockjs`, add this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nsockjs = \"0.2\"\n```\n\n## Supported transports\n\n* [websocket](http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10)\n* [xhr-streaming](https://secure.wikimedia.org/wikipedia/en/wiki/XMLHttpRequest#Cross-domain_requests)\n* [xhr-polling](https://secure.wikimedia.org/wikipedia/en/wiki/XMLHttpRequest#Cross-domain_requests)\n* [iframe-xhr-polling](https://developer.mozilla.org/en/DOM/window.postMessage)\n* iframe-eventsource ([EventSource](http://dev.w3.org/html5/eventsource/) used from an [iframe via\n  postMessage](https://developer.mozilla.org/en/DOM/window.postMessage\u003e))\n* iframe-htmlfile ([HtmlFile](http://cometdaily.com/2007/11/18/ie-activexhtmlfile-transport-part-ii/)\n  used from an [iframe via postMessage](https://developer.mozilla.org/en/DOM/window.postMessage\u003e).)\n* [jsonp-polling](https://secure.wikimedia.org/wikipedia/en/wiki/JSONP)\n\n\n## Simple chat example\n\n```rust\nextern crate actix;\nextern crate actix_web;\nextern crate sockjs;\n\nuse actix_web::*;\nuse actix::prelude::*;\nuse sockjs::{Message, Session, CloseReason, SockJSManager, SockJSContext};\n\nstruct Chat;\n\n/// `SockJSContext` context is required for sockjs session\nimpl Actor for Chat {\n    type Context = SockJSContext\u003cSelf\u003e;\n}\n\n/// Session has to implement `Default` trait\nimpl Default for Chat {\n    fn default() -\u003e Chat { Chat }\n}\n\n/// Sockjs session trait\nimpl Session for Chat {\n    fn opened(\u0026mut self, ctx: \u0026mut SockJSContext\u003cSelf\u003e) {\n        ctx.broadcast(\"Someone joined.\")\n    }\n    fn closed(\u0026mut self, ctx: \u0026mut SockJSContext\u003cSelf\u003e, _: CloseReason) {\n        ctx.broadcast(\"Someone left.\")\n    }\n}\n\n/// Session has to be able to handle `sockjs::Message` messages\nimpl Handler\u003cMessage\u003e for Chat {\n    type Result = ();\n\n    fn handle(\u0026mut self, msg: Message, ctx: \u0026mut SockJSContext\u003cSelf\u003e)\n    {\n        // broadcast message to all sessions\n        ctx.broadcast(msg);\n    }\n}\n\n\nfn main() {\n    let sys = actix::System::new(\"sockjs-chat\");\n\n    // SockJS sessions manager\n    let sm: Addr\u003cSyn, _\u003e = SockJSManager::\u003cChat\u003e::start_default();\n\n    HttpServer::new(move || {\n        let manager = sm.clone();\n        Application::new()\n            // register SockJS application\n            .handler(\n                \"/sockjs/\", sockjs::SockJS::new(manager.clone()))})\n        .bind(\"127.0.0.1:8080\").unwrap()\n        .start();\n\n    // let _ = sys.run();\n}\n```\n\n[Full chat example](https://github.com/actix/actix-sockjs/blob/master/examples/chat.rs)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factix%2Fsockjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Factix%2Fsockjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factix%2Fsockjs/lists"}