javascript - Cached Messages showing in wrong order SignalR -
im using signalr create reporting system. used started project had develop suit needs. system should display messages have been wrote other users when new user logs in , showing in muddled order , 1 section of message( goal) undefined. wondering how fix message should show. should this:
chelsea vs arsenal (3) - (0): bla bla bla
but shows this:
bla bla blachelsea vs arsenal: undefined
code follows:
server side:
public void sendmessagetoall(string goal, string username, string message) { // store last 100 messages in cache addmessageincache(goal, username, message); // broad cast message clients.all.messagereceived(goal, username, message); } }
javascript
function registerclientmethods(chathub) { // calls when user logged in chathub.client.onconnected = function (id, teamnames, allusers, updates) { $('#hdid').val(id); $('#hdusername').val(teamnames); $('#spanuser').html(teamnames); // add existing messages (i = 0; < updates.length; i++) { addmessage(updates[i].goal, updates[i].teamnames, updates[i].message); var view = addmessage; } } // on new user connected chathub.client.onnewuserconnected = function (id, name) { var homescore = $('#homegoal').val(); var awayscore = $('#awaygoal').val(); var goal = "( " + homescore + " ) - ( " + awayscore + " )"; adduser(chathub, id, name); addscore(chathub, id, name, goal); } chathub.client.messagereceived = function (goal, teamnames, updates) { addmessage(goal, teamnames, updates); var view = addmessage; } } function addmessage(goal, teamnames, updates) { var homescore = $('#homegoal').val(); var awayscore = $('#awaygoal').val(); $('#divchatwindow').append('<div class="message"><span class="username">' + teamnames + goal + '</span>: ' + updates + '</div>'); }
on initial read, looks lists might getting overwritten each time hub gets instanciated- hubs transient , re-created each connection. either move list declaration outside hub, or test list null before assigning it.
Comments
Post a Comment