From 5b792d4e3bb226ac7309aec394f3fc118e4c2d48 Mon Sep 17 00:00:00 2001 From: Soslan-Bek Date: Thu, 25 Mar 2021 10:46:23 +0300 Subject: [PATCH] Updated a example code --- README.md | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ab883f9f..3361ff48 100644 --- a/README.md +++ b/README.md @@ -7,28 +7,35 @@ Socket.IO-client for iOS/OS X. ```swift import SocketIO -let manager = SocketManager(socketURL: URL(string: "http://localhost:8080")!, config: [.log(true), .compress]) -let socket = manager.defaultSocket +class SocketIOManager{ + + let manager = SocketManager(socketURL: URL(string: "http://localhost:8080")!, config: [.log(true), .compress]) + + // MARK: - Init + init() { + let socket = manager.defaultSocket + + socket.on(clientEvent: .connect) { data, ack in + print("socket connected") + } -socket.on(clientEvent: .connect) {data, ack in - print("socket connected") -} + socket.on("currentAmount") { data, ack in + guard let cur = data[0] as? Double else { return } + + socket.emitWithAck("canUpdate", cur).timingOut(after: 0) { data in + if data.first as? String ?? "passed" == SocketAckValue.noAck { + // Handle ack timeout + } -socket.on("currentAmount") {data, ack in - guard let cur = data[0] as? Double else { return } - - socket.emitWithAck("canUpdate", cur).timingOut(after: 0) {data in - if data.first as? String ?? "passed" == SocketAckValue.noAck { - // Handle ack timeout + socket.emit("update", ["amount": cur + 2.50]) + } + + ack.with("Got your currentAmount", "dude") } - socket.emit("update", ["amount": cur + 2.50]) + socket.connect() } - - ack.with("Got your currentAmount", "dude") } - -socket.connect() ``` ## Features