Skip to content

Commit

Permalink
clients: js: ws: fix ack events not emitted parsed responses
Browse files Browse the repository at this point in the history
  • Loading branch information
turtleDev committed Sep 30, 2024
1 parent 980e1e8 commit d0b0ed0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
5 changes: 3 additions & 2 deletions clients/js/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import createProtoMarshaller from './wire/proto_wire.js';
import createJsonMarshaller from './wire/json_wire.js';
import { raystack, google } from '../protos/proton_compiled.js';
import EventEmitter from 'events';
import WebSocket from 'ws';

const NANOSECONDS_PER_MILLISECOND = 1e6;

Expand Down Expand Up @@ -65,7 +66,6 @@ class RaccoonClient extends EventEmitter {
}

initializeWebSocket() {
const WebSocket = require('ws');
this.wsClient = new WebSocket(this.url);
this.wsClient.on('open', () => {
this.logger.info('WebSocket connection established');
Expand All @@ -75,8 +75,9 @@ class RaccoonClient extends EventEmitter {
});
this.wsClient.on('message', (data) => {
try {
const response = JSON.parse(data);
const sendEventResponse = this.marshaller.unmarshal(
data,
response,
raystack.raccoon.v1beta1.SendEventResponse
);
this.emit('ack', sendEventResponse.toJSON());
Expand Down
27 changes: 24 additions & 3 deletions clients/js/package-lock.json

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

3 changes: 2 additions & 1 deletion clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"dependencies": {
"axios": "^1.4.0",
"protobufjs": "^7.2.4",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"ws": "^8.18.0"
},
"devDependencies": {
"eslint": "^8.47.0",
Expand Down

0 comments on commit d0b0ed0

Please sign in to comment.