chore: share bonjour escapes + refresh webchat bundle
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
import Foundation
|
||||
|
||||
enum BonjourEscapeDecoder {
|
||||
static func decode(_ input: String) -> String {
|
||||
// mDNS / DNS-SD commonly escapes bytes in instance names as `\\DDD`
|
||||
// (decimal-encoded), e.g. spaces are `\\032`.
|
||||
var out = ""
|
||||
var i = input.startIndex
|
||||
while i < input.endIndex {
|
||||
if input[i] == "\\",
|
||||
let d0 = input.index(i, offsetBy: 1, limitedBy: input.index(before: input.endIndex)),
|
||||
let d1 = input.index(i, offsetBy: 2, limitedBy: input.index(before: input.endIndex)),
|
||||
let d2 = input.index(i, offsetBy: 3, limitedBy: input.index(before: input.endIndex)),
|
||||
input[d0].isNumber,
|
||||
input[d1].isNumber,
|
||||
input[d2].isNumber
|
||||
{
|
||||
let digits = String(input[d0...d2])
|
||||
if let value = Int(digits),
|
||||
let scalar = UnicodeScalar(value)
|
||||
{
|
||||
out.append(Character(scalar))
|
||||
i = input.index(i, offsetBy: 4)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
out.append(input[i])
|
||||
i = input.index(after: i)
|
||||
}
|
||||
return out
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ final class BridgeDiscoveryModel: ObservableObject {
|
||||
self.bridges = results.compactMap { result -> DiscoveredBridge? in
|
||||
switch result.endpoint {
|
||||
case let .service(name, _, _, _):
|
||||
let decodedName = BonjourEscapeDecoder.decode(name)
|
||||
let decodedName = BonjourEscapes.decode(name)
|
||||
return DiscoveredBridge(
|
||||
name: decodedName,
|
||||
endpoint: result.endpoint,
|
||||
@@ -75,6 +75,6 @@ final class BridgeDiscoveryModel: ObservableObject {
|
||||
}
|
||||
|
||||
private static func prettyEndpointDebugID(_ endpoint: NWEndpoint) -> String {
|
||||
BonjourEscapeDecoder.decode(String(describing: endpoint))
|
||||
BonjourEscapes.decode(String(describing: endpoint))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ actor BridgeSession {
|
||||
private static func prettyRemoteEndpoint(_ endpoint: NWEndpoint) -> String? {
|
||||
switch endpoint {
|
||||
case let .hostPort(host, port):
|
||||
return "\(host):\(port)".replacingOccurrences(of: "::ffff:", with: "")
|
||||
"\(host):\(port)".replacingOccurrences(of: "::ffff:", with: "")
|
||||
default:
|
||||
return String(describing: endpoint)
|
||||
String(describing: endpoint)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user