i am working on chat application and facing some issues when i send the message , it sent succuessfully but my listeners donot fire and message cannot updates
i make a sperate class code is here please help
open class SocketIOManager {
public static let default = SocketIOManager()
private let manager: SocketManager
private let socket: SocketIOClient
socket.on("message") { (dataArray, socketAck) -> Void in
print(dataArray)
if let data = dataArray.first as? Data{
do{
let objc = try JSONDecoder.init().decode(GetChatConversation.self, from: data)
completionHandler(objc,nil)
}
catch let error{
return completionHandler(nil,error.localizedDescription)
}
}else{
completionHandler(nil,"Cannot cast Array of Any to Data")
}
}
}
func getStartTypingResponse(completionHandler: @escaping (String) -> Void) {
socket.on("typing") { (dataArray, socketAck) -> Void in
let swiftyJsonVar = JSON(dataArray as Any)
let messageDictionary = swiftyJsonVar.arrayValue[0]
i am working on chat application and facing some issues when i send the message , it sent succuessfully but my listeners donot fire and message cannot updates i make a sperate class code is here please help open class SocketIOManager {
public static let
default
= SocketIOManager() private let manager: SocketManager private let socket: SocketIOClientprivate init() { self.manager = SocketManager(socketURL: URL(string: "http://18.220.164.142:3000/")!, config: [.connectParams(["token": UserState.gettoken() ?? ""]), .compress,.log(true)]) self.socket = manager.defaultSocket }
//To check before any call is socket connected or not. func isSocketConnected() -> Bool{ if self.socket.status == .connected { return true } return false } //Connection with socket Handshaking func establishConnection(completionHandler: @escaping (Bool) -> Void) { socket.on(clientEvent: .connect) {data, ack in completionHandler(true) print("socket connected (data)") } socket.connect() } //Connection with socket Handshaking func establishConnection() { socket.connect()
} //Socket connection disconnect func closeConnection() { socket.disconnect() socket.off(clientEvent: .disconnect) }
//Socket Remove Listeners func removeListeners() { socket.off("message") socket.off("typing") socket.off("stopTyping") }
func getChatMessage(completionHandler: @escaping (GetChatConversation?,String?) -> Void) {
}
func getStartTypingResponse(completionHandler: @escaping (String) -> Void) { socket.on("typing") { (dataArray, socketAck) -> Void in let swiftyJsonVar = JSON(dataArray as Any) let messageDictionary = swiftyJsonVar.arrayValue[0]
}
func getStopTypingResponse(completionHandler: @escaping (String) -> Void) { socket.on("stopTyping") { (dataArray, socketAck) -> Void in let swiftyJsonVar = JSON(dataArray as Any) let messageDictionary = swiftyJsonVar.arrayValue[0]
}
func sendStartTypingMessage(conversationId: String) {
func sendStopTypingMessage(conversationId: String) {
}
func sendMessage(message: String, conversationId: String, completionHandler: @escaping (Bool) -> Void) {
} }