Skip to content

Commit

Permalink
adapted to socket changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gagnant committed Jan 21, 2017
1 parent 66750d7 commit 451cdff
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "Gagnant/Socket" "0.1.6"
github "Gagnant/Socket" "0.1.7"
2 changes: 1 addition & 1 deletion Carthage/Checkouts/Socket
22 changes: 9 additions & 13 deletions JSTP/Chunks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,26 @@ import JavaScriptCore

internal class Chunks {

fileprivate var buffer: String
private var buffer: Data

init() {
buffer = kChunksFirst
buffer = Data()
}

func add(_ chunk: String) -> JSValue! {
func add(_ chunk: Data) -> JSValue? {

buffer += chunk
buffer.append(chunk)

guard chunk.hasSuffix(kPacketDelimiter) else {
guard let source = String(data: buffer, encoding: .utf8), source.hasSuffix(kPacketDelimiter) else {
return nil
}

var chunks = buffer + kChunksLast
buffer = kChunksFirst

chunks = chunks.replacingOccurrences(of: kPacketDelimiter, with: ",")

buffer = Data()

let chunks = (kChunksFirst + source + kChunksLast).replacingOccurrences(of: kPacketDelimiter, with: ",")
let packets = Context.shared.parse(chunks)

guard packets.isUndefined == false,
packets.isNull == false else {

guard packets.isUndefined == false, packets.isNull == false else {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions JSTP/Delegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ internal class TCPSocketDelegateImplementation : TCPSocketDelegate {
connection.delegate?.connection(connection, didFailWithError: error)
}

internal func socket(_ socket: TCPSocket, didReceiveMessage text: String) {
internal func socket(_ socket: TCPSocket, didReceiveData data: Data) {

guard let packets = connection.chunks.add(text) else {
guard let packets = connection.chunks.add(data) else {
return
}

Expand Down

0 comments on commit 451cdff

Please sign in to comment.