Step 1 :
a. Download jquery.signalR-2.2.0.js or jquery.signalR-2.2.0.min.js.
b. Install Microsoft.Owin version 3.0.1.0.
c. Install Microsoft.Owin version 3.0.1.0.
d. Install Microsoft.Owin.Security version 2.1.0.0.
Step 2:
Make a Hub class like
[HubName("LiveChatHub")]
public class LiveChatHub:Hub
{
[HubMethodName("LiveChat")]
public static void LiveChat(string myMsg)
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<LiveChatHub>();
context.Clients.All.LiveChat(myMsg);
}
}
Step:3
Write this line where you want to push your data
LiveChatHub.LiveChat(myMsg.ToString());
Step:4
At RouteProvider class of your plugin add
public IAppBuilder _appBuilderService{get;set;}
and at
RegisterRoutes(RouteCollection routes)
method add
RegisterRoutes(RouteCollection routes)
Like:
public class RouteProvider : IRouteProvider
{
public IAppBuilder _appBuilderService{get;set;}
public void RegisterRoutes(RouteCollection routes)
{
RouteTable.Routes.MapOwinPath("/signalr", _appBuilderService => _appBuilderService.RunSignalR());
}
}
Step 5 :
Add necessary .js at your .cshtml page
Like :
@{
Layout = "~/Views/Shared/_ColumnsOne.cshtml";
Html.AddScriptParts("~/Plugins/LiveNotification/Scripts/jquery.signalR-2.2.0.js");
Html.AddScriptParts("~/SignalR/hubs");
Html.AddScriptParts("~/Plugins/LiveChat/Scripts/LiveChat.js");
}
The contain of LiveChat.js like
$(function () {
var notifications = $.connection.LiveChatHub;
notifications.client.LiveChat = function (myMsg) {
showMessage(myMsg);
};
// Start the connection.
$.connection.hub.start().done(function () {
}).fail(function (e) {
alert(e);
});
});
function showMessage(myMsg) {
alert(myMsg);
}
There may have some other ways to implement Signalar at plugin but by following these step I implement Signalar at my plugin at it works good.