Using SIGNALR to implement message reminders

Source: Internet
Author: User

The ASP. NET SIGNALR is a class library that Microsoft implements for real-time communication. In general, SIGNALR uses JavaScript's long polling to implement client and server communication, and SIGNALR also supports websockets communication as websockets occurs in HTML5. In addition, the program developed by SIGNALR is not limited to hosting in IIS, but can be hosted in any application, including consoles, client programs and Windows services, and also supports mono, which means it can be deployed across platforms in a Linux environment.

There are two types of objects inside SIGNALR:

    1. HTTP Persistent connection (Persisten Connection) object: Used to resolve long-time connections. It is also possible for the client to proactively request data to the server, and the server side does not need to implement too much detail, only to handle the five events provided in Persistentconnection: onconnected, onreconnected, onreceived, OnError and OnDisconnect.
    2. Hub (Hub) object: Used to solve the real-time (realtime) Information exchange function, the server can use the URL to register one or more hubs, as long as the connection to the hub, you can share with all the client to send information to the servers, while the service side can invoke the client's script.

SIGNALR the entire information exchange package, the client and the server are using JSON to communicate, all the hub information declared on the service side, will generate JavaScript output to the client. NET relies on proxies to generate proxy objects, and the inside of proxies is to convert JSON into objects.

A message reminder is that when a customer has a new message, a pop-up box is alerted at the bottom right corner of the client. The idea to implement this function is:

    1. The SIGNALR server push message to the client is implemented by calling the client's ReceiveMessage method to attach the message to the chat record, so we can implement the frame logic in the client's ReceiveMessage method.
    2. After finding a way to define the location, it is natural to find a better frame effect JS class Library, where the use of inotify library to achieve. The GitHub address for this library is: https://github.com/jaywcjlove/iNotify, online test address: http://jslite.io/iNotify/
    3. You see QQ or the message reminds, the message is usually not in the chat of the current tab page will pop up, we can use the HTML5 Visibilitychange event to achieve, but I here is through the loss of focus, that is, the focus event.
Javascript
//Receiving MessagesSystemHub.client.receivePrivateMessage =function(Fromuserid, userName, message) {//the code in topic two             //code for message Reminders    if(Active = =false) {                 varin =NewiNotify ({effect:' Flash ', Interval:500, Audio: {file: ['/music/msg.mp3 ']}, notification: {title:Notification ", Body:' You have a new message '                     }                 }); In.settitle (true). Player (); In.setfavicon (true). Settitle (true). Notify (); }         }; }    

Using SIGNALR to implement message reminders

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.