{"id":17147825,"url":"https://github.com/alexanderwe/websocketkit","last_synced_at":"2025-07-25T23:31:39.961Z","repository":{"id":63902019,"uuid":"304864670","full_name":"alexanderwe/WebSocketKit","owner":"alexanderwe","description":"Small utility around the Network framework and WebSockets","archived":false,"fork":false,"pushed_at":"2020-12-30T18:09:46.000Z","size":206,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-03-14T14:02:15.277Z","etag":null,"topics":["network","swift","swift5","websocket"],"latest_commit_sha":null,"homepage":"https://alexanderwe.github.io/WebSocketKit/","language":"Swift","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/alexanderwe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-17T11:41:53.000Z","updated_at":"2022-08-03T15:39:42.000Z","dependencies_parsed_at":"2023-01-14T13:00:59.143Z","dependency_job_id":null,"html_url":"https://github.com/alexanderwe/WebSocketKit","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/alexanderwe%2FWebSocketKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexanderwe%2FWebSocketKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexanderwe%2FWebSocketKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexanderwe%2FWebSocketKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexanderwe","download_url":"https://codeload.github.com/alexanderwe/WebSocketKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227629104,"owners_count":17796054,"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":["network","swift","swift5","websocket"],"created_at":"2024-10-14T21:26:11.017Z","updated_at":"2024-12-01T21:06:10.530Z","avatar_url":"https://github.com/alexanderwe.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebSocketKit\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/Swift-5.0-orange.svg?style=flat\" alt=\"Swift 5.0\"\u003e\n   \u003c/a\u003e\n   \u003ca href=\"https://github.com/apple/swift-package-manager\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg\" alt=\"SPM\"\u003e\n   \u003c/a\u003e\n\n   \u003ca href=\"https://github.com/alexanderwe/LoggingKit\"\u003e\n      \u003cimg src=\"https://github.com/alexanderwe/WebSocketKit/workflows/Main%20Branch%20CI/badge.svg\" alt=\"CI\"\u003e\n   \u003c/a\u003e\n   \u003c!-- \u003ca href=\"https://codecov.io/gh/alexanderwe/WebSocketKit\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/alexanderwe/WebSocketKit/branch/main/graph/badge.svg?token=zNmgmMp5zB\" alt=\"Code coverage\"\u003e\n   \u003c/a\u003e --\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    WebSocketKit is a small wrapper around the `Network` framework to work with websocket connections\n\u003c/p\u003e\n\n## Installation\n\n### Swift Package Manager\n\nTo integrate using Apple's [Swift Package Manager](https://swift.org/package-manager/), add the following as a dependency to your `Package.swift`:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/alexanderwe/WebSocketKit.git\", from: \"1.0.0\")\n]\n```\n\nAlternatively navigate to your Xcode project, select `Swift Packages` and click the `+` icon to search for `WebSocketKit`.\n\n### Manually\n\nIf you prefer not to use any of the aforementioned dependency managers, you can integrate `WebSocketKit` into your project manually. Simply drag the `Sources` Folder into your Xcode project.\n\n## Usage\n\nAt first import `WebSocketKit`\n\n```swift\nimport WebSocketKit\n```\n\nDefine a `WebsSocket` instance\n\n```swift\nlet websocket = WebsSocket(url: URL(string: \"wss://echo.websocket.org\")!)\n```\n\nIt also makes sense to create a instance of a class that conforms to the `WebSocketConnectionDelegate` in order to receive websocket events. Be aware that you also need to import the `Network` framework in order to have access to `NWProtocolWebSocket`.\n\n```swift\nimport Network\n\n\nclass WebSocketDelegate: WebSocketConnectionDelegate {\n\n    func webSocketDidConnect(connection: WebSocketConnection) {\n        print(\"WebSocket did connect\")\n    }\n\n    func websocketDidPrepare(connection: WebSocketConnection) {\n        print(\"WebSocket did prepare\")\n    }\n\n    func webSocketDidDisconnect(connection: WebSocketConnection, closeCode: NWProtocolWebSocket.CloseCode, reason: Data?) {\n        print(\"WebSocket did disconnect\")\n    }\n\n    func websocketDidCancel(connection: WebSocketConnection) {\n        print(\"WebSocket did cancel\")\n    }\n\n    func webSocketDidReceiveError(connection: WebSocketConnection, error: Error) {\n        print(\"WebSocket did receive error: \\(error)\")\n    }\n\n    func webSocketDidReceivePong(connection: WebSocketConnection) {\n        print(\"WebSocket did receive pong\")\n    }\n\n    func webSocketDidReceiveMessage(connection: WebSocketConnection, string: String) {\n        print(\"WebSocket did receive string message: \\(string)\")\n    }\n\n    func webSocketDidReceiveMessage(connection: WebSocketConnection, data: Data) {\n        print(\"WebSocket did receive data message\")\n    }\n}\n```\n\nSet an instance of the delegate instance to the `Websocket` instance and start listening for events\n\n```swift\nlet delegate = WebSocketDelegate()\nwebsocket.delegate = delegate\n\nwebsocket.connect() // Connects to the url specified in the initializer and listens for messages\n```\n\n### Custom headers\n\nOften it is necessary to attach custom headers to the connection. You can do so by specifying them in the initializer of the `Websocket` class.\n\n```swift\nlet websocket = Websocket(url: URL(string: \"wss://echo.websocket.org\")!,\n                          additionalHeaders: [\n                            \"Authorization:\": \"Bearer \u003csomeToken\u003e\",\n                            \"My-Custom-Header-Key:\": \"My-Custom-Header-Value\"\n                          ]\n)\n```\n\n## Contributing\n\nContributions are very welcome 🙌\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderwe%2Fwebsocketkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexanderwe%2Fwebsocketkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderwe%2Fwebsocketkit/lists"}