Created
December 25, 2015 09:31
-
-
Save korrio/86c82389bb16c79ef59c to your computer and use it in GitHub Desktop.
Test socketio connection and events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TestSocketIO.swift | |
// CandyChat | |
// | |
import Foundation | |
class TestSocket: NSObject { | |
let socket = SocketIOClient(socketURL: SOCKET_END_POINT, options: [.Log(true), .ForcePolling(false)]) | |
let replyMessage = "THIS IS SPARTANNNNN !!!!!!!!!!!!!!!" | |
func start() { | |
socket.on("Authenticate:Success") { (data, ack) -> Void in | |
debugPrint("AuthenticateSuccess") | |
self.socket.emit("JoinRoom", ["userId" :(1), "conversationId":(21)]) | |
self.socket.on("JoinRoom:Success", callback: { (data, ack) -> Void in | |
self.socket.emit("SendMessage", "Hello World!!!!!") | |
self.socket.on("SendMessage", callback: { (data, ack) -> Void in | |
debugPrint(data) | |
self.socket.emit("SendMessage", self.replyMessage) | |
}) | |
}) | |
self.socket.on("JoinRoom:Failure", callback: { (data, ack) -> Void in | |
debugPrint("Join Room Fail") | |
self.socket.disconnect() | |
}) | |
} | |
socket.on("Authenticate:Failure") { (data, ack ) -> Void in | |
debugPrint("AuthenticateFailure") | |
} | |
socket.on("connect") { (data, ack ) -> Void in | |
self.socket.emit("Authenticate", ["userId" : NSNumber(int: 1)]) | |
} | |
socket.connect() | |
} | |
func sendMessage(message:String!) { | |
self.socket.emit("SendMessage", message) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment