@@ -26,8 +26,6 @@ export class WebSocketSubscription implements mastodon.streaming.Subscription {
2626 while ( this . connector . canAcquire ( ) ) {
2727 this . connection = await this . connector . acquire ( ) ;
2828
29- const messages = toAsyncIterable ( this . connection ) ;
30-
3129 const data = this . serializer . serialize ( "json" , {
3230 type : "subscribe" ,
3331 stream : this . stream ,
@@ -37,8 +35,15 @@ export class WebSocketSubscription implements mastodon.streaming.Subscription {
3735 this . logger ?. log ( "debug" , "↑ WEBSOCKET" , data ) ;
3836 this . connection . send ( data ) ;
3937
40- for await ( const event of this . transformIntoEvents ( messages ) ) {
41- if ( ! this . matches ( event ) ) continue ;
38+ const messages = toAsyncIterable ( this . connection ) ;
39+
40+ for await ( const message of messages ) {
41+ const event = await this . parseMessage ( message . data as string ) ;
42+
43+ if ( ! this . test ( event ) ) {
44+ continue ;
45+ }
46+
4247 this . logger ?. log ( "debug" , "↓ WEBSOCKET" , event ) ;
4348 yield event ;
4449 }
@@ -70,7 +75,7 @@ export class WebSocketSubscription implements mastodon.streaming.Subscription {
7075 this . unsubscribe ( ) ;
7176 }
7277
73- private matches ( event : mastodon . streaming . Event ) : boolean {
78+ private test ( event : mastodon . streaming . Event ) : boolean {
7479 // subscribe("hashtag", { tag: "foo" }) -> ["hashtag", "foo"]
7580 // subscribe("list", { list: "foo" }) -> ["list", "foo"]
7681 const params = this . params ?? { } ;
@@ -79,15 +84,6 @@ export class WebSocketSubscription implements mastodon.streaming.Subscription {
7984 return stream . every ( ( s ) => event . stream . includes ( s ) ) ;
8085 }
8186
82- private async * transformIntoEvents (
83- messages : AsyncIterable < WebSocket . MessageEvent > ,
84- ) {
85- for await ( const message of messages ) {
86- const event = await this . parseMessage ( message . data as string ) ;
87- yield event ;
88- }
89- }
90-
9187 private async parseMessage (
9288 rawEvent : string ,
9389 ) : Promise < mastodon . streaming . Event > {
0 commit comments