MCPcopy Create free account
hub / github.com/aspnet/AzureSignalR-samples / startSignalR

Function startSignalR

aspnet-samples/AspNetForm/Scripts/my.js:1–44  ·  view source on GitHub ↗
(tableId, group)

Source from the content-addressed store, hash-verified

1function startSignalR(tableId, group) {
2 // Declare a proxy to reference the hub.
3 var notificationHub = $.connection.notificationHub;
4 $.connection.hub.url = "/signalr";
5 // Create a function that the hub can call to broadcast messages.
6 notificationHub.client.updateItem = function (item) {
7 // Add the message to the page.
8 let tr = $('#' + tableId + item.Id);
9 if (tr) {
10 tr.children().remove();
11 appendCells(tr, item);
12 }
13 };
14 // Start the connection.
15 var connection = $.connection.hub;
16
17 connection.disconnected(function () {
18 reconnectOnFail("Disconnected.");
19 });
20
21 startConnectionWithRetry(connection);
22 return notificationHub;
23
24 function startConnectionWithRetry(hubConnection) {
25 hubConnection.start()
26 .done(async function () {
27 let items = await notificationHub.server.listenGroup(group);
28 $(`#${tableId} tbody tr`).remove();
29 items.forEach(item => {
30 let tr = $(`<tr id="${tableId}${item.Id}" />`);
31 appendCells(tr, item);
32 $(`#${tableId} tbody`).append(tr);
33 });
34 $('#status').html(`<h5 class='success'>Connected</h5>`);
35 });
36 }
37
38 function reconnectOnFail(message) {
39 $('#status').html(`<h5 class='error'>${message} Reconnecting...</h5>`);
40 setTimeout(function () {
41 startConnectionWithRetry(connection)
42 }, 1000);
43 }
44};
45
46function appendRow(tableId, item) {
47 let tr = $(`<tr id="${tableId}${item.Id}" />`);

Callers

nothing calls this directly

Calls 4

appendCellsFunction · 0.85
reconnectOnFailFunction · 0.85
startConnectionWithRetryFunction · 0.85
$Function · 0.70

Tested by

no test coverage detected