UNPKG

2.2 kBMarkdownView Raw
1JavaScript and TypeScript clients for SignalR for ASP.NET Core
2
3## Installation
4
5```bash
6npm install @microsoft/signalr
7```
8or
9```bash
10yarn add @microsoft/signalr
11```
12
13## Usage
14
15See the [SignalR Documentation](https://docs.microsoft.com/en-us/aspnet/core/signalr) at docs.microsoft.com for documentation on the latest release. [API Reference Documentation](https://docs.microsoft.com/javascript/api/%40aspnet/signalr/?view=signalr-js-latest) is also available on docs.microsoft.com.
16
17### Browser
18
19To use the client in a browser, copy `*.js` files from the `dist/browser` folder to your script folder include on your page using the `<script>` tag.
20
21### WebWorker
22
23To use the client in a webworker, copy `*.js` files from the `dist/webworker` folder to your script folder include on your webworker using the `importScripts` function. Note that webworker SignalR hub connection supports only absolute path to a SignalR hub.
24
25### Node.js
26
27To use the client in a NodeJS application, install the package to your `node_modules` folder and use `require('@microsoft/signalr')` to load the module. The object returned by `require('@microsoft/signalr')` has the same members as the global `signalR` object (when used in a browser).
28
29### Example (Browser)
30
31```JavaScript
32let connection = new signalR.HubConnectionBuilder()
33 .withUrl("/chat")
34 .build();
35
36connection.on("send", data => {
37 console.log(data);
38});
39
40connection.start()
41 .then(() => connection.invoke("send", "Hello"));
42```
43
44### Example (WebWorker)
45
46
47```JavaScript
48importScripts('signalr.js');
49
50let connection = new signalR.HubConnectionBuilder()
51 .withUrl("https://example.com/signalr/chat")
52 .build();
53
54connection.on("send", data => {
55 console.log(data);
56});
57
58connection.start()
59 .then(() => connection.invoke("send", "Hello"));
60
61```
62
63### Example (NodeJS)
64
65```JavaScript
66const signalR = require("@microsoft/signalr");
67
68let connection = new signalR.HubConnectionBuilder()
69 .withUrl("/chat")
70 .build();
71
72connection.on("send", data => {
73 console.log(data);
74});
75
76connection.start()
77 .then(() => connection.invoke("send", "Hello"));
78```