1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* import-globals-from head_cookies.js */
9 let WebTransportListener = function () {};
11 WebTransportListener.prototype = {
12 onSessionReady(sessionId) {
13 info("SessionId " + sessionId);
16 onSessionClosed(errorCode, reason) {
17 info("Error: " + errorCode + " reason: " + reason);
22 onIncomingBidirectionalStreamAvailable(stream) {
23 info("got incoming bidirectional stream");
24 this.streamAvailable(stream);
26 onIncomingUnidirectionalStreamAvailable(stream) {
27 info("got incoming unidirectional stream");
28 this.streamAvailable(stream);
30 onDatagramReceived(data) {
32 if (this.onDatagram) {
33 this.onDatagram(data);
36 onMaxDatagramSize(size) {
37 info("max datagram size: " + size);
38 if (this.onMaxDatagramSize) {
39 this.onMaxDatagramSize(size);
42 onOutgoingDatagramOutCome(id, outcome) {
43 if (this.onDatagramOutcome) {
44 this.onDatagramOutcome({ id, outcome });
48 QueryInterface: ChromeUtils.generateQI(["WebTransportSessionEventListener"]),
51 function WebTransportStreamCallback() {}
53 WebTransportStreamCallback.prototype = {
54 QueryInterface: ChromeUtils.generateQI(["nsIWebTransportStreamCallback"]),
56 onBidirectionalStreamReady(aStream) {
57 Assert.ok(aStream != null);
60 onUnidirectionalStreamReady(aStream) {
61 Assert.ok(aStream != null);
69 function StreamStatsCallback() {}
71 StreamStatsCallback.prototype = {
72 QueryInterface: ChromeUtils.generateQI([
73 "nsIWebTransportStreamStatsCallback",
76 onSendStatsAvailable(aStats) {
77 Assert.ok(aStats != null);
80 onReceiveStatsAvailable(aStats) {
81 Assert.ok(aStats != null);
86 function inputStreamReader() {}
88 inputStreamReader.prototype = {
89 QueryInterface: ChromeUtils.generateQI(["nsIInputStreamCallback"]),
91 onInputStreamReady(input) {
92 let data = NetUtil.readInputStreamToString(input, input.available());
97 function streamCreatePromise(transport, bidi) {
98 return new Promise(resolve => {
99 let listener = new WebTransportStreamCallback().QueryInterface(
100 Ci.nsIWebTransportStreamCallback
102 listener.finish = resolve;
105 transport.createOutgoingBidirectionalStream(listener);
107 transport.createOutgoingUnidirectionalStream(listener);
112 function sendStreamStatsPromise(stream) {
113 return new Promise(resolve => {
114 let listener = new StreamStatsCallback().QueryInterface(
115 Ci.nsIWebTransportStreamStatsCallback
117 listener.finish = resolve;
119 stream.QueryInterface(Ci.nsIWebTransportSendStream);
120 stream.getSendStreamStats(listener);
124 function receiveStreamStatsPromise(stream) {
125 return new Promise(resolve => {
126 let listener = new StreamStatsCallback().QueryInterface(
127 Ci.nsIWebTransportStreamStatsCallback
129 listener.finish = resolve;
131 stream.QueryInterface(Ci.nsIWebTransportReceiveStream);
132 stream.getReceiveStreamStats(listener);