Skip to content

valery-bashkatov/Phoenix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phoenix

The Phoenix class provides a convenient mechanism to communicate with Phoenix Framework Channels.

Requirements

  • iOS 9.0+
  • Swift 4.1+

Dependencies

Installation

Carthage

To integrate Phoenix into your project using Carthage, specify it in your Cartfile:

github "valery-bashkatov/Phoenix" ~> 2.0.0

And then follow the instructions to install the framework and its dependencies.

Documentation

API Reference is located at http://valery-bashkatov.github.io/Phoenix.

Sample

import Phoenix

class RadioController: PhoenixListener {

    var phoenix: Phoenix

    init() {
        phoenix = Phoenix(url: "ws://sample.com/websocket")

        phoenix.connect()
        phoenix.addListener(self, forChannel: "radio", event: "new_message")

        let message = PhoenixMessage(topic: "radio", event: "ping")

		phoenix.send(message) {
			(message: PhoenixMessage, error: NSError?) in
            
    		guard error == nil else {
    			print(error)
    			return
    		}

	    	print(message)
	    	print(message.response!.payload)
		}
    }
    
    func phoenix(phoenix: Phoenix, didReceive message: PhoenixMessage) {
    	print("Received message: \(message)")
    }
    
    func phoenix(phoenix: Phoenix, didJoin topic: String) {
        print("Channel \(topic) joined")
    }
    
    func phoenix(phoenix: Phoenix, didClose topic: String, error: NSError?) {
        print("Channel \(topic) closed with error: \(error)")
    }
    
    func phoenixDidConnect(phoenix: Phoenix) {
        print("Phoenix connected")
    }
    
    func phoenixDidDisconnect(phoenix: Phoenix, error: NSError?) {
        print("Phoenix disconnected")
    }
}