-
Notifications
You must be signed in to change notification settings - Fork 749
Expand file tree
/
Copy pathMockWebSocket.swift
More file actions
37 lines (28 loc) · 928 Bytes
/
MockWebSocket.swift
File metadata and controls
37 lines (28 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import Foundation
@testable import ApolloWebSocket
public class MockWebSocket: WebSocketClient {
public var request: URLRequest
public var callbackQueue: DispatchQueue = DispatchQueue.main
public var delegate: WebSocketClientDelegate? = nil
public var isConnected: Bool = false
public required init(request: URLRequest, protocol: WebSocket.WSProtocol) {
self.request = request
self.request.setValue(`protocol`.description, forHTTPHeaderField: WebSocket.Constants.headerWSProtocolName)
}
open func reportDidConnect() {
callbackQueue.async {
self.delegate?.websocketDidConnect(socket: self)
}
}
open func write(string: String) {
callbackQueue.async {
self.delegate?.websocketDidReceiveMessage(socket: self, text: string)
}
}
open func write(ping: Data, completion: (() -> ())?) {
}
public func disconnect() {
}
public func connect() {
}
}