@libp2p/webrtc 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +4 -0
- package/README.md +210 -0
- package/dist/index.min.js +54 -0
- package/dist/index.min.js.map +7 -0
- package/dist/proto_ts/message.d.ts +56 -0
- package/dist/proto_ts/message.d.ts.map +1 -0
- package/dist/proto_ts/message.js +86 -0
- package/dist/proto_ts/message.js.map +1 -0
- package/dist/src/error.d.ts +54 -0
- package/dist/src/error.d.ts.map +1 -0
- package/dist/src/error.js +105 -0
- package/dist/src/error.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/maconn.d.ts +43 -0
- package/dist/src/maconn.d.ts.map +1 -0
- package/dist/src/maconn.js +29 -0
- package/dist/src/maconn.js.map +1 -0
- package/dist/src/muxer.d.ts +55 -0
- package/dist/src/muxer.d.ts.map +1 -0
- package/dist/src/muxer.js +92 -0
- package/dist/src/muxer.js.map +1 -0
- package/dist/src/options.d.ts +6 -0
- package/dist/src/options.d.ts.map +1 -0
- package/dist/src/options.js +2 -0
- package/dist/src/options.js.map +1 -0
- package/dist/src/sdp.d.ts +33 -0
- package/dist/src/sdp.d.ts.map +1 -0
- package/dist/src/sdp.js +118 -0
- package/dist/src/sdp.js.map +1 -0
- package/dist/src/stream.d.ts +141 -0
- package/dist/src/stream.d.ts.map +1 -0
- package/dist/src/stream.js +290 -0
- package/dist/src/stream.js.map +1 -0
- package/dist/src/transport.d.ts +60 -0
- package/dist/src/transport.d.ts.map +1 -0
- package/dist/src/transport.js +193 -0
- package/dist/src/transport.js.map +1 -0
- package/dist/src/util.d.ts +5 -0
- package/dist/src/util.d.ts.map +1 -0
- package/dist/src/util.js +5 -0
- package/dist/src/util.js.map +1 -0
- package/dist/stats.json +1 -0
- package/package.json +170 -0
- package/proto_ts/message.ts +105 -0
- package/src/error.ts +123 -0
- package/src/index.ts +6 -0
- package/src/maconn.ts +67 -0
- package/src/message.proto +22 -0
- package/src/muxer.ts +120 -0
- package/src/options.ts +4 -0
- package/src/sdp.ts +136 -0
- package/src/stream.ts +422 -0
- package/src/transport.ts +243 -0
- package/src/util.ts +5 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { BinaryWriteOptions } from "@protobuf-ts/runtime";
|
|
2
|
+
import type { IBinaryWriter } from "@protobuf-ts/runtime";
|
|
3
|
+
import type { BinaryReadOptions } from "@protobuf-ts/runtime";
|
|
4
|
+
import type { IBinaryReader } from "@protobuf-ts/runtime";
|
|
5
|
+
import type { PartialMessage } from "@protobuf-ts/runtime";
|
|
6
|
+
import { MessageType } from "@protobuf-ts/runtime";
|
|
7
|
+
/**
|
|
8
|
+
* @generated from protobuf message webrtc.pb.Message
|
|
9
|
+
*/
|
|
10
|
+
export interface Message {
|
|
11
|
+
/**
|
|
12
|
+
* @generated from protobuf field: optional webrtc.pb.Message.Flag flag = 1;
|
|
13
|
+
*/
|
|
14
|
+
flag?: Message_Flag;
|
|
15
|
+
/**
|
|
16
|
+
* @generated from protobuf field: optional bytes message = 2;
|
|
17
|
+
*/
|
|
18
|
+
message?: Uint8Array;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @generated from protobuf enum webrtc.pb.Message.Flag
|
|
22
|
+
*/
|
|
23
|
+
export declare enum Message_Flag {
|
|
24
|
+
/**
|
|
25
|
+
* The sender will no longer send messages on the stream.
|
|
26
|
+
*
|
|
27
|
+
* @generated from protobuf enum value: FIN = 0;
|
|
28
|
+
*/
|
|
29
|
+
FIN = 0,
|
|
30
|
+
/**
|
|
31
|
+
* The sender will no longer read messages on the stream. Incoming data is
|
|
32
|
+
* being discarded on receipt.
|
|
33
|
+
*
|
|
34
|
+
* @generated from protobuf enum value: STOP_SENDING = 1;
|
|
35
|
+
*/
|
|
36
|
+
STOP_SENDING = 1,
|
|
37
|
+
/**
|
|
38
|
+
* The sender abruptly terminates the sending part of the stream. The
|
|
39
|
+
* receiver can discard any data that it already received on that stream.
|
|
40
|
+
*
|
|
41
|
+
* @generated from protobuf enum value: RESET = 2;
|
|
42
|
+
*/
|
|
43
|
+
RESET = 2
|
|
44
|
+
}
|
|
45
|
+
declare class Message$Type extends MessageType<Message> {
|
|
46
|
+
constructor();
|
|
47
|
+
create(value?: PartialMessage<Message>): Message;
|
|
48
|
+
internalBinaryRead(reader: IBinaryReader, length: number, options: BinaryReadOptions, target?: Message): Message;
|
|
49
|
+
internalBinaryWrite(message: Message, writer: IBinaryWriter, options: BinaryWriteOptions): IBinaryWriter;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @generated MessageType for protobuf message webrtc.pb.Message
|
|
53
|
+
*/
|
|
54
|
+
export declare const Message: Message$Type;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=message.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../proto_ts/message.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD;;GAEG;AACH,MAAM,WAAW,OAAO;IACpB;;OAEG;IACH,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC;CACxB;AACD;;GAEG;AACH,oBAAY,YAAY;IACpB;;;;OAIG;IACH,GAAG,IAAI;IACP;;;;;OAKG;IACH,YAAY,IAAI;IAChB;;;;;OAKG;IACH,KAAK,IAAI;CACZ;AAED,cAAM,YAAa,SAAQ,WAAW,CAAC,OAAO,CAAC;;IAO3C,MAAM,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO;IAOhD,kBAAkB,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,OAAO;IAsBhH,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,kBAAkB,GAAG,aAAa;CAY3G;AACD;;GAEG;AACH,eAAO,MAAM,OAAO,cAAqB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { WireType } from "@protobuf-ts/runtime";
|
|
2
|
+
import { UnknownFieldHandler } from "@protobuf-ts/runtime";
|
|
3
|
+
import { reflectionMergePartial } from "@protobuf-ts/runtime";
|
|
4
|
+
import { MESSAGE_TYPE } from "@protobuf-ts/runtime";
|
|
5
|
+
import { MessageType } from "@protobuf-ts/runtime";
|
|
6
|
+
/**
|
|
7
|
+
* @generated from protobuf enum webrtc.pb.Message.Flag
|
|
8
|
+
*/
|
|
9
|
+
export var Message_Flag;
|
|
10
|
+
(function (Message_Flag) {
|
|
11
|
+
/**
|
|
12
|
+
* The sender will no longer send messages on the stream.
|
|
13
|
+
*
|
|
14
|
+
* @generated from protobuf enum value: FIN = 0;
|
|
15
|
+
*/
|
|
16
|
+
Message_Flag[Message_Flag["FIN"] = 0] = "FIN";
|
|
17
|
+
/**
|
|
18
|
+
* The sender will no longer read messages on the stream. Incoming data is
|
|
19
|
+
* being discarded on receipt.
|
|
20
|
+
*
|
|
21
|
+
* @generated from protobuf enum value: STOP_SENDING = 1;
|
|
22
|
+
*/
|
|
23
|
+
Message_Flag[Message_Flag["STOP_SENDING"] = 1] = "STOP_SENDING";
|
|
24
|
+
/**
|
|
25
|
+
* The sender abruptly terminates the sending part of the stream. The
|
|
26
|
+
* receiver can discard any data that it already received on that stream.
|
|
27
|
+
*
|
|
28
|
+
* @generated from protobuf enum value: RESET = 2;
|
|
29
|
+
*/
|
|
30
|
+
Message_Flag[Message_Flag["RESET"] = 2] = "RESET";
|
|
31
|
+
})(Message_Flag || (Message_Flag = {}));
|
|
32
|
+
// @generated message type with reflection information, may provide speed optimized methods
|
|
33
|
+
class Message$Type extends MessageType {
|
|
34
|
+
constructor() {
|
|
35
|
+
super("webrtc.pb.Message", [
|
|
36
|
+
{ no: 1, name: "flag", kind: "enum", opt: true, T: () => ["webrtc.pb.Message.Flag", Message_Flag] },
|
|
37
|
+
{ no: 2, name: "message", kind: "scalar", opt: true, T: 12 /*ScalarType.BYTES*/ }
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
create(value) {
|
|
41
|
+
const message = {};
|
|
42
|
+
globalThis.Object.defineProperty(message, MESSAGE_TYPE, { enumerable: false, value: this });
|
|
43
|
+
if (value !== undefined)
|
|
44
|
+
reflectionMergePartial(this, message, value);
|
|
45
|
+
return message;
|
|
46
|
+
}
|
|
47
|
+
internalBinaryRead(reader, length, options, target) {
|
|
48
|
+
let message = target ?? this.create(), end = reader.pos + length;
|
|
49
|
+
while (reader.pos < end) {
|
|
50
|
+
let [fieldNo, wireType] = reader.tag();
|
|
51
|
+
switch (fieldNo) {
|
|
52
|
+
case /* optional webrtc.pb.Message.Flag flag */ 1:
|
|
53
|
+
message.flag = reader.int32();
|
|
54
|
+
break;
|
|
55
|
+
case /* optional bytes message */ 2:
|
|
56
|
+
message.message = reader.bytes();
|
|
57
|
+
break;
|
|
58
|
+
default:
|
|
59
|
+
let u = options.readUnknownField;
|
|
60
|
+
if (u === "throw")
|
|
61
|
+
throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`);
|
|
62
|
+
let d = reader.skip(wireType);
|
|
63
|
+
if (u !== false)
|
|
64
|
+
(u === true ? UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return message;
|
|
68
|
+
}
|
|
69
|
+
internalBinaryWrite(message, writer, options) {
|
|
70
|
+
/* optional webrtc.pb.Message.Flag flag = 1; */
|
|
71
|
+
if (message.flag !== undefined)
|
|
72
|
+
writer.tag(1, WireType.Varint).int32(message.flag);
|
|
73
|
+
/* optional bytes message = 2; */
|
|
74
|
+
if (message.message !== undefined)
|
|
75
|
+
writer.tag(2, WireType.LengthDelimited).bytes(message.message);
|
|
76
|
+
let u = options.writeUnknownFields;
|
|
77
|
+
if (u !== false)
|
|
78
|
+
(u == true ? UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
|
|
79
|
+
return writer;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @generated MessageType for protobuf message webrtc.pb.Message
|
|
84
|
+
*/
|
|
85
|
+
export const Message = new Message$Type();
|
|
86
|
+
//# sourceMappingURL=message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../proto_ts/message.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAcnD;;GAEG;AACH,MAAM,CAAN,IAAY,YAqBX;AArBD,WAAY,YAAY;IACpB;;;;OAIG;IACH,6CAAO,CAAA;IACP;;;;;OAKG;IACH,+DAAgB,CAAA;IAChB;;;;;OAKG;IACH,iDAAS,CAAA;AACb,CAAC,EArBW,YAAY,KAAZ,YAAY,QAqBvB;AACD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,MAAM,CAAC,CAAC;QAClF,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AACD;;GAEG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import errCode from 'err-code';
|
|
2
|
+
import { Direction } from '@libp2p/interface-connection';
|
|
3
|
+
export declare enum codes {
|
|
4
|
+
ERR_ALREADY_ABORTED = "ERR_ALREADY_ABORTED",
|
|
5
|
+
ERR_DATA_CHANNEL = "ERR_DATA_CHANNEL",
|
|
6
|
+
ERR_CONNECTION_CLOSED = "ERR_CONNECTION_CLOSED",
|
|
7
|
+
ERR_HASH_NOT_SUPPORTED = "ERR_HASH_NOT_SUPPORTED",
|
|
8
|
+
ERR_INVALID_MULTIADDR = "ERR_INVALID_MULTIADDR",
|
|
9
|
+
ERR_INVALID_FINGERPRINT = "ERR_INVALID_FINGERPRINT",
|
|
10
|
+
ERR_INVALID_PARAMETERS = "ERR_INVALID_PARAMETERS",
|
|
11
|
+
ERR_NOT_IMPLEMENTED = "ERR_NOT_IMPLEMENTED",
|
|
12
|
+
ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS = "ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS",
|
|
13
|
+
ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS = "ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS"
|
|
14
|
+
}
|
|
15
|
+
export declare class WebRTCTransportError extends Error {
|
|
16
|
+
constructor(msg: string);
|
|
17
|
+
}
|
|
18
|
+
export declare class ConnectionClosedError extends WebRTCTransportError {
|
|
19
|
+
constructor(state: RTCPeerConnectionState, msg: string);
|
|
20
|
+
}
|
|
21
|
+
export declare function connectionClosedError(state: RTCPeerConnectionState, msg: string): Error & errCode.Extensions;
|
|
22
|
+
export declare class DataChannelError extends WebRTCTransportError {
|
|
23
|
+
constructor(streamLabel: string, msg: string);
|
|
24
|
+
}
|
|
25
|
+
export declare function dataChannelError(streamLabel: string, msg: string): Error & errCode.Extensions;
|
|
26
|
+
export declare class InappropriateMultiaddrError extends WebRTCTransportError {
|
|
27
|
+
constructor(msg: string);
|
|
28
|
+
}
|
|
29
|
+
export declare function inappropriateMultiaddr(msg: string): Error & errCode.Extensions;
|
|
30
|
+
export declare class InvalidArgumentError extends WebRTCTransportError {
|
|
31
|
+
constructor(msg: string);
|
|
32
|
+
}
|
|
33
|
+
export declare function invalidArgument(msg: string): Error & errCode.Extensions;
|
|
34
|
+
export declare class InvalidFingerprintError extends WebRTCTransportError {
|
|
35
|
+
constructor(fingerprint: string, source: string);
|
|
36
|
+
}
|
|
37
|
+
export declare function invalidFingerprint(fingerprint: string, source: string): Error & errCode.Extensions;
|
|
38
|
+
export declare class OperationAbortedError extends WebRTCTransportError {
|
|
39
|
+
constructor(context: string, abortReason: string);
|
|
40
|
+
}
|
|
41
|
+
export declare function operationAborted(context: string, reason: string): Error & errCode.Extensions;
|
|
42
|
+
export declare class OverStreamLimitError extends WebRTCTransportError {
|
|
43
|
+
constructor(msg: string);
|
|
44
|
+
}
|
|
45
|
+
export declare function overStreamLimit(dir: Direction, proto: string): Error & errCode.Extensions;
|
|
46
|
+
export declare class UnimplementedError extends WebRTCTransportError {
|
|
47
|
+
constructor(methodName: string);
|
|
48
|
+
}
|
|
49
|
+
export declare function unimplemented(methodName: string): Error & errCode.Extensions;
|
|
50
|
+
export declare class UnsupportedHashAlgorithmError extends WebRTCTransportError {
|
|
51
|
+
constructor(algo: string);
|
|
52
|
+
}
|
|
53
|
+
export declare function unsupportedHashAlgorithm(algorithm: string): Error & errCode.Extensions;
|
|
54
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CA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E,MAAM,EAAE,MAAM,8BAEhE;AAED,qBAAa,oBAAqB,SAAQ,oBAAoB;gBAC/C,GAAG,EAAE,MAAM;CAIzB;AAED,wBAAgB,eAAe,CAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,8BAG7D;AAED,qBAAa,kBAAmB,SAAQ,oBAAoB;gBAC7C,UAAU,EAAE,MAAM;CAIhC;AAED,wBAAgB,aAAa,CAAE,UAAU,EAAE,MAAM,8BAEhD;AAED,qBAAa,6BAA8B,SAAQ,oBAAoB;gBACxD,IAAI,EAAE,MAAM;CAK1B;AAED,wBAAgB,wBAAwB,CAAE,SAAS,EAAE,MAAM,8BAE1D"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import errCode from 'err-code';
|
|
2
|
+
import '@libp2p/interface-connection';
|
|
3
|
+
export var codes;
|
|
4
|
+
(function (codes) {
|
|
5
|
+
codes["ERR_ALREADY_ABORTED"] = "ERR_ALREADY_ABORTED";
|
|
6
|
+
codes["ERR_DATA_CHANNEL"] = "ERR_DATA_CHANNEL";
|
|
7
|
+
codes["ERR_CONNECTION_CLOSED"] = "ERR_CONNECTION_CLOSED";
|
|
8
|
+
codes["ERR_HASH_NOT_SUPPORTED"] = "ERR_HASH_NOT_SUPPORTED";
|
|
9
|
+
codes["ERR_INVALID_MULTIADDR"] = "ERR_INVALID_MULTIADDR";
|
|
10
|
+
codes["ERR_INVALID_FINGERPRINT"] = "ERR_INVALID_FINGERPRINT";
|
|
11
|
+
codes["ERR_INVALID_PARAMETERS"] = "ERR_INVALID_PARAMETERS";
|
|
12
|
+
codes["ERR_NOT_IMPLEMENTED"] = "ERR_NOT_IMPLEMENTED";
|
|
13
|
+
codes["ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS"] = "ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS";
|
|
14
|
+
codes["ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS"] = "ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS";
|
|
15
|
+
})(codes || (codes = {}));
|
|
16
|
+
export class WebRTCTransportError extends Error {
|
|
17
|
+
constructor(msg) {
|
|
18
|
+
super(`WebRTC transport error: ${msg}`);
|
|
19
|
+
this.name = 'WebRTCTransportError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class ConnectionClosedError extends WebRTCTransportError {
|
|
23
|
+
constructor(state, msg) {
|
|
24
|
+
super(`peerconnection moved to state: ${state}: ${msg}`);
|
|
25
|
+
this.name = 'WebRTC/ConnectionClosed';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export function connectionClosedError(state, msg) {
|
|
29
|
+
return errCode(new ConnectionClosedError(state, msg), codes.ERR_CONNECTION_CLOSED);
|
|
30
|
+
}
|
|
31
|
+
export class DataChannelError extends WebRTCTransportError {
|
|
32
|
+
constructor(streamLabel, msg) {
|
|
33
|
+
super(`[stream: ${streamLabel}] data channel error: ${msg}`);
|
|
34
|
+
this.name = 'WebRTC/DataChannelError';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function dataChannelError(streamLabel, msg) {
|
|
38
|
+
return errCode(new DataChannelError(streamLabel, msg), codes.ERR_DATA_CHANNEL);
|
|
39
|
+
}
|
|
40
|
+
export class InappropriateMultiaddrError extends WebRTCTransportError {
|
|
41
|
+
constructor(msg) {
|
|
42
|
+
super(`There was a problem with the Multiaddr which was passed in: ${msg}`);
|
|
43
|
+
this.name = 'WebRTC/InappropriateMultiaddrError';
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function inappropriateMultiaddr(msg) {
|
|
47
|
+
return errCode(new InappropriateMultiaddrError(msg), codes.ERR_INVALID_MULTIADDR);
|
|
48
|
+
}
|
|
49
|
+
export class InvalidArgumentError extends WebRTCTransportError {
|
|
50
|
+
constructor(msg) {
|
|
51
|
+
super(`There was a problem with a provided argument: ${msg}`);
|
|
52
|
+
this.name = 'WebRTC/InvalidArgumentError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function invalidArgument(msg) {
|
|
56
|
+
return errCode(new InvalidArgumentError(msg), codes.ERR_INVALID_PARAMETERS);
|
|
57
|
+
}
|
|
58
|
+
export class InvalidFingerprintError extends WebRTCTransportError {
|
|
59
|
+
constructor(fingerprint, source) {
|
|
60
|
+
super(`Invalid fingerprint "${fingerprint}" within ${source}`);
|
|
61
|
+
this.name = 'WebRTC/InvalidFingerprintError';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function invalidFingerprint(fingerprint, source) {
|
|
65
|
+
return errCode(new InvalidFingerprintError(fingerprint, source), codes.ERR_INVALID_FINGERPRINT);
|
|
66
|
+
}
|
|
67
|
+
export class OperationAbortedError extends WebRTCTransportError {
|
|
68
|
+
constructor(context, abortReason) {
|
|
69
|
+
super(`Signalled to abort because (${abortReason}}) ${context}`);
|
|
70
|
+
this.name = 'WebRTC/OperationAbortedError';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function operationAborted(context, reason) {
|
|
74
|
+
return errCode(new OperationAbortedError(context, reason), codes.ERR_ALREADY_ABORTED);
|
|
75
|
+
}
|
|
76
|
+
export class OverStreamLimitError extends WebRTCTransportError {
|
|
77
|
+
constructor(msg) {
|
|
78
|
+
super(msg);
|
|
79
|
+
this.name = 'WebRTC/OverStreamLimitError';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export function overStreamLimit(dir, proto) {
|
|
83
|
+
const code = dir === 'inbound' ? codes.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS : codes.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS;
|
|
84
|
+
return errCode(new OverStreamLimitError(`${dir} stream limit reached for protocol - ${proto}`), code);
|
|
85
|
+
}
|
|
86
|
+
export class UnimplementedError extends WebRTCTransportError {
|
|
87
|
+
constructor(methodName) {
|
|
88
|
+
super(`A method (${methodName}) was called though it has been intentionally left unimplemented.`);
|
|
89
|
+
this.name = 'WebRTC/UnimplementedError';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
export function unimplemented(methodName) {
|
|
93
|
+
return errCode(new UnimplementedError(methodName), codes.ERR_NOT_IMPLEMENTED);
|
|
94
|
+
}
|
|
95
|
+
export class UnsupportedHashAlgorithmError extends WebRTCTransportError {
|
|
96
|
+
constructor(algo) {
|
|
97
|
+
const msg = `unsupported hash algorithm: ${algo}`;
|
|
98
|
+
super(msg);
|
|
99
|
+
this.name = 'WebRTC/UnsupportedHashAlgorithmError';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export function unsupportedHashAlgorithm(algorithm) {
|
|
103
|
+
return errCode(new UnsupportedHashAlgorithmError(algorithm), codes.ERR_HASH_NOT_SUPPORTED);
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAA0B,8BAA8B,CAAA;AAExD,MAAM,CAAN,IAAY,KAWX;AAXD,WAAY,KAAK;IACf,oDAA2C,CAAA;IAC3C,8CAAqC,CAAA;IACrC,wDAA+C,CAAA;IAC/C,0DAAiD,CAAA;IACjD,wDAA+C,CAAA;IAC/C,4DAAmD,CAAA;IACnD,0DAAiD,CAAA;IACjD,oDAA2C,CAAA;IAC3C,wFAA+E,CAAA;IAC/E,0FAAiF,CAAA;AACnF,CAAC,EAXW,KAAK,KAAL,KAAK,QAWhB;AAED,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAa,GAAW;QACtB,KAAK,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAA;QACvC,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,oBAAoB;IAC7D,YAAa,KAA6B,EAAE,GAAW;QACrD,KAAK,CAAC,kCAAkC,KAA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MAAM,OAAO,kBAAmB,SAAQ,oBAAoB;IAC1D,YAAa,UAAkB;QAC7B,KAAK,CAAC,aAAa,UAAU,mEAAmE,CAAC,CAAA;QACjG,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;IACzC,CAAC;CACF;AAED,MAAM,UAAU,aAAa,CAAE,UAAkB;IAC/C,OAAO,OAAO,CAAC,IAAI,kBAAkB,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAA;AAC/E,CAAC;AAED,MAAM,OAAO,6BAA8B,SAAQ,oBAAoB;IACrE,YAAa,IAAY;QACvB,MAAM,GAAG,GAAG,+BAA+B,IAAI,EAAE,CAAA;QACjD,KAAK,CAAC,GAAG,CAAC,CAAA;QACV,IAAI,CAAC,IAAI,GAAG,sCAAsC,CAAA;IACpD,CAAC;CACF;AAED,MAAM,UAAU,wBAAwB,CAAE,SAAiB;IACzD,OAAO,OAAO,CAAC,IAAI,6BAA6B,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAA;AAC5F,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AACvD,OAAO,EAAmB,yBAAyB,EAAE,MAAM,gBAAgB,CAAA;AAE3E,wBAAgB,MAAM,IAAK,CAAC,UAAU,EAAE,yBAAyB,KAAK,SAAS,CAE9E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAA0B,6BAA6B,CAAA;AACvD,OAAO,EAAE,eAAe,EAA6B,MAAM,gBAAgB,CAAA;AAE3E,MAAM,UAAU,MAAM;IACpB,OAAO,CAAC,UAAqC,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,UAAU,CAAC,CAAA;AACnF,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { MultiaddrConnection, MultiaddrConnectionTimeline } from '@libp2p/interface-connection';
|
|
2
|
+
import { Multiaddr } from '@multiformats/multiaddr';
|
|
3
|
+
import { Source, Sink } from 'it-stream-types';
|
|
4
|
+
interface WebRTCMultiaddrConnectionInit {
|
|
5
|
+
/**
|
|
6
|
+
* WebRTC Peer Connection
|
|
7
|
+
*/
|
|
8
|
+
peerConnection: RTCPeerConnection;
|
|
9
|
+
/**
|
|
10
|
+
* The multiaddr address used to communicate with the remote peer
|
|
11
|
+
*/
|
|
12
|
+
remoteAddr: Multiaddr;
|
|
13
|
+
/**
|
|
14
|
+
* Holds the relevant events timestamps of the connection
|
|
15
|
+
*/
|
|
16
|
+
timeline: MultiaddrConnectionTimeline;
|
|
17
|
+
}
|
|
18
|
+
export declare class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
19
|
+
/**
|
|
20
|
+
* WebRTC Peer Connection
|
|
21
|
+
*/
|
|
22
|
+
readonly peerConnection: RTCPeerConnection;
|
|
23
|
+
/**
|
|
24
|
+
* The multiaddr address used to communicate with the remote peer
|
|
25
|
+
*/
|
|
26
|
+
remoteAddr: Multiaddr;
|
|
27
|
+
/**
|
|
28
|
+
* Holds the lifecycle times of the connection
|
|
29
|
+
*/
|
|
30
|
+
timeline: MultiaddrConnectionTimeline;
|
|
31
|
+
/**
|
|
32
|
+
* The stream source, a no-op as the transport natively supports multiplexing
|
|
33
|
+
*/
|
|
34
|
+
source: Source<Uint8Array>;
|
|
35
|
+
/**
|
|
36
|
+
* The stream destination, a no-op as the transport natively supports multiplexing
|
|
37
|
+
*/
|
|
38
|
+
sink: Sink<Uint8Array, Promise<void>>;
|
|
39
|
+
constructor(init: WebRTCMultiaddrConnectionInit);
|
|
40
|
+
close(err?: Error | undefined): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=maconn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maconn.d.ts","sourceRoot":"","sources":["../../src/maconn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAA;AAE/F,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAM9C,UAAU,6BAA6B;IACrC;;OAEG;IACH,cAAc,EAAE,iBAAiB,CAAA;IAEjC;;OAEG;IACH,UAAU,EAAE,SAAS,CAAA;IAErB;;OAEG;IACH,QAAQ,EAAE,2BAA2B,CAAA;CACtC;AAED,qBAAa,yBAA0B,YAAW,mBAAmB;IACnE;;OAEG;IACH,QAAQ,CAAC,cAAc,EAAE,iBAAiB,CAAC;IAE3C;;OAEG;IACH,UAAU,EAAE,SAAS,CAAC;IAEtB;;OAEG;IACH,QAAQ,EAAE,2BAA2B,CAAC;IAEtC;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAY;IAEtC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAW;gBAEnC,IAAI,EAAE,6BAA6B;IAM1C,KAAK,CAAE,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAQrD"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import '@libp2p/interface-connection';
|
|
2
|
+
import { logger } from '@libp2p/logger';
|
|
3
|
+
import '@multiformats/multiaddr';
|
|
4
|
+
import 'it-stream-types';
|
|
5
|
+
import { nopSink, nopSource } from './util.js';
|
|
6
|
+
const log = logger('libp2p:webrtc:connection');
|
|
7
|
+
export class WebRTCMultiaddrConnection {
|
|
8
|
+
constructor(init) {
|
|
9
|
+
/**
|
|
10
|
+
* The stream source, a no-op as the transport natively supports multiplexing
|
|
11
|
+
*/
|
|
12
|
+
this.source = nopSource;
|
|
13
|
+
/**
|
|
14
|
+
* The stream destination, a no-op as the transport natively supports multiplexing
|
|
15
|
+
*/
|
|
16
|
+
this.sink = nopSink;
|
|
17
|
+
this.remoteAddr = init.remoteAddr;
|
|
18
|
+
this.timeline = init.timeline;
|
|
19
|
+
this.peerConnection = init.peerConnection;
|
|
20
|
+
}
|
|
21
|
+
async close(err) {
|
|
22
|
+
if (err !== undefined) {
|
|
23
|
+
log.error('error closing connection', err);
|
|
24
|
+
}
|
|
25
|
+
this.timeline.close = new Date().getTime();
|
|
26
|
+
this.peerConnection.close();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=maconn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"maconn.js","sourceRoot":"","sources":["../../src/maconn.ts"],"names":[],"mappings":"AAAA,OAAiE,8BAA8B,CAAA;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAA0B,yBAAyB,CAAA;AACnD,OAA6B,iBAAiB,CAAA;AAE9C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE9C,MAAM,GAAG,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAA;AAmB9C,MAAM,OAAO,yBAAyB;IA0BpC,YAAa,IAAmC;QAVhD;;WAEG;QACH,WAAM,GAAuB,SAAS,CAAA;QAEtC;;WAEG;QACH,SAAI,GAAoC,OAAO,CAAC;QAG9C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAA;QACjC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;QAC7B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,KAAK,CAAE,GAAuB;QAClC,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,GAAG,CAAC,KAAK,CAAC,0BAA0B,EAAE,GAAG,CAAC,CAAA;SAC3C;QAED,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;QAC1C,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAA;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Stream } from '@libp2p/interface-connection';
|
|
2
|
+
import { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface-stream-muxer';
|
|
3
|
+
import { Source, Sink } from 'it-stream-types';
|
|
4
|
+
export declare class DataChannelMuxerFactory implements StreamMuxerFactory {
|
|
5
|
+
/**
|
|
6
|
+
* WebRTC Peer Connection
|
|
7
|
+
*/
|
|
8
|
+
private readonly peerConnection;
|
|
9
|
+
/**
|
|
10
|
+
* The string representation of the protocol, required by `StreamMuxerFactory`
|
|
11
|
+
*/
|
|
12
|
+
protocol: string;
|
|
13
|
+
constructor(peerConnection: RTCPeerConnection);
|
|
14
|
+
createStreamMuxer(init?: StreamMuxerInit | undefined): StreamMuxer;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A libp2p data channel stream muxer
|
|
18
|
+
*/
|
|
19
|
+
export declare class DataChannelMuxer implements StreamMuxer {
|
|
20
|
+
/**
|
|
21
|
+
* WebRTC Peer Connection
|
|
22
|
+
*/
|
|
23
|
+
private readonly peerConnection;
|
|
24
|
+
/**
|
|
25
|
+
* The protocol as represented in the multiaddress
|
|
26
|
+
*/
|
|
27
|
+
readonly protocol: string;
|
|
28
|
+
/**
|
|
29
|
+
* Array of streams in the data channel
|
|
30
|
+
*/
|
|
31
|
+
streams: Stream[];
|
|
32
|
+
/**
|
|
33
|
+
* Initialized stream muxer
|
|
34
|
+
*/
|
|
35
|
+
init?: StreamMuxerInit;
|
|
36
|
+
/**
|
|
37
|
+
* Close or abort all tracked streams and stop the muxer
|
|
38
|
+
*/
|
|
39
|
+
close: (err?: Error | undefined) => void;
|
|
40
|
+
/**
|
|
41
|
+
* The stream source, a no-op as the transport natively supports multiplexing
|
|
42
|
+
*/
|
|
43
|
+
source: Source<Uint8Array>;
|
|
44
|
+
/**
|
|
45
|
+
* The stream destination, a no-op as the transport natively supports multiplexing
|
|
46
|
+
*/
|
|
47
|
+
sink: Sink<Uint8Array, Promise<void>>;
|
|
48
|
+
constructor(peerConnection: RTCPeerConnection, init?: StreamMuxerInit);
|
|
49
|
+
/**
|
|
50
|
+
* Initiate a new stream with the given name. If no name is
|
|
51
|
+
* provided, the id of the stream will be used.
|
|
52
|
+
*/
|
|
53
|
+
newStream(name?: string): Stream;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=muxer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"muxer.d.ts","sourceRoot":"","sources":["../../src/muxer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AACjG,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAK9C,qBAAa,uBAAwB,YAAW,kBAAkB;IAChE;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmB;IAElD;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAY;gBAEf,cAAc,EAAE,iBAAiB;IAI9C,iBAAiB,CAAE,IAAI,CAAC,EAAE,eAAe,GAAG,SAAS,GAAG,WAAW;CAGpE;AAED;;GAEG;AACH,qBAAa,gBAAiB,YAAW,WAAW;IAClD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmB;IAClD;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAY;IAErC;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAK;IAEtB;;OAEG;IACH,IAAI,CAAC,EAAE,eAAe,CAAA;IAEtB;;OAEG;IACH,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAW;IAEnD;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,CAAa;IAEvC;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAW;gBAEnC,cAAc,EAAE,iBAAiB,EAAE,IAAI,CAAC,EAAE,eAAe;IAmCtE;;;OAGG;IACH,SAAS,CAAE,IAAI,GAAE,MAAW,GAAG,MAAM;CAetC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import '@libp2p/interface-connection';
|
|
2
|
+
import '@libp2p/interface-stream-muxer';
|
|
3
|
+
import 'it-stream-types';
|
|
4
|
+
import { WebRTCStream } from './stream.js';
|
|
5
|
+
import { nopSink, nopSource } from './util.js';
|
|
6
|
+
export class DataChannelMuxerFactory {
|
|
7
|
+
constructor(peerConnection) {
|
|
8
|
+
/**
|
|
9
|
+
* The string representation of the protocol, required by `StreamMuxerFactory`
|
|
10
|
+
*/
|
|
11
|
+
this.protocol = '/webrtc';
|
|
12
|
+
this.peerConnection = peerConnection;
|
|
13
|
+
}
|
|
14
|
+
createStreamMuxer(init) {
|
|
15
|
+
return new DataChannelMuxer(this.peerConnection, init);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A libp2p data channel stream muxer
|
|
20
|
+
*/
|
|
21
|
+
export class DataChannelMuxer {
|
|
22
|
+
constructor(peerConnection, init) {
|
|
23
|
+
/**
|
|
24
|
+
* The protocol as represented in the multiaddress
|
|
25
|
+
*/
|
|
26
|
+
this.protocol = '/webrtc';
|
|
27
|
+
/**
|
|
28
|
+
* Array of streams in the data channel
|
|
29
|
+
*/
|
|
30
|
+
this.streams = [];
|
|
31
|
+
/**
|
|
32
|
+
* Close or abort all tracked streams and stop the muxer
|
|
33
|
+
*/
|
|
34
|
+
this.close = () => { };
|
|
35
|
+
/**
|
|
36
|
+
* The stream source, a no-op as the transport natively supports multiplexing
|
|
37
|
+
*/
|
|
38
|
+
this.source = nopSource;
|
|
39
|
+
/**
|
|
40
|
+
* The stream destination, a no-op as the transport natively supports multiplexing
|
|
41
|
+
*/
|
|
42
|
+
this.sink = nopSink;
|
|
43
|
+
/**
|
|
44
|
+
* Initialized stream muxer
|
|
45
|
+
*/
|
|
46
|
+
this.init = init;
|
|
47
|
+
/**
|
|
48
|
+
* WebRTC Peer Connection
|
|
49
|
+
*/
|
|
50
|
+
this.peerConnection = peerConnection;
|
|
51
|
+
/**
|
|
52
|
+
* Fired when a data channel has been added to the connection has been
|
|
53
|
+
* added by the remote peer.
|
|
54
|
+
*
|
|
55
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event}
|
|
56
|
+
*/
|
|
57
|
+
this.peerConnection.ondatachannel = ({ channel }) => {
|
|
58
|
+
const stream = new WebRTCStream({
|
|
59
|
+
channel,
|
|
60
|
+
stat: {
|
|
61
|
+
direction: 'inbound',
|
|
62
|
+
timeline: {
|
|
63
|
+
open: 0
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
closeCb: init?.onStreamEnd
|
|
67
|
+
});
|
|
68
|
+
if ((init?.onIncomingStream) != null) {
|
|
69
|
+
init.onIncomingStream(stream);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Initiate a new stream with the given name. If no name is
|
|
75
|
+
* provided, the id of the stream will be used.
|
|
76
|
+
*/
|
|
77
|
+
newStream(name = '') {
|
|
78
|
+
const channel = this.peerConnection.createDataChannel(name);
|
|
79
|
+
const stream = new WebRTCStream({
|
|
80
|
+
channel,
|
|
81
|
+
stat: {
|
|
82
|
+
direction: 'outbound',
|
|
83
|
+
timeline: {
|
|
84
|
+
open: 0
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
closeCb: this.init?.onStreamEnd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ACP,IAAI,EAAE;oBACJ,SAAS,EAAE,SAAS;oBACpB,QAAQ,EAAE;wBACR,IAAI,EAAE,CAAC;qBACR;iBACF;gBACD,OAAO,EAAE,IAAI,EAAE,WAAW;aAC3B,CAAC,CAAA;YAEF,IAAI,CAAC,IAAI,EAAE,gBAAgB,CAAC,IAAI,IAAI,EAAE;gBACpC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;aAC9B;QACH,CAAC,CAAA;IACH,CAAC;IAED;;;OAGG;IACH,SAAS,CAAE,OAAe,EAAE;QAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAA;QAC3D,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC;YAC9B,OAAO;YACP,IAAI,EAAE;gBACJ,SAAS,EAAE,UAAU;gBACrB,QAAQ,EAAE;oBACR,IAAI,EAAE,CAAC;iBACR;aACF;YACD,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,WAAW;SAChC,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEhF,MAAM,WAAW,qBAAsB,SAAQ,qBAAqB;CAAG;AACvE,MAAM,WAAW,iBAAkB,SAAQ,WAAW;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":"AAAA,OAAmD,6BAA6B,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
+
import * as multihashes from 'multihashes';
|
|
3
|
+
/**
|
|
4
|
+
* Get base2 | identity decoders
|
|
5
|
+
*/
|
|
6
|
+
export declare const mbdecoder: any;
|
|
7
|
+
export declare function certhash(ma: Multiaddr): string;
|
|
8
|
+
/**
|
|
9
|
+
* Convert a certhash into a multihash
|
|
10
|
+
*/
|
|
11
|
+
export declare function decodeCerthash(certhash: string): {
|
|
12
|
+
code: import("multihashes/dist/src/constants.js").HashCode;
|
|
13
|
+
name: import("multihashes/dist/src/constants.js").HashName;
|
|
14
|
+
length: number;
|
|
15
|
+
digest: Uint8Array;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Extract the fingerprint from a multiaddr
|
|
19
|
+
*/
|
|
20
|
+
export declare function ma2Fingerprint(ma: Multiaddr): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Normalize the hash name from a given multihash has name
|
|
23
|
+
*/
|
|
24
|
+
export declare function toSupportedHashFunction(name: multihashes.HashName): string;
|
|
25
|
+
/**
|
|
26
|
+
* Create an answer SDP from a multiaddr
|
|
27
|
+
*/
|
|
28
|
+
export declare function fromMultiAddr(ma: Multiaddr, ufrag: string): RTCSessionDescriptionInit;
|
|
29
|
+
/**
|
|
30
|
+
* Replace (munge) the ufrag and password values in a SDP
|
|
31
|
+
*/
|
|
32
|
+
export declare function munge(desc: RTCSessionDescriptionInit, ufrag: string): RTCSessionDescriptionInit;
|
|
33
|
+
//# sourceMappingURL=sdp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdp.d.ts","sourceRoot":"","sources":["../../src/sdp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,OAAO,KAAK,WAAW,MAAM,aAAa,CAAA;AAO1C;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,GAKpB,CAAA;AAkBJ,wBAAgB,QAAQ,CAAE,EAAE,EAAE,SAAS,GAAG,MAAM,CAS/C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAE,QAAQ,EAAE,MAAM;;;;;EAG/C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAE,EAAE,EAAE,SAAS,GAAG,MAAM,EAAE,CAYvD;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAE,IAAI,EAAE,WAAW,CAAC,QAAQ,GAAG,MAAM,CAW3E;AA2BD;;GAEG;AACH,wBAAgB,aAAa,CAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,yBAAyB,CAKtF;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAE,IAAI,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,GAAG,yBAAyB,CAShG"}
|