{"id":3100,"url":"https://github.com/danielrhodes/Swift-ActionCableClient","last_synced_at":"2025-08-03T13:31:52.664Z","repository":{"id":56901486,"uuid":"52783872","full_name":"danielrhodes/Swift-ActionCableClient","owner":"danielrhodes","description":"ActionCable is a new WebSocket server being released with Rails 5 which makes it easy to add real-time features to your app. This Swift client makes it dead-simple to connect with that server, abstracting away everything except what you need to get going.","archived":false,"fork":false,"pushed_at":"2022-09-23T12:26:18.000Z","size":512,"stargazers_count":165,"open_issues_count":29,"forks_count":128,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-04-24T19:25:46.635Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/danielrhodes.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":"2016-02-29T10:42:01.000Z","updated_at":"2023-09-07T01:17:14.000Z","dependencies_parsed_at":"2022-08-20T18:20:53.697Z","dependency_job_id":null,"html_url":"https://github.com/danielrhodes/Swift-ActionCableClient","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielrhodes%2FSwift-ActionCableClient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielrhodes%2FSwift-ActionCableClient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielrhodes%2FSwift-ActionCableClient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielrhodes%2FSwift-ActionCableClient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielrhodes","download_url":"https://codeload.github.com/danielrhodes/Swift-ActionCableClient/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228548567,"owners_count":17935221,"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-01-05T20:16:31.388Z","updated_at":"2024-12-07T01:30:32.912Z","avatar_url":"https://github.com/danielrhodes.png","language":"Swift","readme":"# ActionCableClient\n\n[![Version](https://img.shields.io/cocoapods/v/ActionCableClient.svg?style=flat)](http://cocoapods.org/pods/ActionCableClient)\n[![License](https://img.shields.io/cocoapods/l/ActionCableClient.svg?style=flat)](http://cocoapods.org/pods/ActionCableClient)\n[![Platform](https://img.shields.io/cocoapods/p/ActionCableClient.svg?style=flat)](http://cocoapods.org/pods/ActionCableClient)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\n[ActionCable](https://github.com/rails/rails/tree/master/actioncable) is a new WebSockets server being released with Rails 5 which makes it easy to add real-time features to your app. This Swift client makes it dead-simple to connect with that server, abstracting away everything except what you need to get going.\n\n## Installation\n\nTo install, simply:\n\n#### Cocoapods\n\nAdd the following line to your `Podfile` and run `pod install`\n\n```ruby\npod \"ActionCableClient\"\n```\n\n#### Carthage\n\nAdd the following to your `Cartfile` and run `carthage update` as normal.\n```ruby\ngithub \"danielrhodes/Swift-ActionCableClient\"\n```\n\n\n## Usage\n\n### Get Started \u0026 Connect\n\n```swift\nimport ActionCableClient\n\nself.client = ActionCableClient(url: URL(string: \"ws://domain.tld/cable\")!)\n\n// Connect!\nclient.connect()\n\nclient.onConnected = {\n    print(\"Connected!\")\n}\n\nclient.onDisconnected = {(error: Error?) in\n    print(\"Disconnected!\")\n}\n```\n\n### Subscribe to a Channel\n\n```swift\n// Create the Room Channel\nlet roomChannel = client.create(\"RoomChannel\") //The channel name must match the class name on the server\n\n// More advanced usage\nlet room_identifier = [\"room_id\" : identifier]\nlet roomChannel = client.create(\"RoomChannel\", identifier: room_identifier, autoSubscribe: true, bufferActions: true)\n\n```\n\n### Channel Callbacks\n\n```swift\n\n// Receive a message from the server. Typically a Dictionary.\nroomChannel.onReceive = { (JSON : Any?, error : ErrorType?) in\n    print(\"Received\", JSON, error)\n}\n\n// A channel has successfully been subscribed to.\nroomChannel.onSubscribed = {\n    print(\"Yay!\")\n}\n\n// A channel was unsubscribed, either manually or from a client disconnect.\nroomChannel.onUnsubscribed = {\n    print(\"Unsubscribed\")\n}\n\n// The attempt at subscribing to a channel was rejected by the server.\nroomChannel.onRejected = {\n    print(\"Rejected\")\n}\n\n```\n\n### Perform an Action on a Channel\n\n```swift\n// Send an action\nroomChannel[\"speak\"]([\"message\": \"Hello, World!\"])\n\n// Alternate less magical way:\nroomChannel.action(\"speak\", [\"message\": \"Hello, World!\"])\n\n// Note: The `speak` action must be defined already on the server\n```\n\n### Authorization \u0026 Headers\n\n```swift\n// ActionCable can be picky about origins, so if you\n// need it can be set here.\nclient.origin = \"https://domain.tld/\"\n\n// If you need any sort of authentication, you \n// will not have cookies like you do in the browser,\n// so set any headers here.\n//\n// These are available in the `Connection`\n// on the server side.\n\nclient.headers = [\n    \"Authorization\": \"sometoken\"\n]\n```\n\n### Misc\n\n```swift\n\nclient.onPing = {\n    \n}\n\n```\n\nFor more documentation, see the [wiki](https://github.com/danielrhodes/Swift-ActionCableClient/wiki/Documentation)\n\n## Requirements\n\n[Starscream](https://github.com/daltoniam/Starscream): The underlying WebSocket library.\n\n## Author\n\nDaniel Rhodes, rhodes.daniel@gmail.com\n\n## License\n\nActionCableClient is available under the MIT license. See the LICENSE file for more info.\n","funding_links":[],"categories":["WebSocket"],"sub_categories":["Web View","Other free courses"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielrhodes%2FSwift-ActionCableClient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielrhodes%2FSwift-ActionCableClient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielrhodes%2FSwift-ActionCableClient/lists"}