partey_workadventure/pusher/src/Services/ApiClientRepository.ts

27 lines
832 B
TypeScript
Raw Normal View History

/**
* 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('')];
}
}
const apiClientRepository = new ApiClientRepository();
export { apiClientRepository };