Skip to content

Polling #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Mar 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8bebc3c
start work on adding polling
nuclearace Mar 4, 2015
5cc42be
start moving websocket stuff to socketengine
nuclearace Mar 4, 2015
7e05496
move more things to socketengine. reconnecting broken
nuclearace Mar 4, 2015
16fd043
fix reconnect
nuclearace Mar 4, 2015
6e4aa4e
work on polling heartbeat
nuclearace Mar 4, 2015
7f22dc8
send connect event on polling connect
nuclearace Mar 4, 2015
574e9d5
start work on parsing polling messages
nuclearace Mar 4, 2015
3088bd8
handle binary
nuclearace Mar 4, 2015
2e80b94
Fixes. Sending doesn't work on polling, namespaces broken
nuclearace Mar 4, 2015
2205cfb
fix EXE_BAD_ACCESS when compiling with -O with swift 1.1
nuclearace Mar 4, 2015
4925c00
work on xhr polling sending
nuclearace Mar 4, 2015
95d50ec
remove old method
nuclearace Mar 4, 2015
346edc7
Better handle moving between polling and websockets. Sending binary o…
nuclearace Mar 5, 2015
b295561
non-namespace polling seems to work, needs more testing
nuclearace Mar 5, 2015
1f1ba60
fix namespaces
nuclearace Mar 5, 2015
63aed1c
tweaks
nuclearace Mar 5, 2015
68a0f8d
gotta go fast
nuclearace Mar 5, 2015
1a63088
readme
nuclearace Mar 5, 2015
543a3c8
add toggle for polling only
nuclearace Mar 5, 2015
8312d28
update READEME.md
nuclearace Mar 5, 2015
a1e3232
update README.md
nuclearace Mar 5, 2015
5d545f9
Merge branch 'polling' of https://github.com/nuclearace/Socket.IO-Cli…
nuclearace Mar 5, 2015
829992f
send disconnect on polling close
nuclearace Mar 5, 2015
296802f
better handle closes
nuclearace Mar 5, 2015
5ed2688
better handle when the server closes the connection (polling)
nuclearace Mar 5, 2015
c85a1de
tell client about failed ws
nuclearace Mar 5, 2015
d35934c
handle binary data better
nuclearace Mar 5, 2015
59a5e19
clean up
nuclearace Mar 5, 2015
166b2b5
make sure we're polling
nuclearace Mar 5, 2015
851ac76
Fix connection issues, binary data in nested data structures, some ra…
nuclearace Mar 6, 2015
44bff82
better reconnects
nuclearace Mar 6, 2015
41c168a
Fixes. Add onAny method
nuclearace Mar 6, 2015
ae28a02
Use a ephemeral NSURLSession for polling, because NSURLConnection.sen…
nuclearace Mar 6, 2015
14bf642
add example for onAny
nuclearace Mar 6, 2015
6399df4
tweaks
nuclearace Mar 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Socket.IO-Client-Swift
======================

Socket.IO-client for Swift. Supports ws/wss connections and binary. For socket.io 1.0+ and Swift 1.1.
Socket.IO-client for Swift. Supports ws/wss/polling connections and binary. For socket.io 1.0+ and Swift 1.1.

For Swift 1.2 use the 1.2 branch.

Expand All @@ -15,12 +15,13 @@ API
===
Constructor
-----------
`init(socketURL: String, opts:[String: AnyObject]? = nil)` - Constructs a new client for the given URL. opts can be omitted (will use default values.)
`init(socketURL: String, opts:[String: AnyObject]? = nil)` - Constructs a new client for the given URL. opts can be omitted (will use default values. See example)
Methods
-------
1. `socket.on(name:String, callback:((data:NSArray?, ack:AckEmitter?) -> Void))` - Adds a handler for an event. Items are passed by an array. `ack` can be used to send an ack when one is requested. See example.
2. `socket.onAny(callback:((event:String, items:AnyObject?)) -> Void)` - Adds a handler for all events. It will be called on any received event.
3. `socket.emit(event:String, args:AnyObject...)` - Sends a message. Can send multiple args.
4. `socket.emitWithAck(event:String, args:AnyObject...) -> SocketAckHandler` - Sends a message that requests an acknoweldgement from the server. Returns a SocketAckHandler which you can use to add an onAck handler. See example.
4. `socket.emitWithAck(event:String, args:AnyObject...) -> SocketAckHandler` - Sends a message that requests an acknowledgement from the server. Returns a SocketAckHandler which you can use to add an onAck handler. See example.
5. `socket.connect()` - Establishes a connection to the server. A "connect" event is fired upon successful connection.
6. `socket.connectWithParams(params:[String: AnyObject])` - Establishes a connection to the server passing the specified params. A "connect" event is fired upon successful connection.
7. `socket.close()` - Closes the socket. Once a socket is closed it should not be reopened.
Expand All @@ -41,9 +42,13 @@ let socket = SocketIOClient(socketURL: "https://localhost:8080", opts: [
"reconnects": true, // default true
"reconnectAttempts": 5, // default -1 (infinite tries)
"reconnectWait": 5, // default 10
"nsp": "swift" // connects to the specified namespace. Default is /
"nsp": "swift", // connects to the specified namespace. Default is /
"forcePolling": true // if true, the socket will only use XHR polling, default is false (polling/WebSockets)
])

// Called on every event
socket.onAny {println("got event: \($0.event) with items \($0.items)")}

// Socket Events
socket.on("connect") {data, ack in
println("socket connected")
Expand All @@ -67,7 +72,7 @@ socket.on("ackEvent") {data, ack in
}

socket.emitWithAck("ackTest", "test").onAck {data in
println(data)
println(data?[0])
}

ack?("Got your event", "dude")
Expand Down
2 changes: 1 addition & 1 deletion SwiftIO/SocketAckHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import Foundation

typealias AckCallback = (AnyObject?) -> Void
typealias AckCallback = (NSArray?) -> Void

class SocketAckHandler {
let ackNum:Int!
Expand Down
Loading