{"id":19869702,"url":"https://github.com/sockjs/websocket-multiplex","last_synced_at":"2025-04-05T22:06:20.138Z","repository":{"id":2743263,"uuid":"3739288","full_name":"sockjs/websocket-multiplex","owner":"sockjs","description":"A thin library for doing multiplexing on top of SockJS","archived":false,"fork":false,"pushed_at":"2021-06-08T10:54:02.000Z","size":15,"stargazers_count":160,"open_issues_count":12,"forks_count":37,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-04-15T14:09:04.127Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/sockjs/websocket-multiplex","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sockjs.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}},"created_at":"2012-03-16T13:47:41.000Z","updated_at":"2024-03-09T21:52:33.000Z","dependencies_parsed_at":"2022-09-13T21:50:32.956Z","dependency_job_id":null,"html_url":"https://github.com/sockjs/websocket-multiplex","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fwebsocket-multiplex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fwebsocket-multiplex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fwebsocket-multiplex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sockjs%2Fwebsocket-multiplex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sockjs","download_url":"https://codeload.github.com/sockjs/websocket-multiplex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406087,"owners_count":20933803,"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":[],"created_at":"2024-11-12T16:06:40.067Z","updated_at":"2025-04-05T22:06:20.114Z","avatar_url":"https://github.com/sockjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"WebSocket-multiplex\n===================\n\nWebSocket-multiplex is a small library on top of SockJS that allows\nyou to do multiplexing over a single SockJS connection.\n\nThe rationale for that is explained in details in the following blog\npost:\n\n  * https://www.rabbitmq.com/blog/2012/02/23/how-to-compose-apps-using-websockets/\n\n\nUsage from the browser\n----------------------\n\nOn the client side (browser) load library like that:\n\n    \u003cscript src=\"http://cdn.sockjs.org/websocket-multiplex-0.1.js\"\u003e\n      \u003c/script\u003e\n\nAlternatively, if you're using SSL:\n\n    \u003cscript src=\"https://d1fxtkz8shb9d2.cloudfront.net/websocket-multiplex-0.1.js\"\u003e\n      \u003c/script\u003e\n\nUsage example:\n\n```javascript\n    var sockjs_url = '/multiplex';\n    var sockjs = new SockJS(sockjs_url);\n\n    var multiplexer = new WebSocketMultiplex(sockjs);\n    var ann  = multiplexer.channel('ann');\n    var bob  = multiplexer.channel('bob');\n    var carl = multiplexer.channel('carl');\n```\n\nUsage from the node.js server\n-----------------------------\n\nOn the node.js server side, you can use npm to get the code:\n\n    npm install websocket-multiplex\n\nAnd a simplistic example:\n\n```javascript\n    var multiplex_server = require('websocket-multiplex');\n\n    // 1. Setup SockJS server\n    var service = sockjs.createServer();\n\n    // 2. Setup multiplexing\n    var multiplexer = new multiplex_server.MultiplexServer(service);\n\n    var ann = multiplexer.registerChannel('ann');\n    ann.on('connection', function(conn) {\n        conn.write('Ann says hi!');\n        conn.on('data', function(data) {\n            conn.write('Ann nods: ' + data);\n        });\n    });\n\n    // 3. Setup http server\n    var server = http.createServer();\n    sockjs_echo.installHandlers(server, {prefix:'/multiplex'});\n    var app = express.createServer();\n```\n\nFor a full-featured example see the\n[/examples/sockjs](https://github.com/sockjs/websocket-multiplex/tree/master/examples/sockjs)\ndirectory.\n\n\nProtocol\n--------\n\nThe underlying protocol is quite simple. Each message is a string consisting of\nthree comma separated parts: _type_, _topic_ and _payload_. There are\nthree valid message types:\n\n * `sub` - expresses a will to subscribe to a given _topic_.\n * `msg` - a message with _payload_ is being sent on a _topic_.\n * `uns` - a will to unsubscribe from a _topic_.\n\nInvalid messages like wrong unsubscriptions or publishes to a _topic_\nto which a client was not subscribed to are simply ignored.\n\nThis protocol assumes that both parties are generally willing to\ncooperate and that no party makes errors. All invalid\nmessages should be ignored.\n\nIt's important to notice that the namespace is shared between both\nparties. It is not a good idea to use the same topic names on the\nclient and on the server side because both parties may unsubscribe\nthe other from a topic.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsockjs%2Fwebsocket-multiplex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsockjs%2Fwebsocket-multiplex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsockjs%2Fwebsocket-multiplex/lists"}