Skip to content

Commit af0bfbc

Browse files
committed
feat: added events for connection recv/send and stream readable/writable
[ci skip]
1 parent ff2e533 commit af0bfbc

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

src/QUICConnection.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ class QUICConnection extends EventTarget {
451451
}
452452
return;
453453
}
454+
this.dispatchEvent(new events.QUICConnectionRecvEvent());
454455
// Here we can resolve our promises!
455456
if (this.conn.isEstablished()) {
456457
this.resolveEstablishedP();
@@ -482,6 +483,7 @@ class QUICConnection extends EventTarget {
482483
);
483484
}
484485
quicStream.read();
486+
quicStream.dispatchEvent(new events.QUICStreamReadableEvent());
485487
}
486488
for (const streamId of this.conn.writable() as Iterable<StreamId>) {
487489
let quicStream = this.streamMap.get(streamId);
@@ -500,6 +502,7 @@ class QUICConnection extends EventTarget {
500502
new events.QUICConnectionStreamEvent({ detail: quicStream }),
501503
);
502504
}
505+
quicStream.dispatchEvent(new events.QUICStreamWritableEvent());
503506
quicStream.write();
504507
}
505508
// Checking shortlist if streams have finished.
@@ -626,6 +629,7 @@ class QUICConnection extends EventTarget {
626629
);
627630
return;
628631
}
632+
this.dispatchEvent(new events.QUICConnectionSendEvent());
629633
}
630634
} finally {
631635
this.logger.debug('SEND FINALLY');

src/QUICStream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class QUICStream
5757

5858
/**
5959
* For `reasonToCode`, return 0 means "unknown reason"
60-
* It is the catch all for codes.
60+
* It is the catch-all for codes.
6161
* So it is the default reason.
6262
*
6363
* It may receive any reason for cancellation.

src/events.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ class QUICConnectionStreamEvent extends Event {
7171
}
7272
}
7373

74+
class QUICConnectionSendEvent extends Event {
75+
constructor(options?: EventInit) {
76+
super('send', options);
77+
}
78+
}
79+
80+
class QUICConnectionRecvEvent extends Event {
81+
constructor(options?: EventInit) {
82+
super('recv', options);
83+
}
84+
}
85+
7486
class QUICConnectionDestroyEvent extends Event {
7587
constructor(options?: EventInit) {
7688
super('destroy', options);
@@ -89,18 +101,17 @@ class QUICConnectionErrorEvent extends Event {
89101
}
90102
}
91103

92-
// TODO: use these or remove them
93-
// class QUICStreamReadableEvent extends Event {
94-
// constructor(options?: EventInit) {
95-
// super('readable', options);
96-
// }
97-
// }
98-
//
99-
// class QUICStreamWritableEvent extends Event {
100-
// constructor(options?: EventInit) {
101-
// super('writable', options);
102-
// }
103-
// }
104+
class QUICStreamReadableEvent extends Event {
105+
constructor(options?: EventInit) {
106+
super('readable', options);
107+
}
108+
}
109+
110+
class QUICStreamWritableEvent extends Event {
111+
constructor(options?: EventInit) {
112+
super('writable', options);
113+
}
114+
}
104115

105116
class QUICStreamDestroyEvent extends Event {
106117
constructor(options?: EventInit) {
@@ -133,8 +144,12 @@ export {
133144
QUICServerStopEvent,
134145
QUICServerErrorEvent,
135146
QUICConnectionStreamEvent,
147+
QUICConnectionSendEvent,
148+
QUICConnectionRecvEvent,
136149
QUICConnectionDestroyEvent,
137150
QUICConnectionErrorEvent,
151+
QUICStreamReadableEvent,
152+
QUICStreamWritableEvent,
138153
QUICStreamDestroyEvent,
139154
QUICClientDestroyEvent,
140155
QUICClientErrorEvent,

0 commit comments

Comments
 (0)