From bb811f4f137bc3c0972eb79596e6fec88ea964d5 Mon Sep 17 00:00:00 2001 From: Elliot Waddington Date: Fri, 9 Aug 2024 14:50:45 +0200 Subject: [PATCH] feat: add chat message event listeners --- package.json | 2 +- src/events.ts | 5 +++++ src/gateway-session.ts | 22 ++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 1dcfa55..ab55fa9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@overmindtech/sdp-js", - "version": "9.2.0", + "version": "9.3.0", "description": "Javascript and Typescript libraries for the State Description Protocol", "license": "MIT", "sideEffects": false, diff --git a/src/events.ts b/src/events.ts index 6515e3d..50af720 100644 --- a/src/events.ts +++ b/src/events.ts @@ -61,6 +61,11 @@ export const SnapshotLoadResultEvent = 'snapshot-load-result' */ export const QueryStatusEvent = 'query-status' +/** + * This event informs the client of chat message response + */ +export const ChatMessageResultEvent = 'chat-message-result' + /** * This event means that an error was encountered by one of the responders * when responding to the request. This could indicate a failure, or might diff --git a/src/gateway-session.ts b/src/gateway-session.ts index 6b5e3d6..485d48d 100644 --- a/src/gateway-session.ts +++ b/src/gateway-session.ts @@ -15,6 +15,7 @@ import { BookmarkStoreResultEvent, SnapshotLoadResultEvent, SnapshotStoreResultEvent, + ChatMessageResultEvent, } from './events' import { Edge, @@ -33,6 +34,7 @@ import { SnapshotLoadResult, StoreBookmark, StoreSnapshot, + ChatMessageResult, } from './protobuf' export interface CustomEventListener { @@ -309,6 +311,14 @@ export class GatewaySession extends EventTarget { ) break } + case 'chatMessageResult': { + this.dispatchEvent( + new CustomEvent(ChatMessageResultEvent, { + detail: response.responseType.value, + }), + ) + break + } default: { break } @@ -375,6 +385,12 @@ export class GatewaySession extends EventTarget { options?: boolean | AddEventListenerOptions | undefined, ): void + addEventListener( + type: typeof ChatMessageResultEvent, + callback: CustomEventListenerOrEventListenerObject | null, + options?: boolean | AddEventListenerOptions | undefined, + ): void + addEventListener( type: typeof QueryStatusEvent, callback: CustomEventListenerOrEventListenerObject | null, @@ -473,6 +489,12 @@ export class GatewaySession extends EventTarget { options?: boolean | AddEventListenerOptions | undefined, ): void + removeEventListener( + type: typeof ChatMessageResultEvent, + callback: CustomEventListenerOrEventListenerObject | null, + options?: boolean | AddEventListenerOptions | undefined, + ): void + removeEventListener( type: typeof QueryStatusEvent, callback: CustomEventListenerOrEventListenerObject | null,