我们有一个SignalR中心.以下jQuery代码在cordova上成功连接并正确处理SignalR客户端"调用"事件.
var connectionURL = "https://SOMEURL.azurewebsites.net/message";
connection = $.connection(connectionURL);
connection.start().done(function () {
console.log("Connected to hub again");
});
connection.disconnected(function () {
setTimeout(function () {
connection.start().done(function () {
console.log("Disconnected and Connected to hub again");
});
}, 5000);
});
connection.stateChanged(function (change) {
if (change.newState == $.signalR.connectionState.reconnecting) {
}
else if (change.newState == $.signalR.connectionState.connected) {
}
else if (change.newState == $.signalR.connectionState.disconnected) {
}// else if
});
connection.received(function (data) {
connectId = connection.id + "";
console.log("onDeviceReady run");
// call the function to parse the data
if …Run Code Online (Sandbox Code Playgroud)