This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Snippets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use_frameworks! | |
pod 'SwiftSignalRClient' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let hubConnection = HubConnectionBuilder(url: URL(string: "http://localhost:5000/playground")!) | |
.withLogging(minLogLevel: .debug) | |
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol HubConnectionDelegate: class { | |
func connectionDidOpen(hubConnection: HubConnection) | |
func connectionDidFailToOpen(error: Error) | |
func connectionDidClose(error: Error?) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// invoking a hub method and receiving a result | |
hubConnection.invoke(method: "Add", 2, 3, resultType: Int.self) { result, error in | |
if let error = error { | |
print("error: \(error)") | |
} else { | |
print("Add result: \(result!)") | |
} | |
} | |
// invoking a hub method that does not return a result | |
hubConnection.invoke(method: "Broadcast", "Playground user", "Sending a message") { error in | |
if let error = error { | |
print("error: \(error)") | |
} else { | |
print("Broadcast invocation completed without errors") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hubConnection.invoke(method: "Add", arguments: [2, 3], resultType: Int.self) { result, error in | |
if let error = error { | |
print("error: \(error)") | |
} else { | |
print("Add result: \(result!)") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hubConnection.on(method: "AddMessage") {(user: String, message: String) in | |
print(">>> \(user): \(message)") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hubConnection.on(method: "AddMessage", callback: { argumentExtractor in | |
let user = try argumentExtractor.getArgument(type: String.self) | |
var message = "" | |
if argumentExtractor.hasMoreArgs() { | |
message = try argumentExtractor.getArgument(type: String.self) | |
} | |
print(">>> \(user): \(message)") | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hubConnection.send(method: "Broadcast", "Playground user", "Testing send") { error in | |
if let error = error { | |
print("Send failed: \(error)") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hubConnection.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hubConnection.stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let streamHandle = hubConnection.stream(method: "StreamNumbers", 1, 10000, itemType: Int.self, | |
streamItemReceived: { item in print(">>> \(item!)") }) { error in | |
print("Stream closed.") | |
if let error = error { | |
print("Error: \(error)") | |
} | |
} | |
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2)) { | |
hubConnection.cancelStreamInvocation(streamHandle: streamHandle) { error in | |
print("Canceling stream invocation failed: \(error)") | |
} | |
} |
The getUserStatus
status method is supposed to return pStatus
but it returned null
hence the error 'while getting result for server method with invocationId 1'.
"No handler registered for method 'partnerStatus'" means that the server invoked a client method but there was no code registered to handle this invocation. You register handlers with the HubConnection.on
method.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello
I am using this library.
I try to invoke method
I want to read the response.
From below link, I create the class & set it as resultType: pStatus.self in above method.
https://gist.github.com/moozzyk/be9be3881e36191891ead2980108bcc5
I get response as below.
2019-11-17T11:53:58.879Z debug: Message received: {"type":1,"target":"partnerStatus","arguments":[{"UserId":"e30fca3b-a2b9-4200-b89c-13f68a1226b2","Online":false,"Status":"Last Seen 08/11/2019 07:19 ص","LastSeen":"2019-11-08T07:19:58.8444713"}]}
2019-11-17T11:53:58.879Z debug: Message received: {"type":3,"invocationId":"1","result":null}
Also I get below log.
2019-11-17T11:53:58.879Z debug: Server method with invocationId 1 completed successfully
2019-11-17T11:53:58.879Z error: Error while getting result for server method with invocationId 1
fapa==error: serializationError(underlyingError: Swift.DecodingError.valueNotFound(Swift.KeyedDecodingContainer<ChatTestSignalR.pStatus.(unknown context at $10924b7e0).CodingKeys>, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "result", intValue: nil)], debugDescription: "Cannot get keyed decoding container -- found null value instead.", underlyingError: nil)))
I am not understanding why I didn't get response for my main method of getUserStatus?
I also get message as "No handler registered for method 'partnerStatus'"