SwiftyActionCable 0.1.1

SwiftyActionCable 0.1.1

测试已测试
Lang语言 SwiftSwift
许可证 MIT
释放最后释放2016年7月
SPM支持SPM

Roman Kovtunenko维护。



 
依赖
SwiftyJSON~> 2.3.0
SwiftWebSocket~> 2.6.0
 

  • Roman Kovtunenko

SwiftyActionCable

Swift编写的Rails ActionCable客户端的超简单实现。基于swift websocket库:[https://github.com/tidwall/SwiftWebSocket](https://github.com/tidwall/SwiftWebSocket)

示例

// Initiate client with NSMutableURLRequest
let request = NSMutableURLRequest(URL: NSURL(string: "ws://: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服务器示例在此:[https://github.com/tenshilg/ActionCableExample](https://github.com/tenshilg/ActionCableExample)

安装

SwiftyActionCable可通过CocoaPods获取。要安装它,只需将以下行添加到Podfile中

pod "SwiftyActionCable"

依赖项

  • SwiftyJSON [https://github.com/SwiftyJSON/SwiftyJSON](https://github.com/SwiftyJSON/SwiftyJSON)
  • WebSockets [https://github.com/tidwall/SwiftWebSocket](https://github.com/tidwall/SwiftWebSocket)

作者

Roman Kovtunenko,[保护邮箱地址](#)

许可证

SwiftyActionCable可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。