【发布时间】:2018-03-13 14:44:57
【问题描述】:
我正在使用AutosoftDMS/SignalR-Swift 客户端将我的 Swift/iOS 应用程序连接到 SignalR 服务器。我的问题是,如果 SignalR 服务器支持不同的“房间”,正确的连接顺序是什么?
示例 #1:
let hubConnection = HubConnection(withUrl: <some SignalR server URL>)
let chatHub = hubConnection.createHubProxy(hubName: "RoomChatHub")
hubConnection.started = {
// the value 2 is some room identifier
self.chatHub.invoke(method: "RoomConnect", withArgs: [2])
}
这个例子的问题是 invoke 没有处理程序来开始接收来自 2 号房间的 SignalR 服务器的消息。
示例 #2:
let hubConnection = HubConnection(withUrl: <some SignalR server URL>)
let chatHub = hubConnection.createHubProxy(hubName: "RoomChatHub")
chatHub.on(eventName: "RoomConnect") { (args) in
if let message = args[0] as? String {
print("Room Message: \(message)")
}
}
这个例子的问题是 chatHub.on 方法没有允许我指定我只想要房间 #2 的消息的参数。
您如何以一种我可以说我想要某个特定房间的消息的方式连接到 SignalR 服务器?
【问题讨论】: