mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 10:11:00 +00:00
Streaming: Send message as UTF8 + token in subprotocols fix #1438
This commit is contained in:
parent
9e01e6b0f6
commit
831ff08082
2 changed files with 9 additions and 4 deletions
|
@ -62,8 +62,10 @@ public class StreamWatcher: ObservableObject {
|
|||
}
|
||||
|
||||
private func sendMessage(message: StreamMessage) {
|
||||
task?.send(.data(try! encoder.encode(message)),
|
||||
completionHandler: { _ in })
|
||||
if let encodedMessage = try? encoder.encode(message),
|
||||
let stringMessage = String(data: encodedMessage, encoding: .utf8) {
|
||||
task?.send(.string(stringMessage), completionHandler: { _ in })
|
||||
}
|
||||
}
|
||||
|
||||
private func receiveMessage() {
|
||||
|
|
|
@ -218,8 +218,11 @@ public final class Client: ObservableObject, Equatable, Identifiable, Hashable {
|
|||
|
||||
public func makeWebSocketTask(endpoint: Endpoint, instanceStreamingURL: URL?) -> URLSessionWebSocketTask {
|
||||
let url = makeURL(scheme: "wss", endpoint: endpoint, forceServer: instanceStreamingURL?.host)
|
||||
let request = makeURLRequest(url: url, endpoint: endpoint, httpMethod: "GET")
|
||||
return urlSession.webSocketTask(with: request)
|
||||
var subprotocols: [String] = []
|
||||
if let oauthToken = critical.withLock({ $0.oauthToken }) {
|
||||
subprotocols.append(oauthToken.accessToken)
|
||||
}
|
||||
return urlSession.webSocketTask(with: url, protocols: subprotocols)
|
||||
}
|
||||
|
||||
public func mediaUpload<Entity: Decodable>(endpoint: Endpoint,
|
||||
|
|
Loading…
Reference in a new issue