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';
|
|
|
|
|
import { WebSocketMessage, WebSocketService } from '../../infra/socket/socket';
|
2024-06-04 13:12:38 +01:00
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class MessageLiveDataSourceService {
|
|
|
|
|
|
2024-06-13 12:11:17 +01:00
|
|
|
constructor(public socket: WebSocketService) {}
|
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 {
|
|
|
|
|
|
|
|
|
|
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-06-12 15:20:07 +01:00
|
|
|
}
|