@@ -58,6 +58,9 @@ public struct SocketPacket : CustomStringConvertible {
58
58
}
59
59
}
60
60
61
+ /// don't do any additional encoding on non-binary events
62
+ private let disableEventMessageParsing : Bool
63
+
61
64
private let placeholders : Int
62
65
63
66
/// A string representation of this packet.
@@ -77,13 +80,14 @@ public struct SocketPacket : CustomStringConvertible {
77
80
}
78
81
79
82
init ( type: PacketType , data: [ Any ] = [ Any] ( ) , id: Int = - 1 , nsp: String , placeholders: Int = 0 ,
80
- binary: [ Data ] = [ Data] ( ) ) {
83
+ binary: [ Data ] = [ Data] ( ) , disableEventMessageParsing : Bool = false ) {
81
84
self . data = data
82
85
self . id = id
83
86
self . nsp = nsp
84
87
self . type = type
85
88
self . placeholders = placeholders
86
89
self . binary = binary
90
+ self . disableEventMessageParsing = disableEventMessageParsing
87
91
}
88
92
89
93
mutating func addData( _ data: Data ) -> Bool {
@@ -102,6 +106,10 @@ public struct SocketPacket : CustomStringConvertible {
102
106
}
103
107
104
108
private func completeMessage( _ message: String ) -> String {
109
+ if type == . event && disableEventMessageParsing {
110
+ return message + ( args. first as? String ?? " [] " )
111
+ }
112
+
105
113
guard data. count != 0 else { return message + " [] " }
106
114
guard let jsonSend = try ? data. toJSON ( ) , let jsonString = String ( data: jsonSend, encoding: . utf8) else {
107
115
DefaultSocketLogger . Logger. error ( " Error creating JSON object in SocketPacket.completeMessage " ,
@@ -207,14 +215,15 @@ extension SocketPacket {
207
215
}
208
216
}
209
217
210
- static func packetFromEmit( _ items: [ Any ] , id: Int , nsp: String , ack: Bool , checkForBinary: Bool = true ) -> SocketPacket {
218
+ static func packetFromEmit( _ items: [ Any ] , id: Int , nsp: String , ack: Bool , checkForBinary: Bool = true , disableEventMessageParsing : Bool = false ) -> SocketPacket {
211
219
if checkForBinary {
212
220
let ( parsedData, binary) = deconstructData ( items)
213
221
214
222
return SocketPacket ( type: findType ( binary. count, ack: ack) , data: parsedData, id: id, nsp: nsp,
215
- binary: binary)
223
+ binary: binary, disableEventMessageParsing : disableEventMessageParsing )
216
224
} else {
217
- return SocketPacket ( type: findType ( 0 , ack: ack) , data: items, id: id, nsp: nsp)
225
+ return SocketPacket ( type: findType ( 0 , ack: ack) , data: items, id: id, nsp: nsp,
226
+ disableEventMessageParsing: disableEventMessageParsing)
218
227
}
219
228
}
220
229
}
0 commit comments