2020-11-13 18:00:22 +01:00
|
|
|
/**
|
|
|
|
* A class to get connections to the correct "api" server given a room name.
|
|
|
|
*/
|
|
|
|
import {RoomManagerClient} from "../Messages/generated/messages_grpc_pb";
|
|
|
|
import grpc from 'grpc';
|
|
|
|
import {API_URL} from "../Enum/EnvironmentVariable";
|
|
|
|
|
|
|
|
|
|
|
|
class ApiClientRepository {
|
|
|
|
private roomManagerClient: RoomManagerClient|null = null;
|
|
|
|
|
|
|
|
public async getClient(roomId: string): Promise<RoomManagerClient> {
|
|
|
|
if (this.roomManagerClient === null) {
|
|
|
|
this.roomManagerClient = new RoomManagerClient(API_URL, grpc.credentials.createInsecure());
|
|
|
|
}
|
|
|
|
return Promise.resolve(this.roomManagerClient);
|
|
|
|
}
|
2020-12-11 12:23:50 +01:00
|
|
|
|
|
|
|
public async getAllClients(): Promise<RoomManagerClient[]> {
|
|
|
|
return [await this.getClient('')];
|
|
|
|
}
|
2020-11-13 18:00:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const apiClientRepository = new ApiClientRepository();
|
|
|
|
|
|
|
|
export { apiClientRepository };
|