{"id":21564612,"url":"https://github.com/phoenixframework/websock","last_synced_at":"2025-04-05T12:03:28.505Z","repository":{"id":57680632,"uuid":"494185391","full_name":"phoenixframework/websock","owner":"phoenixframework","description":"A specification for Elixir apps to service WebSocket connections","archived":false,"fork":false,"pushed_at":"2023-12-30T16:53:56.000Z","size":58,"stargazers_count":79,"open_issues_count":0,"forks_count":5,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-29T11:04:59.229Z","etag":null,"topics":["elixir","elixir-lang","http-server","websocket"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/phoenixframework.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-19T18:23:47.000Z","updated_at":"2025-03-10T19:11:10.000Z","dependencies_parsed_at":"2023-12-30T17:52:32.515Z","dependency_job_id":"458b0e2d-74a7-434e-8940-666e2b97e9e5","html_url":"https://github.com/phoenixframework/websock","commit_stats":null,"previous_names":["mtrudel/sock"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phoenixframework%2Fwebsock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phoenixframework%2Fwebsock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phoenixframework%2Fwebsock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phoenixframework%2Fwebsock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phoenixframework","download_url":"https://codeload.github.com/phoenixframework/websock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332560,"owners_count":20921853,"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":["elixir","elixir-lang","http-server","websocket"],"created_at":"2024-11-24T10:16:33.577Z","updated_at":"2025-04-05T12:03:28.470Z","avatar_url":"https://github.com/phoenixframework.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebSock\n\n[![Build Status](https://github.com/phoenixframework/websock/workflows/Elixir%20CI/badge.svg)](https://github.com/phoenixframework/websock/actions)\n[![Docs](https://img.shields.io/badge/api-docs-green.svg?style=flat)](https://hexdocs.pm/websock)\n[![Hex.pm](https://img.shields.io/hexpm/v/websock.svg?style=flat\u0026color=blue)](https://hex.pm/packages/websock)\n\nWebSock is a specification for apps to service WebSocket connections; you can\nthink of it as 'Plug for WebSockets'. WebSock abstracts WebSocket support from\nservers such as [Bandit][] or [Cowboy][] and exposes a generic WebSocket API to\napplications. WebSocket-aware applications such as Phoenix can then be hosted\nwithin a supported web server simply by defining conformance to the `WebSock`\nbehaviour, in the same manner as how Plug conformance allows their HTTP aspects\nto be hosted within an arbitrary web server.\n\n\u003c!-- MDOC --\u003e\nDefines the `WebSock` behaviour which describes the functions that\nan application such as Phoenix must implement in order to be WebSock compliant;\nit is roughly the equivalent of the `Plug` interface, but for WebSocket\nconnections. It is commonly used in conjunction with the [websock_adapter][]\npackage which defines concrete adapters on top of [Bandit][] and [Cowboy][];\nthe two packages are separate to allow for servers which directly expose\n`WebSock` support to depend on just the behaviour. Users will almost always\nwant to depend on [websock_adapter][] instead of this package.\n\n## WebSocket Lifecycle\n\nWebSocket connections go through a well defined lifecycle mediated by `WebSock`\nand `WebSock.Adapters`:\n\n* **This step is outside the scope of the WebSock API**. A client will\n  attempt to Upgrade an HTTP connection to a WebSocket connection by passing\n  a specific set of headers in an HTTP request. An application may choose to\n  determine the feasibility of such an upgrade request however it pleases\n* An application will then signal an upgrade to be performed by calling\n  `WebSockAdapter.upgrade/4`, passing in the `Plug.Conn` to upgrade, along with\n  the `WebSock` compliant handler module which will handle the connection once\n  it is upgraded\n* The underlying server will then attempt to upgrade the HTTP connection to a WebSocket connection\n* Assuming the WebSocket connection is successfully negotiated, WebSock will\n  call `c:WebSock.init/1` on the configured handler to allow the application to perform any necessary\n  tasks now that the WebSocket connection is live\n* WebSock will call the configured handler's `c:WebSock.handle_in/2` callback\n  whenever data is received from the client\n* WebSock will call the configured handler's `c:WebSock.handle_info/2` callback\n  whenever other processes send messages to the handler process\n* The `WebSock` implementation can send data to the client by returning\n  a `{:push,...}` tuple from any of the above `handle_*` callbacks\n* At any time, `c:WebSock.terminate/2` (if implemented) may be called to indicate a close, error or\n  timeout condition\n\n[Cowboy]: https://github.com/ninenines/cowboy\n[Bandit]: https://github.com/mtrudel/bandit/\n[websock_adapter]: https://hex.pm/packages/websock_adapter\n\u003c!-- MDOC --\u003e\n\nFor more information, consult the [docs](https://hexdocs.pm/websock).\n\n## Installation\n\nThe websock package can be installed by adding `websock` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:websock, \"~\u003e 0.5\"}\n  ]\nend\n```\n\nDocumentation can be found at \u003chttps://hexdocs.pm/websock\u003e.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphoenixframework%2Fwebsock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphoenixframework%2Fwebsock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphoenixframework%2Fwebsock/lists"}