         return self
     }
 
+    public func onNewState(callback: Presence -> ()) -> Self {
+        presenceStateCallback = callback
+        return self
+    }
+
     // MARK: - States
 
     public enum State: String {

        return socket.send(message)
    }

    // MARK: - Raw events

    func received(response: Response) {

import Foundation

public class Channel {
    // MARK: - Convenience typealias

    public typealias Presence = [String: [String: AnyObject]]

    // MARK: - Properties

    public let topic: String
    public let params: Socket.Payload
    private let socket: Socket
    private(set) public var state: State

    private(set) public var presence: Presence

    private var callbacks: [String: (Response) -> ()] = [:]
    private var presenceStateCallback: (Presence -> ())?

    init(socket: Socket, topic: String, params: Socket.Payload = [:]) {
        self.socket = socket
        self.topic = topic
        self.params = params
        self.state = .Closed
        self.presence = [:]

        // Register presence handling.
        on("presence_state", callback: presenceState)
        on("presence_diff", callback: presenceDiff)
    }

    // MARK: - Control
