Skip to content

BryanJBryce/Birdsong

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Birdsong: Phoenix Channels WebSockets client for iOS & OS X

Birdsong

An iOS & OS X WebSockets client for use with Phoenix Channels. Supports Phoenix Presence!

Usage

import Birdsong



let socket = Socket(url: NSURL(string: "http://localhost:4000/socket/websocket")!)

socket.onConnect = {
    let channel = self.socket.channel("rooms:some-topic", payload: ["user": "spartacus"])
    channel.on("new:msg", callback: { message in
        self.displayMessage(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)")
    }
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

Available on CocoaPods:

platform :ios, '9.0'
use_frameworks!

pod 'Birdsong', '~> 0.2'

Author

Simon Manning — sjrmanning@github

License

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

About

🐦🎼 Swift WebSockets client for Phoenix Channels.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 95.8%
  • Ruby 4.2%