Coder Social home page Coder Social logo

birdsong's Introduction

Birdsong: Phoenix Channels WebSockets client for iOS & OS X

Birdsong

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

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

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. 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:

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

License

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

birdsong's People

Contributors

sjrmanning avatar eridbardhaj avatar codeofrobin avatar daltron avatar ankor avatar percygrunwald avatar

Watchers

James Cloos avatar Eoin O'Connell avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.