aldwyish / SwiftPhoenixChannels

Phoenix Socket Client in Swift (WIP)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SwiftPhoenixChannels

Goal/Status

Phoenix Socket Client in Swift (WIP)

Very WIP - Building a Swift client for easily connecting to the WebSocket channels on your Phoenix project. For more information on setting up Phoenix Channels check out the repo.

Working on Beta6 Compatibility

Update: It's Alive! PhoenixChat

Installation

For the monent, until the Swift support in Cocoapods gets shored up, you can download the Phoenix.Socket.swift file from the main PhoenixChat directory of this project and include it in your application.

Dependencies

This relies on the Square teams SocketRocket which I added via CocoaPods.

Usage

The syntax is very similar to the Phoenix Channels syntax demonstrated on the main Phoenix Repo.

  1. You will need to instantiate the Phoenix::Socket class (inside of the ViewController in my example)

     let socket = Phoenix.Socket(endPoint: "ws://localhost:4000/ws")
    
  2. You can then join the socket with the socket.join method as such:

     socket.join("YOUR CHANNEL", topic: "YOUR TOPIC", message: YOUR_MESSAGE_DICTIONARY) { channel in 
     	// do stuffs 
     }
    
  3. Once joined, you can handle a variety of listeners such as your initial join, new messages and new users entering the channel.

     chan.on("join") { message in
    		// say hello
     }
    
     chan.on("new:message") { message in
    		// display new message
     }
    
     chan.on("user:entered") { message in
    		// welcome the new user
     }
    
  4. Do awesome things.

About

Phoenix Socket Client in Swift (WIP)


Languages

Language:D 56.9%Language:Swift 27.6%Language:Objective-C 14.5%Language:Shell 0.7%Language:Ruby 0.3%