Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"README.md"
],
"main": "lib/index.js",
"version": "8.0.0-rc",
"version": "8.4.0-rc",
"devDependencies": {
"@types/assert": "^1.5.6",
"@types/chai": "^4.3.3",
Expand Down
22 changes: 19 additions & 3 deletions nodejs/src/events/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ export class EventsBase<PluginConfigType extends IPluginConfig = any>
constructor(pluginName: string, cwd: string,pluginCwd: string, log: IPluginLogger) {
super(pluginName, cwd, pluginCwd, log);
}
public async onEvent(
public async onBroadcast(
callerPluginName: string,
pluginName: string,
event: string,
listener: { (args: Array<any>): Promise<void> }
): Promise<void> {
throw ErrorMessages.EventsNotImplementedProperly;
}
public async onReturnableEvent(
public async emitBroadcast(
callerPluginName: string,
pluginName: string,
event: string,
listener: { (args: Array<any>): Promise<any> }
args: Array<any>
): Promise<void> {
throw ErrorMessages.EventsNotImplementedProperly;
}
public async onEvent(
callerPluginName: string,
pluginName: string,
event: string,
listener: { (args: Array<any>): Promise<void> }
): Promise<void> {
throw ErrorMessages.EventsNotImplementedProperly;
}
Expand All @@ -34,6 +42,14 @@ export class EventsBase<PluginConfigType extends IPluginConfig = any>
): Promise<void> {
throw ErrorMessages.EventsNotImplementedProperly;
}
public async onReturnableEvent(
callerPluginName: string,
pluginName: string,
event: string,
listener: { (args: Array<any>): Promise<any> }
): Promise<void> {
throw ErrorMessages.EventsNotImplementedProperly;
}
public async emitEventAndReturn(
callerPluginName: string,
pluginName: string,
Expand Down
17 changes: 16 additions & 1 deletion nodejs/src/interfaces/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,23 @@ export interface IServiceEvents<
onEvents,
emitEvents,
onReturnableEvents,
emitReturnableEvents
emitReturnableEvents,
onBroadcast,
emitBroadcast,
> {
onBroadcast<TA extends string>(
...args: DynamicallyReferencedMethodOnIEvents<
DynamicallyReferencedMethodType<onBroadcast>,
TA,
false
>
): Promise<void>;
emitBroadcast<TA extends string>(
...args: DynamicallyReferencedMethodEmitIEvents<
DynamicallyReferencedMethodType<emitBroadcast>,
TA
>
): Promise<void>;
onEvent<TA extends string>(
...args: DynamicallyReferencedMethodOnIEvents<
DynamicallyReferencedMethodType<onEvents>,
Expand Down
8 changes: 6 additions & 2 deletions nodejs/src/interfaces/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ export interface IService<
onEvents,
emitEvents,
onReturnableEvents,
emitReturnableEvents
emitReturnableEvents,
onBroadcast,
emitBroadcast
> extends IServiceEvents<
onEvents,
emitEvents,
onReturnableEvents,
emitReturnableEvents
emitReturnableEvents,
onBroadcast,
emitBroadcast
> {
initIndex?: number;
init?(): Promise<void>;
Expand Down
40 changes: 40 additions & 0 deletions nodejs/src/plugins/events-default/events/broadcast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { EventEmitter } from "events";
import { IPluginLogger } from '../../../interfaces/logger';

export default class broadcast extends EventEmitter {
private log: IPluginLogger;

constructor(log: IPluginLogger) {
super();
this.log = log;
}
public dispose() {
this.removeAllListeners();
}

public async onBroadcast(
callerPluginName: string,
pluginName: string,
event: string,
listener: { (args: Array<any>): Promise<void> }
): Promise<void> {
await this.log.debug(
"onBroadcast: {callerPluginName} listening to {pluginName}-{event}",
{ callerPluginName, pluginName, event }
);
this.on(`${pluginName}-${event}`, listener);
}

public async emitBroadcast(
callerPluginName: string,
pluginName: string,
event: string,
args: Array<any>
): Promise<void> {
await this.log.debug(
"emitBroadcast: {callerPluginName} emitting {pluginName}-{event}",
{ callerPluginName, pluginName, event }
);
this.emit(`${pluginName}-${event}`, args);
}
}
21 changes: 21 additions & 0 deletions nodejs/src/plugins/events-default/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import emitAndReturn from "./events/emitAndReturn";
import emitStreamAndReceiveStream from "./events/emitStreamAndReceiveStream";
import { EventsBase } from "../../events/events";
import { PluginConfig } from "./sec.config";
import broadcast from './events/broadcast';

export class Events extends EventsBase<PluginConfig> {
protected broadcast!: broadcast;
protected emit!: emit;
protected ear!: emitAndReturn;
protected eas!: emitStreamAndReceiveStream;
Expand All @@ -19,17 +21,36 @@ export class Events extends EventsBase<PluginConfig> {
) {
super(pluginName, cwd, pluginCwd, log);

this.broadcast = new broadcast(log);
this.emit = new emit(log);
this.ear = new emitAndReturn(log);
this.eas = new emitStreamAndReceiveStream(log);
}

public dispose() {
this.broadcast.dispose();
this.emit.dispose();
this.ear.dispose();
this.eas.dispose();
}

public async onBroadcast(
callerPluginName: string,
pluginName: string,
event: string,
listener: { (args: Array<any>): Promise<void> }
): Promise<void> {
await this.broadcast.onBroadcast(callerPluginName, pluginName, event, listener);
}
public async emitBroadcast(
callerPluginName: string,
pluginName: string,
event: string,
args: Array<any>
): Promise<void> {
await this.broadcast.emitBroadcast(callerPluginName, pluginName, event, args);
}

public async onEvent(
callerPluginName: string,
pluginName: string,
Expand Down
1 change: 1 addition & 0 deletions nodejs/src/service/base.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface ServiceEvents {}
export interface ServiceBroadcasts {}
export interface ServiceReturnableEvents {}
export interface ServiceCallable {}
54 changes: 45 additions & 9 deletions nodejs/src/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import {
ServiceCallable,
ServiceEvents,
ServiceBroadcasts,
ServiceReturnableEvents,
} from "./base";

Expand All @@ -23,11 +24,20 @@ export class ServicesBase<
onReturnableEvents = ServiceReturnableEvents,
emitReturnableEvents = ServiceReturnableEvents,
callableMethods = ServiceCallable,
pluginConfigType extends IPluginConfig = any
pluginConfigType extends IPluginConfig = any,
onBroadcast = ServiceBroadcasts,
emitBroadcast = ServiceBroadcasts
>
extends DefaultBase<pluginConfigType>
implements
IService<onEvents, emitEvents, onReturnableEvents, emitReturnableEvents>
IService<
onEvents,
emitEvents,
onReturnableEvents,
emitReturnableEvents,
onBroadcast,
emitBroadcast
>
{
public readonly initBeforePlugins?: Array<string>;
public readonly initAfterPlugins?: Array<string>;
Expand All @@ -42,7 +52,9 @@ export class ServicesBase<
pluginClientOnReturnableEvents,
pluginClientEmitReturnableEvents,
pluginCallableMethods,
pluginClientConfigType extends IPluginConfig
pluginClientConfigType extends IPluginConfig,
pluginClientOnBroadcast,
pluginClientEmitBroadcast
>(
pluginName: string
): Promise<
Expand All @@ -52,7 +64,9 @@ export class ServicesBase<
pluginClientOnReturnableEvents,
pluginClientEmitReturnableEvents,
pluginCallableMethods,
pluginClientConfigType
pluginClientConfigType,
pluginClientOnBroadcast,
pluginClientEmitBroadcast
>
> {
throw ErrorMessages.BSBNotInit;
Expand All @@ -76,6 +90,23 @@ export class ServicesBase<
sendStream(streamId: string, stream: Readable): Promise<void> {
throw ErrorMessages.BSBNotInit;
}
onBroadcast<TA extends string>(
...args: DynamicallyReferencedMethodOnIEvents<
DynamicallyReferencedMethodType<onBroadcast>,
TA,
false
>
): Promise<void> {
throw ErrorMessages.BSBNotInit;
}
emitBroadcast<TA extends string>(
...args: DynamicallyReferencedMethodEmitIEvents<
DynamicallyReferencedMethodType<emitBroadcast>,
TA
>
): Promise<void> {
throw ErrorMessages.BSBNotInit;
}
onEvent<TA extends string>(
...args: DynamicallyReferencedMethodOnIEvents<
DynamicallyReferencedMethodType<onEvents>,
Expand All @@ -85,7 +116,8 @@ export class ServicesBase<
): Promise<void> {
throw ErrorMessages.BSBNotInit;
}
onEventSpecific<TA extends string>(serverId: string,
onEventSpecific<TA extends string>(
serverId: string,
...args: DynamicallyReferencedMethodOnIEvents<
DynamicallyReferencedMethodType<onEvents>,
TA,
Expand All @@ -102,7 +134,8 @@ export class ServicesBase<
): Promise<void> {
throw ErrorMessages.BSBNotInit;
}
emitEventSpecific<TA extends string>(serverId: string,
emitEventSpecific<TA extends string>(
serverId: string,
...args: DynamicallyReferencedMethodEmitIEvents<
DynamicallyReferencedMethodType<emitEvents>,
TA
Expand All @@ -119,7 +152,8 @@ export class ServicesBase<
): Promise<void> {
throw ErrorMessages.BSBNotInit;
}
onReturnableEventSpecific<TA extends string>(serverId: string,
onReturnableEventSpecific<TA extends string>(
serverId: string,
...args: DynamicallyReferencedMethodOnIEvents<
DynamicallyReferencedMethodType<onReturnableEvents>,
TA,
Expand All @@ -142,7 +176,8 @@ export class ServicesBase<
> {
throw ErrorMessages.BSBNotInit;
}
emitEventAndReturnSpecific<TA extends string>(serverId: string,
emitEventAndReturnSpecific<TA extends string>(
serverId: string,
...args: DynamicallyReferencedMethodEmitEARIEvents<
DynamicallyReferencedMethodType<emitReturnableEvents>,
TA,
Expand Down Expand Up @@ -170,7 +205,8 @@ export class ServicesBase<
> {
throw ErrorMessages.BSBNotInit;
}
emitEventAndReturnTimedSpecific<TA extends string>(serverId: string,
emitEventAndReturnTimedSpecific<TA extends string>(
serverId: string,
...args: DynamicallyReferencedMethodEmitEARIEvents<
DynamicallyReferencedMethodType<emitReturnableEvents>,
TA,
Expand Down
Loading