You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
Installation
To install, simply:
Cocoapods
Add the following line to your Podfile and run pod install
pod"ActionCableClient"
Carthage
Add the following to your Cartfile and run carthage update as normal.
// Create the Room Channel
letroomChannel= client.create("RoomChannel") //The channel name must match the class name on the server
// More advanced usage
letroom_identifier=["room_id": identifier]letroomChannel= client.create("RoomChannel", identifier: room_identifier, autoSubscribe:true, bufferActions:true)
Channel Callbacks
// Receive a message from the server. Typically a Dictionary.
roomChannel.onReceive ={(JSON :Any?, error :ErrorType?)inprint("Received", JSON, error)}
// A channel has successfully been subscribed to.
roomChannel.onSubscribed ={print("Yay!")}
// A channel was unsubscribed, either manually or from a client disconnect.
roomChannel.onUnsubscribed ={print("Unsubscribed")}
// The attempt at subscribing to a channel was rejected by the server.
roomChannel.onRejected ={print("Rejected")}
Perform an Action on a Channel
// Send an action
roomChannel["speak"](["message":"Hello, World!"])
// Alternate less magical way:
roomChannel.action("speak",["message":"Hello, World!"])
// Note: The `speak` action must be defined already on the server
Authorization & Headers
// ActionCable can be picky about origins, so if you
// need it can be set here.
client.origin ="https://domain.tld/"
// If you need any sort of authentication, you
// will not have cookies like you do in the browser,
// so set any headers here.
//
// These are available in the `Connection`
// on the server side.
client.headers =["Authorization":"sometoken"]
ActionCableClient is available under the MIT license. See the LICENSE file for more info.
About
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.