2024-06-04 13:12:38 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2024-06-13 12:11:17 +01:00
|
|
|
import { err, ok } from 'neverthrow';
|
2024-07-11 10:28:21 +01:00
|
|
|
import { WebSocketMessage, WebSocketService } from '../../../infra/socket/socket';
|
|
|
|
|
import { SignalRService } from '../../../infra/socket/signal-r.service';
|
2024-06-04 13:12:38 +01:00
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class MessageLiveDataSourceService {
|
|
|
|
|
|
2024-07-11 10:28:21 +01:00
|
|
|
constructor(
|
|
|
|
|
public socket: WebSocketService,
|
|
|
|
|
private signalR: SignalRService) {}
|
2024-06-04 13:12:38 +01:00
|
|
|
|
2024-06-13 12:11:17 +01:00
|
|
|
async sendMessage(data: WebSocketMessage) {
|
2024-06-04 13:12:38 +01:00
|
|
|
|
2024-06-13 12:11:17 +01:00
|
|
|
try {
|
2024-07-11 10:28:21 +01:00
|
|
|
|
2024-06-13 12:11:17 +01:00
|
|
|
const result = await this.socket.sendMessage(data).toPromise()
|
2024-06-04 13:12:38 +01:00
|
|
|
|
2024-06-13 12:11:17 +01:00
|
|
|
return ok(result)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
return err(e)
|
|
|
|
|
}
|
2024-06-04 13:12:38 +01:00
|
|
|
|
|
|
|
|
}
|
2024-06-13 12:11:17 +01:00
|
|
|
|
2024-07-11 10:28:21 +01:00
|
|
|
}
|