2021-06-12 15:13:13 +02:00
|
|
|
import EventEmitter from 'events';
|
2021-05-19 12:55:10 +02:00
|
|
|
|
2021-05-23 16:07:23 +02:00
|
|
|
namespace ImplementableApi {
|
|
|
|
export type Config = {
|
|
|
|
name: string;
|
2021-06-12 15:13:13 +02:00
|
|
|
};
|
2021-05-19 12:55:10 +02:00
|
|
|
|
2021-05-23 16:07:23 +02:00
|
|
|
/**
|
|
|
|
* [optional] idListener is the way to identificate the listener who's the src of the newEntries
|
|
|
|
* the type field permit to know which type of message it is
|
2021-06-12 15:13:13 +02:00
|
|
|
* rawContent field is the string content of the message
|
2021-05-23 16:07:23 +02:00
|
|
|
*/
|
|
|
|
export type Message = {
|
|
|
|
idListener?: number;
|
2021-06-12 15:13:13 +02:00
|
|
|
type: 'newEntriesNotify' | 'newListener';
|
2021-05-23 16:07:23 +02:00
|
|
|
rawContent: any;
|
2021-06-12 15:13:13 +02:00
|
|
|
};
|
2021-05-23 16:07:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
abstract class ImplementableApi extends EventEmitter {
|
|
|
|
readonly name: string;
|
|
|
|
|
|
|
|
constructor(readonly config: ImplementableApi.Config) {
|
|
|
|
super();
|
|
|
|
this.name = config.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract receivedMessage(message: ImplementableApi.Message): void;
|
|
|
|
}
|
|
|
|
|
2021-06-12 15:13:13 +02:00
|
|
|
export { ImplementableApi };
|