Files
doneit-web/src/app/services/socket-connection-mcr.service.ts
T

45 lines
981 B
TypeScript
Raw Normal View History

2024-01-17 10:25:16 +01:00
import { Injectable } from '@angular/core';
import * as signalR from "@microsoft/signalr"
import { SessionStore } from '../store/session.service';
@Injectable({
providedIn: 'root'
})
export class SocketConnectionMCRService {
constructor() { }
connect() {
2024-01-17 15:11:31 +01:00
2024-01-22 16:09:02 +01:00
console.log("SocketConnectionMCRService")
2024-01-17 15:11:31 +01:00
2024-01-17 10:25:16 +01:00
var connection = new signalR.HubConnectionBuilder()
.withUrl("https://gdcmapi-dev.dyndns.info/FileHub", {
accessTokenFactory: () => SessionStore.user.Authorization
}).configureLogging(signalR.LogLevel.Information)
2024-01-17 15:11:31 +01:00
.build();
2024-01-17 10:25:16 +01:00
connection.on("ReceiveMessage", (message) => {
2024-01-17 15:11:31 +01:00
console.log("ReceiveMessage", message)
2024-01-17 10:25:16 +01:00
})
2024-01-17 15:11:31 +01:00
2024-01-22 16:09:02 +01:00
connection.start()
.then(() => {
console.log("SignalR connection started.");
})
.catch((error) => {
console.error("Error starting SignalR connection:", error);
});
2024-01-17 15:11:31 +01:00
2024-01-22 16:09:02 +01:00
connection.onclose((error) => {
console.log("SignalR connection closed:", error);
});
2024-01-17 15:11:31 +01:00
2024-01-17 10:25:16 +01:00
}
}