{"id":16711836,"url":"https://github.com/bburdette/websocket","last_synced_at":"2025-07-31T11:07:50.084Z","repository":{"id":57674836,"uuid":"215160181","full_name":"bburdette/websocket","owner":"bburdette","description":"Dead simple websockets implementation for elm.","archived":false,"fork":false,"pushed_at":"2020-03-16T21:05:52.000Z","size":14,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T05:51:06.910Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elm","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/bburdette.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":"2019-10-14T23:00:15.000Z","updated_at":"2022-10-09T01:11:21.000Z","dependencies_parsed_at":"2022-09-11T18:03:57.164Z","dependency_job_id":null,"html_url":"https://github.com/bburdette/websocket","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/bburdette/websocket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bburdette%2Fwebsocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bburdette%2Fwebsocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bburdette%2Fwebsocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bburdette%2Fwebsocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bburdette","download_url":"https://codeload.github.com/bburdette/websocket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bburdette%2Fwebsocket/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268026475,"owners_count":24183439,"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","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-10-12T20:26:44.439Z","updated_at":"2025-07-31T11:07:50.037Z","avatar_url":"https://github.com/bburdette.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebSocket\n\nDead simple websocket implementation for elm.\n\n\nThe WebSocket Elm module lets you encode and decode messages to pass to javascript.\n\nYou'll need some JS code to do the actual websocket sending and receiving. That code\nis right here:\n\n      \u003cscript\u003e\n        var mySockets = {};\n\n        function sendSocketCommand(wat) {\n          // console.log( \"ssc: \" +  JSON.stringify(wat, null, 4));\n          if (wat.cmd == \"connect\")\n          {\n            // console.log(\"connecting!\");\n            let socket = new WebSocket(wat.address, wat.protocol);\n            socket.onmessage = function (event) {\n              // console.log( \"onmessage: \" +  JSON.stringify(event.data, null, 4));\n              app.ports.receiveSocketMsg.send({ name : wat.name\n                                              , msg : \"data\"\n                                              , data : event.data} );\n            }\n            mySockets[wat.name] = socket;\n          }\n          else if (wat.cmd == \"send\")\n          {\n            // console.log(\"sending to socket: \" + wat.name );\n            mySockets[wat.name].send(wat.content);\n          }\n          else if (wat.cmd == \"close\")\n          {\n            // console.log(\"closing socket: \" + wat.name);\n            mySockets[wat.name].close();\n            delete mySockets[wat.name];\n          }\n        }\n      \u003c/script\u003e\n\nPut the above in your index.html or whatever.\n\nThen in your Main.elm (or wherever you define your ports), you'll want to make \nsome ports like this:\n\n    port receiveSocketMsg : (JD.Value -\u003e msg) -\u003e Sub msg\n    port sendSocketCommand : JE.Value -\u003e Cmd msg\n\nSee the WebSocket module for usage specifics. \n\nLastly, you'll need to set up the port function in javascript, as in this example (the subscribe line).\n\n      \u003cscript\u003e\n        var app = Elm.Main.init( { node: document.getElementById(\"elm\") });\n        if (document.getElementById(\"elm\"))\n        {\n          document.getElementById(\"elm\").innerText = 'This is a headless program, meaning there is nothing to show here.\\\\n\\\\nI started the program anyway though, and you can access it as `app` in the developer console.';\n        }\n        // Add this line!\n        app.ports.sendSocketCommand.subscribe(sendSocketCommand);\n      \u003c/script\u003e\n\nThere's no example code here yet, but [touchpage](https://github.com/bburdette/touchpage) uses websocket. Requires rust.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbburdette%2Fwebsocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbburdette%2Fwebsocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbburdette%2Fwebsocket/lists"}