Add rawEmitView. Implements #992
This commit is contained in:
parent
4564aebec1
commit
d21a65e117
@ -7,16 +7,15 @@ import Foundation
|
||||
/// Class that gives a backwards compatible way to cause an emit not to recursively check for Data objects.
|
||||
///
|
||||
/// Usage:
|
||||
///
|
||||
/// ```swift
|
||||
/// socket.binary(false).emit("myEvent", myObject)
|
||||
/// socket.rawEmitView.emit("myEvent", myObject)
|
||||
/// ```
|
||||
public final class SocketBinaryView : NSObject {
|
||||
private unowned let socket: SocketIOClient
|
||||
private let binary: Bool
|
||||
|
||||
init(socket: SocketIOClient, binary: Bool) {
|
||||
init(socket: SocketIOClient) {
|
||||
self.socket = socket
|
||||
self.binary = binary
|
||||
}
|
||||
|
||||
/// Send an event to the server, with optional data items.
|
||||
@ -48,7 +47,7 @@ public final class SocketBinaryView : NSObject {
|
||||
return
|
||||
}
|
||||
|
||||
socket.emit([event] + items, binary: binary)
|
||||
socket.emit([event] + items, binary: false)
|
||||
}
|
||||
|
||||
/// Sends a message to the server, requesting an ack.
|
||||
@ -101,6 +100,6 @@ public final class SocketBinaryView : NSObject {
|
||||
/// - returns: An `OnAckCallback`. You must call the `timingOut(after:)` method before the event will be sent.
|
||||
@objc
|
||||
open func emitWithAck(_ event: String, with items: [Any]) -> OnAckCallback {
|
||||
return socket.createOnAck([event] + items, binary: binary)
|
||||
return socket.createOnAck([event] + items, binary: false)
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,6 +67,18 @@ open class SocketIOClient : NSObject, SocketIOClientSpec {
|
||||
@objc
|
||||
public private(set) weak var manager: SocketManagerSpec?
|
||||
|
||||
/// A view into this socket where emits do not check for binary data.
|
||||
///
|
||||
/// Usage:
|
||||
///
|
||||
/// ```swift
|
||||
/// socket.rawEmitView.emit("myEvent", myObject)
|
||||
/// ```
|
||||
///
|
||||
/// **NOTE**: It is not safe to hold on to this view beyond the life of the socket.
|
||||
@objc
|
||||
public private(set) lazy var rawEmitView = SocketBinaryView(socket: self)
|
||||
|
||||
/// The status of this client.
|
||||
@objc
|
||||
public private(set) var status = SocketIOStatus.notConnected {
|
||||
|
||||
@ -43,6 +43,17 @@ public protocol SocketIOClientSpec : class {
|
||||
/// **Must** start with a `/`.
|
||||
var nsp: String { get }
|
||||
|
||||
/// A view into this socket where emits do not check for binary data.
|
||||
///
|
||||
/// Usage:
|
||||
///
|
||||
/// ```swift
|
||||
/// socket.rawEmitView.emit("myEvent", myObject)
|
||||
/// ```
|
||||
///
|
||||
/// **NOTE**: It is not safe to hold on to this view beyond the life of the socket.
|
||||
var rawEmitView: SocketBinaryView { get }
|
||||
|
||||
/// The status of this client.
|
||||
var status: SocketIOStatus { get }
|
||||
|
||||
|
||||
@ -66,6 +66,10 @@
|
||||
[self.socket emit:@"testEmit" with:@[@YES]];
|
||||
}
|
||||
|
||||
- (void)testRawEmitSyntax {
|
||||
[[self.socket rawEmitView] emit:@"myEvent" with:@[@1]];
|
||||
}
|
||||
|
||||
- (void)testEmitWithAckSyntax {
|
||||
[[self.socket emitWithAck:@"testAckEmit" with:@[@YES]] timingOutAfter:0 callback:^(NSArray* data) { }];
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user