Skip to content

Commit

Permalink
Update socket functions
Browse files Browse the repository at this point in the history
  • Loading branch information
enums committed Jan 2, 2022
1 parent 90ebcb5 commit fc50e2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
17 changes: 1 addition & 16 deletions Sources/Heze/Socket/HezeSocketClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,8 @@ open class HezeSocketClient: HezeSocketHandler {
return nil
}

public func sendMessage(_ msg: String) {
socket?.sendStringMessage(string: msg, final: true) { }
}

public func sendBytes(_ bytes: [UInt8]) {
socket?.sendBinaryMessage(bytes: bytes, final: true) { }
}

public func close() {
open func close() {
socket?.close()
}

open override func connected() {

}

open override func closed() {

}
}
14 changes: 11 additions & 3 deletions Sources/Heze/Socket/HezeSocketHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ open class HezeSocketHandler: HezeHandler, WebSocketSessionHandler {
return
}
if let bytes = self.handleBytes(bytes, opcodeType: opcodeType, final: final, socket: socket)?.toBytes() {
socket.sendBinaryMessage(bytes: bytes, final: final) {
self.sendBytes(bytes) {
self.handleSession(request: req, socket: socket)
}
} else {
Expand All @@ -85,11 +85,19 @@ open class HezeSocketHandler: HezeHandler, WebSocketSessionHandler {
return nil
}

public func connected() {
open func sendMessage(_ msg: String, completion: @escaping () -> Void) {
sendBytes([UInt8](msg.utf8), completion: completion)
}

open func sendBytes(_ bytes: [UInt8], completion: @escaping () -> Void) {
socket?.sendBinaryMessage(bytes: bytes, final: true, completion: completion)
}

open func connected() {

}

public func closed() {
open func closed() {

}
}

0 comments on commit fc50e2e

Please sign in to comment.