Skip to content

Commit

Permalink
feat: add chat message event listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
getinnocuous committed Aug 9, 2024
1 parent 9f0f0cc commit bb811f4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions src/gateway-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
BookmarkStoreResultEvent,
SnapshotLoadResultEvent,
SnapshotStoreResultEvent,
ChatMessageResultEvent,
} from './events'
import {
Edge,
Expand All @@ -33,6 +34,7 @@ import {
SnapshotLoadResult,
StoreBookmark,
StoreSnapshot,
ChatMessageResult,
} from './protobuf'

export interface CustomEventListener<T> {
Expand Down Expand Up @@ -309,6 +311,14 @@ export class GatewaySession extends EventTarget {
)
break
}
case 'chatMessageResult': {
this.dispatchEvent(
new CustomEvent<ChatMessageResult>(ChatMessageResultEvent, {
detail: response.responseType.value,
}),
)
break
}
default: {
break
}
Expand Down Expand Up @@ -375,6 +385,12 @@ export class GatewaySession extends EventTarget {
options?: boolean | AddEventListenerOptions | undefined,
): void

addEventListener(
type: typeof ChatMessageResultEvent,
callback: CustomEventListenerOrEventListenerObject<ChatMessageResult> | null,
options?: boolean | AddEventListenerOptions | undefined,
): void

addEventListener(
type: typeof QueryStatusEvent,
callback: CustomEventListenerOrEventListenerObject<QueryStatus> | null,
Expand Down Expand Up @@ -473,6 +489,12 @@ export class GatewaySession extends EventTarget {
options?: boolean | AddEventListenerOptions | undefined,
): void

removeEventListener(
type: typeof ChatMessageResultEvent,
callback: CustomEventListenerOrEventListenerObject<ChatMessageResult> | null,
options?: boolean | AddEventListenerOptions | undefined,
): void

removeEventListener(
type: typeof QueryStatusEvent,
callback: CustomEventListenerOrEventListenerObject<QueryStatus> | null,
Expand Down

0 comments on commit bb811f4

Please sign in to comment.