Skip to content

Commit

Permalink
Use WebsocketClient protocol to support mocking (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 authored and freak4pc committed Nov 8, 2018
1 parent e249c0b commit e107d9b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Source/RxStarscream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ public enum WebSocketEvent {
case pong
}

public class RxWebSocketDelegateProxy: DelegateProxy<WebSocket, NSObjectProtocol>, DelegateProxyType, WebSocketDelegate, WebSocketPongDelegate {
public class RxWebSocketDelegateProxy<Client: WebSocketClient>: DelegateProxy<Client, NSObjectProtocol>, DelegateProxyType, WebSocketDelegate, WebSocketPongDelegate {

private weak var forwardDelegate: WebSocketDelegate?
private weak var forwardPongDelegate: WebSocketPongDelegate?

fileprivate let subject = PublishSubject<WebSocketEvent>()

required public init(websocket: WebSocket) {
required public init(websocket: Client) {
super.init(parentObject: websocket, delegateProxy: RxWebSocketDelegateProxy.self)
}

public static func currentDelegate(for object: WebSocket) -> NSObjectProtocol? {
public static func currentDelegate(for object: Client) -> NSObjectProtocol? {
return object.delegate as? NSObjectProtocol
}

public static func setCurrentDelegate(_ delegate: NSObjectProtocol?, to object: WebSocket) {
public static func setCurrentDelegate(_ delegate: NSObjectProtocol?, to object: Client) {
object.delegate = delegate as? WebSocketDelegate
object.pongDelegate = delegate as? WebSocketPongDelegate
}
Expand Down Expand Up @@ -69,7 +69,7 @@ public class RxWebSocketDelegateProxy: DelegateProxy<WebSocket, NSObjectProtocol
}
}

extension Reactive where Base: WebSocket {
extension Reactive where Base: WebSocketClient {

public var response: Observable<WebSocketEvent> {
return RxWebSocketDelegateProxy.proxy(for: base).subject
Expand Down

0 comments on commit e107d9b

Please sign in to comment.