Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sjrmanning/birdsong
:bird::musical_score: Swift WebSockets client for Phoenix Channels.
https://github.com/sjrmanning/birdsong
birdsong phoenix swift websocket-client
Last synced: 5 days ago
JSON representation
:bird::musical_score: Swift WebSockets client for Phoenix Channels.
- Host: GitHub
- URL: https://github.com/sjrmanning/birdsong
- Owner: sjrmanning
- License: mit
- Created: 2016-06-30T14:54:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-06T21:14:35.000Z (about 5 years ago)
- Last Synced: 2024-04-27T00:41:14.024Z (7 months ago)
- Topics: birdsong, phoenix, swift, websocket-client
- Language: Swift
- Homepage:
- Size: 118 KB
- Stars: 126
- Watchers: 7
- Forks: 37
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Birdsong
An iOS & OS X WebSockets client for use with [Phoenix](http://www.phoenixframework.org) [Channels](http://www.phoenixframework.org/docs/channels). Supports [Phoenix Presence](https://hexdocs.pm/phoenix/1.2.0/Phoenix.Presence.html)!
As of version 0.3.0, Birdsong requires Swift 3.0+. Please use version 0.2.2 if you need Swift 2.2 support.
Version 0.6 onwards supports Swift 4 using Starscream 3.0.
## Usage
```swift
import Birdsong…
// In your view controller / client
let socket = Socket(url: NSURL(string: "http://localhost:4000/socket/websocket")!, params: ["key": "secret"])…
socket.onConnect = {
let channel = self.socket.channel("rooms:some-topic", payload: ["user": "spartacus"])
channel.on("new:msg", callback: { message in
print("New message: \(message)")
})channel.join()?.receive("ok", callback: { payload in
print("Successfully joined: \(channel.topic)")
})channel.send("new:msg", payload: ["body": "Hello!"])
.receive("ok", callback: { response in
print("Sent a message!")
})
.receive("error", callback: { reason in
print("Message didn't send: \(reason)")
})// Presence support.
channel.presence.onStateChange = { newState in
// newState = dict where key = unique ID, value = array of metas.
print("New presence state: \(newState)")
}channel.presence.onJoin = { id, meta in
print("Join: user with id \(id) with meta entry: \(meta)")
}channel.presence.onLeave = { id, meta in
print("Leave: user with id \(id) with meta entry: \(meta)")
}
}socket.connect()
```## Example
To run the example project, clone the repo, and run `pod install` from the Example directory first, then use the Birdsong.xcworkspace Xcode workspace. The example is configured to work directly with the [Phoenix Chat Example](https://github.com/chrismccord/phoenix_chat_example). It simply connects to `localhost:4000`, joins the `rooms:lobby` channel, and logs each received message. The “Send message” button will send a message to the channel with an incrementing count.
## Installation
Available on CocoaPods:
```ruby
platform :ios, '9.0'
use_frameworks!pod 'Birdsong', '~> 0.6'
```If you need Swift 2.2 compatibility, please use version `0.2.2`.
## Author
Simon Manning — [sjrmanning@github](https://github.com/sjrmanning)
## License
Birdsong is available under the MIT license. See the LICENSE file for more info.