javascript - Play Real-time Notification Sound to all the users logged in the Webapp Without reloading the page -
i know there many solutions can found in web regarding problem, none of them working me. that's why i'm asking question.
first let me explain i'm looking achieve -
-> i'm developing multi-user web application [asp.net] -> i'm using signalr real-time database change notifications , signalr instantly transmit change notifications users logged in application. -> in addition want play notification sound logged in users can understand new notification need attention.
this i've done far -
javascript
<script> function playsound(mysound) { //thissound = document.getelementbyid(mysound); //thissound.play(); var audio = new audio(mysound); audio.play(); } </script>
code behind -
scriptmanager.registerclientscriptblock(me, [gettype](), "openwindow", "javascript: playsound('./audio/notification.wav')", true)
the problem solution user need reload page hear notification sound, think pointless if user can't hear them instantly signalr processing notifications.
is possible push sound clients don't need reload page?
any highly appreciated. if need further clarification please let me know.
finally got worked. had change jquery little bit -
<script type="text/javascript"> function playsound(mysound) { //thissound = document.getelementbyid(mysound); //thissound.play(); var audio = new audio(mysound); audio.play(); } $(function () { var notify = $.connection.notificationshub; var audio; notify.client.displaynotification = function (s_not, s_path) { $("#newnot").html(s_not); audio = new audio(s_path); var ilevel = "<%=system.web.httpcontext.current.session("user_level")%>"; var i_oldnot = "<%=system.web.httpcontext.current.session("not_count")%>"; if (ilevel == 2) { //alert(i_oldnot + " " + s_not); if (i_oldnot < i_not) { playsound("/audio/notification.wav"); //i_oldnot == number(s_not); } } }; $.connection.hub.start(); }); </script>
in code behind had set session variable store number of last notification before update. if previous , present number of notification higher session value notification sound play -
system.web.httpcontext.current.session("not_count")= i_lastnotcount
now sound playing without reloading page. special rdans
, because of below comments got idea -
then in comment say:
i have implemented signalr. it's not problem @ all.
this suggests me don't understand signalr doing because whole point of signalr push browser without having post or use ajax call.
Comments
Post a Comment