Skip to content

Commit

Permalink
fix: Fix WebSocket to send subscribe event before unsubscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
neet committed Oct 21, 2024
1 parent 7110ad0 commit aa47a3b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/adapters/ws/web-socket-subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export class WebSocketSubscription implements mastodon.streaming.Subscription {
) {}

async *values(): AsyncIterableIterator<mastodon.streaming.Event> {
try {
this.logger?.log("info", "Subscribing to stream", this.stream);
this.logger?.log("info", "Subscribing to stream", this.stream);

try {
for await (this.connection of this.connector) {
const data = this.serializer.serialize("json", {
type: "subscribe",
Expand All @@ -46,7 +46,10 @@ export class WebSocketSubscription implements mastodon.streaming.Subscription {
continue;
}

this.logger?.log("debug", "↓ WEBSOCKET", event);
this.logger?.log(
"info",
`↓ WEBSOCKET ${JSON.stringify(event).slice(0, 100)}`,
);
yield event;
}
}
Expand All @@ -69,6 +72,10 @@ export class WebSocketSubscription implements mastodon.streaming.Subscription {
...this.params,
});

this.logger?.log(
"info",
`↑ WEBSOCKET ${JSON.stringify(data).slice(0, 100)}`,
);
this.connection.send(data);
}

Expand Down

0 comments on commit aa47a3b

Please sign in to comment.