Skip to content
Open
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
14 changes: 13 additions & 1 deletion src/OcppClientConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,18 @@ export class OcppClientConnection extends Client {
cb: (response: UrnOCPPCp220203StatusNotificationResponse) => void
) => void
): this;
on(
event: "call",
listener: (target: "cs" | "csms", message: string) => void
): this;
on(
event: "call_result",
listener: (target: "cs" | "csms", message: string) => void
): this;
on(
event: "call_error",
listener: (target: "cs" | "csms", message: string) => void
): this;
on(
event: "close",
listener: (code: number, reason: Buffer) => void
Expand Down Expand Up @@ -501,4 +513,4 @@ export class OcppClientConnection extends Client {
}
}

export default OcppClientConnection;
export default OcppClientConnection;
37 changes: 37 additions & 0 deletions src/impl/Protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,34 @@ export class Protocol {
const [messageType, ...rest] = JSON.parse(message);

if (messageType === CALL_MESSAGE && rest.length === 3) {
this.eventEmitter.emit(
"call",
"csms",
message,
);
const [messageId, action, payload] = rest;
this.onCall(
messageId,
action,
payload
);
} else if (messageType === CALLRESULT_MESSAGE && rest.length === 2) {
this.eventEmitter.emit(
"call_result",
"csms",
message
);
const [messageId, payload] = rest;
this.onCallResult(
messageId,
payload
);
} else if (messageType === CALLERROR_MESSAGE && rest.length === 3) {
this.eventEmitter.emit(
"call_error",
"csms",
message,
);
const [messageId, errorCode, errorDescription, errorDetails] = rest;
this.onCallError(
messageId,
Expand Down Expand Up @@ -81,6 +96,13 @@ export class Protocol {
messageId,
request,
payload]);

this.eventEmitter.emit(
"call",
"cs",
result,
);

this.socket.send(result);
this.pendingCalls[messageId] = {
resolve,
Expand Down Expand Up @@ -117,6 +139,13 @@ export class Protocol {
error.code,
error.message,
error.details || {}]);

this.eventEmitter.emit(
"call_error",
"cs",
result
);

this.socket.send(result);
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -220,6 +249,7 @@ export class Protocol {
new OcppError(
ERROR_INTERNALERROR,
"An internal error occurred and the receiver was not able to process the requested Action",
e,
),
);
}
Expand All @@ -238,6 +268,13 @@ export class Protocol {
CALLRESULT_MESSAGE,
messageId,
responsePayload]);

this.eventEmitter.emit(
"call_result",
"cs",
result
);

this.socket.send(result);
} catch (e) {
if (e instanceof SyntaxError) {
Expand Down