GithubHelp home page GithubHelp logo

carabina / swiftphoenixclient Goto Github PK

View Code? Open in Web Editor NEW

This project forked from davidstump/swiftphoenixclient

0.0 1.0 0.0 21.06 MB

Connect your Phoenix and iOS applications through WebSockets!

License: MIT License

Ruby 2.54% Swift 80.47% Objective-C 1.33% Shell 15.66%

swiftphoenixclient's Introduction

Swift Phoenix Client

Installation

CocoaPods

You can install SwiftPhoenix Client via CocoaPods by adding the following to your Podfile

pod "SwiftPhoenixClient"

and running pod install. From there you will need to add import SwiftPhoenixClient in any ViewController you want it to be used.

Usage

Using the Swift Phoenix Client is extremely easy (and familiar if have used the Phoenix JS client).

Socket Connection/Setup

The first thing you will need is to specify your Phoenix channel endpoint:

let socket = Phoenix.Socket(domainAndPort: "localhost:4000", path: "socket", transport: "websocket")

To specify a specific protocol you can use the prot argument:

let socket = Phoenix.Socket(domainAndPort: "localhost:4000", path: "socket", transport: "websocket", prot: "https")

Additionally, you will want to identify the topic of the channel we are joining:

let topic: String? = "rooms:lobby"

Joining Channel

Next we want to join our channel:

socket.join(topic: topic!, message: Phoenix.Message(subject: "status", body: "joining")) { channel in
  let chan = channel as! Phoenix.Channel

  chan.on("join") { message in
    // A new player has joined the game
  }
}

New Messages

We will want to handle new messages (or events) on the channel:

chan.on("new:msg") { message in
  let msg = message as! Phoenix.Message
  // Fire ze missiles.
}

Other Events

Just like above, you can handle any events that your Phoenix app is handling/broadcasting.

chan.on("user:entered") { message in
  // A new user has entered the game.
}
chan.on("error") { message in
  // Nuts
}

Example

Check out the ViewController in this repo for a brief example of a simple iOS chat application using the Phoenix Chat Example

Also check out both the Swift and Elixir channels on IRC.

Read the README_pods.md file to include this pod from a local copy (of a cloned repo). This may be necessary if you want to use the latest features, but they haven't been tagged and released to CocoaPods yet.

Note:

Currently works with Swift 2.0, Xcode 7.0, and Phoenix 1.0.1.

Tested with the Phoenix Chat Server example, upgraded to Phoenix 1.0.1.

License

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

swiftphoenixclient's People

Contributors

aaa70 avatar bbrock25 avatar davidstump avatar mudphone avatar sjrmanning avatar zhyu avatar

Watchers

 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.