Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Simple & Flexible Rails ActionCable client written in swift

License

Notifications You must be signed in to change notification settings

romankovt/SwiftyActionCable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Version License Platform

SwiftyActionCable

Super simple implementation of Rails ActionCable client written in Swift. Working on top of swift websocket library: https://github.com/tidwall/SwiftWebSocket

Example

// Initiate client with NSMutableURLRequest
let request = NSMutableURLRequest(URL: NSURL(string: "ws://localhost:3000/cable")!)
let client = ActionCableClient(mutableRequest: request)

// Create new channel
let exampleChannel = ActionChannel.init(name: "ExampleChannel")

// callback on message from server
exampleChannel.onMessage = { json in
  print(json)
  // send unsubscribe event to the server
  client.unsubscribeFrom(exampleChannel)
}

// callback on succesfull subsbscription
exampleChannel.onSubscribed  = {
    print("succesfully subscribed!")
}

// send subscribe to request to server and start listening
client.subscribeTo(exampleChannel)
exampleChannel.perform("say_hello")

Rails server example is here: https://github.com/tenshilg/ActionCableExample

Installation

SwiftyActionCable is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "SwiftyActionCable"

Dependencies

Author

Roman Kovtunenko, roman.kovtunenko@gmail.com

License

SwiftyActionCable is available under the MIT license. See the LICENSE file for more info.

About

Simple & Flexible Rails ActionCable client written in swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published