SwiftyActionCable 0.1.1

SwiftyActionCable 0.1.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jul 2016
SPMSupports SPM

Maintained by Roman Kovtunenko.



 
Depends on:
SwiftyJSON~> 2.3.0
SwiftWebSocket~> 2.6.0
 

  • By
  • Roman Kovtunenko

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, [email protected]

License

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