Skip to content

Commit 67375c4

Browse files
authored
updated README
1. Added section for specifying custom queue 2. Set custom headers and method while connecting 3. Specify protocols while connecting to server
1 parent b3d4b1f commit 67375c4

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,46 @@ Implementing Pub-Sub via channels
257257
var client = ScClient(url: "http://localhost:8000/socketcluster/")
258258
client.disableSSLVerification(true)
259259
```
260+
### Custom Queue
260261

262+
A custom queue can be specified when delegate methods are called. By default `DispatchQueue.main` is used, thus making all delegate methods calls run on the main thread. It is important to note that all WebSocket processing is done on a background thread, only the delegate method calls are changed when modifying the queue. The actual processing is always on a background thread and will not pause your app.
263+
264+
```swift
265+
var client = ScClient(url: "http://localhost:8000/socketcluster/")
266+
//create a custom queue
267+
client.setBackgroundQueue(queueName : "com.example.chatapp")
268+
```
269+
270+
### Custom Headers
271+
272+
You can also override the default websocket headers with your own custom ones like so:
273+
274+
```swift
275+
var request = URLRequest(url: URL(string: "http://localhost:8000/socketcluster/")!)
276+
request.timeoutInterval = 5
277+
request.setValue("someother protocols", forHTTPHeaderField: "Sec-WebSocket-Protocol")
278+
request.setValue("14", forHTTPHeaderField: "Sec-WebSocket-Version")
279+
request.setValue("Everything is Awesome!", forHTTPHeaderField: "My-Awesome-Header")
280+
var client = ScClient(URLRequest: request)
281+
```
282+
283+
### Custom HTTP Method
284+
285+
Your server may use a different HTTP method when connecting to the websocket:
286+
287+
```swift
288+
var request = URLRequest(url: URL(string: "http://localhost:8000/socketcluster/")!)
289+
request.httpMethod = "POST"
290+
request.timeoutInterval = 5
291+
var client = ScClient(URLRequest: request)
292+
```
293+
294+
### Protocols
295+
296+
If you need to specify a protocol, simple add it to the init:
297+
298+
```swift
299+
//chat and superchat are the example protocols here
300+
var request = URLRequest(url: URL(string: "http://localhost:8000/socketcluster/")!)
301+
var client = ScClient(URLRequest: request, protocols: ["chat","superchat"])
302+
```

0 commit comments

Comments
 (0)