Showing posts with the label signalr

How to hide generated javascript file in visual studio code

In this post I am going to show you a cool trick in visual studio code. Let's suppose you are writing typescript code in visual studio code and you want to hide generated javascript code.

Create .vscode folder in your folder and then create settings.json file and paste following code

{ "files.exclude": { "node_modules":true, "**/.git": true, "**/.DS_Store": true, "**/*": true, "**/*.js": {"when": "$(basename).ts"}     } }

How to create chat application using microsoft signalr

open visual studio and create a new MVC application
Select Empty MVC application

Open Package Manager Console and install SignalR

Right click on project and add new class ChatHub and inherit from Hub class that resides in Microsoft.AspNet.SignalR

public class ChatHub:Hub { //this method is called when client send message public void sendMessage(string message) { //this method brodcast message to all connected client Clients.All.newMessage(message); } } Right click on project and add new class named Startup and add following code inside it
public class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } Create a new html page and add following markup inside it.You can see that I have added three JavaScript lib :jquery,jqery-signalr* and  signalr/hubs.Signalr/hubs contains functions for interacting with server side hub class and also it generated automatic…

Access to the Hubs from outside of the Hub class

The Clients dynamic property of the Hub gives you access to all clients connected to the hub within the hub class. However, what if you would like to push data to the clients from outside of the Hub class.Use following code snippet and replace HubClass with your own class and get access of the signalr clients and server dynamic properties/methods.var myHub = GlobalHost.ConnectionManager.GetHubContext<HubClass>();