 		onSocketOpen?()
 	}
 
-	private func webSocketDidReceiveMessage(message: String?) {
-
-	}
-	
 	private func webSocketDidReceiveMessage(messageData: NSData) {
-		webSocketDidReceiveMessage(String(data: messageData, encoding: NSUTF8StringEncoding))
+		do {
+			let message: Message = try Unbox(messageData)
+
+			for channel in channels where channel.topic == message.topic {
+
+				channel.triggerEvent(
+					message.event,
+					ref: message.ref,
+					payload: message.payload
+				)
+			}
+
+			onSocketMessage?(result: .Success(message))
+		} catch let error as NSError {
+			webSocketDidError(error)
+			onSocketMessage?(result: .Failure(error))
+		}
 	}
 	
 	private func webSocketDidClose(code code: Int, reason: String, wasClean: Bool) {

	@objc private func sendHeartBeat() {
		let message = Message(
			topic: "phoenix",
			event: "heartbeat"
		)

		try! push(message)

import Foundation
import SwiftWebSocket
import Wrap
import Unbox

public typealias SocketState = SwiftWebSocket.WebSocketReadyState

