| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- export module Interfaces {
- export interface LoggerInterface {
- debug(message);
- error(message);
- }
- export interface ApiConnectorInterface {
- execute(endpointPath: string, data: any): Promise<string>;
- }
- export interface ClientInterface {
- id: string;
- coefficient: number;
- status: boolean;
- name: string;
- photo: string;
- payedTime: number;
- timeToPay: number;
- conversations: { [id: string]: ConversationInterface }
- send(event: string, data: {});
- addSocket(socket: SocketIO.Socket);
- sendMessage(messageData);
- }
- export interface ClientsManagerInterface {
- get(id: string): Promise<ClientInterface>
- add(socket: SocketIO.Socket, data);
- }
- export interface ConversationsManagerInterface {
- get(id: string): Promise<ConversationInterface>;
- add(conversation: ConversationInterface);
- remove(id: string);
- create(initiator: ClientInterface, recipient: ClientInterface): Promise<ConversationInterface>;
- }
- export interface ConversationInterface {
- id: string;
- duration: number;
- state: ConversationState;
- getInitiator(): ClientInterface;
- getRecipient(): ClientInterface;
- newMessage(message, from, to);
- }
- export class ConversationState {
- private value;
- private constructor(state) {
- if (ConversationState.availableStates().indexOf(state) < 0) {
- throw new Error(`State "${state}" is not valid value`);
- }
- this.value = state;
- }
- toString() {
- return this.value;
- }
- public isEqualsTo(state: ConversationState) {
- return this.value === state.value;
- }
- static create(state) {
- return new ConversationState(state);
- }
- private static availableStates() {
- return ['init', 'running', 'stopped', 'paused'];
- }
- static INIT() {
- return ConversationState.create('init');
- }
- static RUNNING() {
- return ConversationState.create('running');
- }
- static STOPPED() {
- return ConversationState.create('stopped');
- }
- static PAUSED() {
- return ConversationState.create('paused');
- }
- }
- export class AppMode {
- private value;
- private constructor(mode) {
- this.value = mode;
- }
- toString() {
- return this.value;
- }
- public isEqualsTo(mode: AppMode) {
- return this.value === mode.value;
- }
- static create(mode) {
- if (AppMode.availableModes().indexOf(mode) < 0) {
- throw new Error(`Mode "${mode}" is not valid value`);
- }
- return new AppMode(mode);
- }
- private static availableModes() {
- return ['dev', 'prod'];
- }
- static DEV() {
- return AppMode.create('dev');
- }
- static PROD() {
- return AppMode.create('prod');
- }
- }
- }
|