{"id":18100004,"url":"https://github.com/kevinlang/plug_socket","last_synced_at":"2025-04-13T16:08:46.675Z","repository":{"id":57535214,"uuid":"399972650","full_name":"kevinlang/plug_socket","owner":"kevinlang","description":"Add Cowboy websockets to your Plug.Router easily.","archived":false,"fork":false,"pushed_at":"2021-08-25T22:36:30.000Z","size":9,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T16:08:42.926Z","etag":null,"topics":["cowboy","plug","sockets","websocket","websockets"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/plug_socket","language":"Elixir","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/kevinlang.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":"2021-08-25T22:29:42.000Z","updated_at":"2023-12-04T18:59:55.000Z","dependencies_parsed_at":"2022-09-26T18:21:51.187Z","dependency_job_id":null,"html_url":"https://github.com/kevinlang/plug_socket","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/kevinlang%2Fplug_socket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinlang%2Fplug_socket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinlang%2Fplug_socket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinlang%2Fplug_socket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinlang","download_url":"https://codeload.github.com/kevinlang/plug_socket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248741205,"owners_count":21154255,"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":["cowboy","plug","sockets","websocket","websockets"],"created_at":"2024-10-31T21:12:40.157Z","updated_at":"2025-04-13T16:08:46.649Z","avatar_url":"https://github.com/kevinlang.png","language":"Elixir","readme":"# PlugSocket\n\n[Online Documentation](https://hexdocs.pm/plug_socket).\n\n\u003c!-- MDOC !--\u003e\n\nEnables a convenient way of specifying sockets within your `Plug.Router`.\n\n`PlugSocket` is not a `Plug` itself. Instead, it provides a convenient\nDSL for specifying any sockets as part of your `Plug.Router` that can\nlater be added to the `Plug.Cowboy` adapter.\n\nBecause it is not tied to `Plug` or `Plug.Router` directly, it can also be\nused independently of Plug, if one wants to just use `Cowboy` directly.\n\n## Usage\n\nAdd the `PlugSocket` to your router. E.g.,\n\n    defmodule MyApp.Router do\n      use Plug.Router\n\n      socket \"/my-socket\", MyApp.MySocket\n\n      plug :match\n      plug :dispatch\n\n      get \"/\" do\n        send_resp(conn, 200, \"hello world\")\n      end\n    end\n\nEach `module` you pass to `socket/3` must implement the `:cowboy_websocket_handler`\nbehavior. Note that because `socket/3` is _not_ a `Plug`, it is not part of any\nplug pipeline you create in your router.\n\nNext, you need to ensure our websockets are added to the `Cowboy` dispatch:\n\n    def start(_type, _args) do\n      children = [\n        {Plug.Cowboy, scheme: :http, plug: MyApp.Router, options: [\n          dispatch: PlugSocket.plug_cowboy_dispatch(MyApp.Router)\n        ]}\n      ]\n\n      opts = [strategy: :one_for_one, name: MyApp.Supervisor]\n      Supervisor.start_link(children, opts)\n    end\n\nThis registers your sockets with the Cowboy dispatcher. You can now\nstart the application and navigate to your socket path in your client\nand see that it is now routing!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinlang%2Fplug_socket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinlang%2Fplug_socket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinlang%2Fplug_socket/lists"}