|
|
@ -86,35 +86,23 @@ |
|
|
|
|
|
|
|
@RenderSection("scripts", required: false) |
|
|
|
|
|
|
|
|
|
|
|
@using Microsoft.AspNetCore.Authentication; |
|
|
|
@using Microsoft.Extensions.Options |
|
|
|
@inject IOptions<AppSettings> settings |
|
|
|
|
|
|
|
<script type="text/javascript"> |
|
|
|
if ('@User.Identity.IsAuthenticated' === 'True') { |
|
|
|
var timerId; |
|
|
|
|
|
|
|
stablishConnection((conn) => registerNotificationHandlers(conn)); |
|
|
|
connect(); |
|
|
|
} |
|
|
|
|
|
|
|
function stablishConnection(cb) { |
|
|
|
async function connect() { |
|
|
|
let connection = new signalR.HubConnectionBuilder() |
|
|
|
.withUrl('@settings.Value.SignalrHubUrl/hub/notificationhub', { |
|
|
|
accessTokenFactory: () => { |
|
|
|
return "Authorization", getToken(); |
|
|
|
} |
|
|
|
}) |
|
|
|
.withUrl('/hub/notificationhub') |
|
|
|
.withAutomaticReconnect() |
|
|
|
.build(); |
|
|
|
|
|
|
|
connection.start().then(function () { |
|
|
|
console.log('User Registered to Signalr Hub'); |
|
|
|
cb(connection); |
|
|
|
}); |
|
|
|
} |
|
|
|
.build(); |
|
|
|
|
|
|
|
await connection.start(); |
|
|
|
|
|
|
|
console.log('User Registered to Signalr Hub'); |
|
|
|
|
|
|
|
function registerNotificationHandlers(connection) { |
|
|
|
connection.on("UpdatedOrderState", (message) => { |
|
|
|
toastr.success('Updated to status: ' + message.status, 'Order Id: ' + message.orderId); |
|
|
|
if (window.location.pathname.split("/").pop() === 'Order') { |
|
|
@ -123,10 +111,6 @@ |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function getToken() { |
|
|
|
return '@Context.GetTokenAsync("access_token").Result'; |
|
|
|
} |
|
|
|
|
|
|
|
function refreshOrderList() { |
|
|
|
clearTimeout(timerId); |
|
|
|
timerId = setTimeout(function () { |
|
|
|