Reputation: 179
I have a problem receiving messages from an application because sometimes works but not always, and I have to F5 side to get back to work. Any ideas what could be?
correct messages:
[19:15:27 GMT+0100 (Środkowoeuropejski czas stand.)] SignalR: Invoking question.SendMessage jquery.signalR-2.2.0.min.js:8 [19:15:27 GMT+0100 (Środkowoeuropejski czas stand.)] SignalR: Invoked question.SendMessage jquery.signalR-2.2.0.min.js:8 [19:15:27 GMT+0100 (Środkowoeuropejski czas stand.)] SignalR: Triggering client hub event 'newMessage' on hub 'question'. gameController.js:19 2d856458-6874-44a9-a402-37ab6ca61cec: hello
incorrect messages(no answer):
[19:15:51 GMT+0100 (Środkowoeuropejski czas stand.)] SignalR: Invoking question.SendMessage jquery.signalR-2.2.0.min.js:8 [19:15:51 GMT+0100 (Środkowoeuropejski czas stand.)] SignalR: Invoked question.SendMessage
$(function () {
$.connection.hub.logging = true;
$.connection.hub.start();
});
$.connection.hub.error(function (err) {
alert("error: " + err);
});
angular.module('app').value('gameHub', $.connection.question);
In CTRL
$scope.sendMessage = function () {
gameHub.server.sendMessage($scope.message);
}
gameHub.client.newMessage = function onNewMessage(message) {
$scope.messages.push({message: message});
$scope.$apply();
console.log(message);
}
Upvotes: 1
Views: 100
Reputation: 1213
As SignalR is for RealTime Application it will get you message as soon as the other person will send, meanwhile if you are on the other page where you don't have you hub connected then there can be two scenarios
1) If you've appended message through HTML or something then when you'll get back to same page (chat) then the messages will be removed due to page refresh.
-Solution
you can try saving messages to database so that when you get back you can
retrieve you chat
2) The hub might be getting disconnected
so you should try using OnConnected(), OnDisconnected(), & On ReConnected() methods.
Upvotes: 3