Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@libp2p/webrtc

Package Overview
Dependencies
Maintainers
6
Versions
590
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/webrtc - npm Package Compare versions

Comparing version 1.1.10 to 1.1.11

4

dist/src/index.d.ts

@@ -0,4 +1,4 @@

import { type WebRTCDirectTransportComponents } from './transport.js';
import type { WebRTCTransportComponents, WebRTCTransportInit } from './peer_transport/transport.js';
import type { Transport } from '@libp2p/interface-transport';
import type { WebRTCTransportComponents, WebRTCTransportInit } from './peer_transport/transport.js';
import { WebRTCDirectTransportComponents } from './transport.js';
declare function webRTCDirect(): (components: WebRTCDirectTransportComponents) => Transport;

@@ -5,0 +5,0 @@ declare function webRTC(init?: WebRTCTransportInit): (components: WebRTCTransportComponents) => Transport;

@@ -34,7 +34,7 @@ import type { MultiaddrConnection, MultiaddrConnectionTimeline } from '@libp2p/interface-connection';

*/
source: Source<Uint8Array>;
source: AsyncGenerator<Uint8Array, any, unknown>;
/**
* The stream destination, a no-op as the transport natively supports multiplexing
*/
sink: Sink<Uint8Array, Promise<void>>;
sink: Sink<Source<Uint8Array>, Promise<void>>;
constructor(init: WebRTCMultiaddrConnectionInit);

@@ -41,0 +41,0 @@ close(err?: Error | undefined): Promise<void>;

@@ -5,11 +5,23 @@ import { logger } from '@libp2p/logger';

export class WebRTCMultiaddrConnection {
/**
* WebRTC Peer Connection
*/
peerConnection;
/**
* The multiaddr address used to communicate with the remote peer
*/
remoteAddr;
/**
* Holds the lifecycle times of the connection
*/
timeline;
/**
* The stream source, a no-op as the transport natively supports multiplexing
*/
source = nopSource();
/**
* The stream destination, a no-op as the transport natively supports multiplexing
*/
sink = nopSink;
constructor(init) {
/**
* The stream source, a no-op as the transport natively supports multiplexing
*/
this.source = nopSource;
/**
* The stream destination, a no-op as the transport natively supports multiplexing
*/
this.sink = nopSink;
this.remoteAddr = init.remoteAddr;

@@ -16,0 +28,0 @@ this.timeline = init.timeline;

import type { Stream } from '@libp2p/interface-connection';
import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface-stream-muxer';
import type { Source, Sink } from 'it-stream-types';
import type { Uint8ArrayList } from 'uint8arraylist';
export declare class DataChannelMuxerFactory implements StreamMuxerFactory {

@@ -38,7 +39,7 @@ readonly protocol: string;

*/
source: Source<Uint8Array>;
source: AsyncGenerator<Uint8Array, any, unknown>;
/**
* The stream destination, a no-op as the transport natively supports multiplexing
*/
sink: Sink<Uint8Array, Promise<void>>;
sink: Sink<Source<Uint8Array | Uint8ArrayList>, Promise<void>>;
constructor(peerConnection: RTCPeerConnection, streams: Stream[], protocol?: string, init?: StreamMuxerInit);

@@ -45,0 +46,0 @@ newStream(): Stream;

import { WebRTCStream } from './stream.js';
import { nopSink, nopSource } from './util.js';
export class DataChannelMuxerFactory {
protocol;
/**
* WebRTC Peer Connection
*/
peerConnection;
streamBuffer = [];
constructor(peerConnection, protocol = '/webrtc') {
this.protocol = protocol;
this.streamBuffer = [];
this.peerConnection = peerConnection;

@@ -31,21 +36,30 @@ // store any datachannels opened before upgrade has been completed

export class DataChannelMuxer {
protocol;
/**
* WebRTC Peer Connection
*/
peerConnection;
/**
* Array of streams in the data channel
*/
streams = [];
/**
* Initialized stream muxer
*/
init;
/**
* Close or abort all tracked streams and stop the muxer
*/
close = () => { };
/**
* The stream source, a no-op as the transport natively supports multiplexing
*/
source = nopSource();
/**
* The stream destination, a no-op as the transport natively supports multiplexing
*/
sink = nopSink;
constructor(peerConnection, streams, protocol = '/webrtc', init) {
this.protocol = protocol;
/**
* Array of streams in the data channel
*/
this.streams = [];
/**
* Close or abort all tracked streams and stop the muxer
*/
this.close = () => { };
/**
* The stream source, a no-op as the transport natively supports multiplexing
*/
this.source = nopSource;
/**
* The stream destination, a no-op as the transport natively supports multiplexing
*/
this.sink = nopSink;
/**
* Initialized stream muxer

@@ -52,0 +66,0 @@ */

@@ -0,3 +1,3 @@

import type { Stream } from '@libp2p/interface-connection';
import type { IncomingStreamData } from '@libp2p/interface-registrar';
import type { Stream } from '@libp2p/interface-connection';
import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer';

@@ -4,0 +4,0 @@ export type IncomingStreamOpts = {

@@ -0,15 +1,13 @@

import { logger } from '@libp2p/logger';
import { abortableDuplex } from 'abortable-iterator';
import { pbStream } from 'it-pb-stream';
import pDefer from 'p-defer';
import { TimeoutController } from 'timeout-abort-controller';
import { DataChannelMuxerFactory } from '../muxer.js';
import * as pb from './pb/index.js';
import { readCandidatesUntilConnected, resolveOnConnected } from './util.js';
import * as pb from './pb/index.js';
import { abortableDuplex } from 'abortable-iterator';
import { logger } from '@libp2p/logger';
import { DataChannelMuxerFactory } from '../muxer.js';
const DEFAULT_TIMEOUT = 30 * 1000;
const log = logger('libp2p:webrtc:peer');
export async function handleIncomingStream({ rtcConfiguration, stream: rawStream }) {
const timeoutController = new TimeoutController(DEFAULT_TIMEOUT);
const signal = timeoutController.signal;
const stream = pbStream(abortableDuplex(rawStream, timeoutController.signal)).pb(pb.Message);
const signal = AbortSignal.timeout(DEFAULT_TIMEOUT);
const stream = pbStream(abortableDuplex(rawStream, signal)).pb(pb.Message);
const pc = new RTCPeerConnection(rtcConfiguration);

@@ -16,0 +14,0 @@ const muxerFactory = new DataChannelMuxerFactory(pc);

@@ -0,5 +1,5 @@

import { EventEmitter } from '@libp2p/interfaces/events';
import { type Multiaddr } from '@multiformats/multiaddr';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { ListenerEvents, TransportManager, Upgrader, Listener } from '@libp2p/interface-transport';
import { EventEmitter } from '@libp2p/interfaces/events';
import { Multiaddr } from '@multiformats/multiaddr';
export interface ListenerOptions {

@@ -6,0 +6,0 @@ peerId: PeerId;

@@ -6,6 +6,6 @@ import { EventEmitter } from '@libp2p/interfaces/events';

export class WebRTCPeerListener extends EventEmitter {
opts;
constructor(opts) {
super();
this.opts = opts;
this.listeningAddrs = [];
}

@@ -19,2 +19,3 @@ getBaseAddress(ma) {

}
listeningAddrs = [];
async listen(ma) {

@@ -21,0 +22,0 @@ const baseAddr = this.getBaseAddress(ma);

@@ -0,3 +1,3 @@

import type { Codec } from 'protons-runtime';
import type { Uint8ArrayList } from 'uint8arraylist';
import type { Codec } from 'protons-runtime';
export interface Message {

@@ -4,0 +4,0 @@ type?: Message.Type;

@@ -0,9 +1,8 @@

import { type CreateListenerOptions, type DialOptions, type Listener, symbol, type Transport, type TransportManager, type Upgrader } from '@libp2p/interface-transport';
import { type Multiaddr } from '@multiformats/multiaddr';
import type { Connection } from '@libp2p/interface-connection';
import { CreateListenerOptions, DialOptions, Listener, symbol, Transport } from '@libp2p/interface-transport';
import type { TransportManager, Upgrader } from '@libp2p/interface-transport';
import { Multiaddr } from '@multiformats/multiaddr';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { PeerStore } from '@libp2p/interface-peer-store';
import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar';
import type { PeerId } from '@libp2p/interface-peer-id';
import type { Startable } from '@libp2p/interfaces/startable';
import type { PeerStore } from '@libp2p/interface-peer-store';
export declare const TRANSPORT = "/webrtc";

@@ -31,4 +30,4 @@ export declare const SIGNALING_PROTO_ID = "/webrtc-signaling/0.0.1";

createListener(options: CreateListenerOptions): Listener;
get [Symbol.toStringTag](): string;
get [symbol](): true;
readonly [Symbol.toStringTag] = "@libp2p/webrtc";
readonly [symbol] = true;
filter(multiaddrs: Multiaddr[]): Multiaddr[];

@@ -35,0 +34,0 @@ private splitAddr;

import { symbol } from '@libp2p/interface-transport';
import { CodeError } from '@libp2p/interfaces/errors';
import { logger } from '@libp2p/logger';
import { peerIdFromString } from '@libp2p/peer-id';
import { multiaddr, protocols } from '@multiformats/multiaddr';
import { peerIdFromString } from '@libp2p/peer-id';
import { codes } from '../error.js';
import { WebRTCMultiaddrConnection } from '../maconn.js';
import { initiateConnection, handleIncomingStream } from './handler.js';
import { WebRTCPeerListener } from './listener.js';
import { logger } from '@libp2p/logger';
import { initiateConnection, handleIncomingStream } from './handler.js';
import { CodeError } from '@libp2p/interfaces/errors';
import { codes } from '../error.js';
const log = logger('libp2p:webrtc:peer');

@@ -15,6 +15,8 @@ export const TRANSPORT = '/webrtc';

export class WebRTCTransport {
components;
init;
_started = false;
constructor(components, init) {
this.components = components;
this.init = init;
this._started = false;
}

@@ -37,8 +39,4 @@ isStarted() {

}
get [Symbol.toStringTag]() {
return '@libp2p/webrtc';
}
get [symbol]() {
return true;
}
[Symbol.toStringTag] = '@libp2p/webrtc';
[symbol] = true;
filter(multiaddrs) {

@@ -45,0 +43,0 @@ return multiaddrs.filter((ma) => {

@@ -0,3 +1,3 @@

import * as pb from './pb/index.js';
import type { DeferredPromise } from 'p-defer';
import * as pb from './pb/index.js';
export declare const isFirefox: boolean;

@@ -4,0 +4,0 @@ interface MessageStream {

import { logger } from '@libp2p/logger';
import { detect } from 'detect-browser';
import * as pb from './pb/index.js';
import { detect } from 'detect-browser';
const browser = detect();

@@ -5,0 +5,0 @@ export const isFirefox = ((browser != null) && browser.name === 'firefox');

@@ -0,3 +1,3 @@

import * as multihashes from 'multihashes';
import type { Multiaddr } from '@multiformats/multiaddr';
import * as multihashes from 'multihashes';
import type { HashCode, HashName } from 'multihashes';

@@ -4,0 +4,0 @@ /**

@@ -0,6 +1,6 @@

import { type DeferredPromise } from 'p-defer';
import { Uint8ArrayList } from 'uint8arraylist';
import * as pb from '../proto_ts/message.js';
import type { Stream, StreamStat, Direction } from '@libp2p/interface-connection';
import { DeferredPromise } from 'p-defer';
import type { Source } from 'it-stream-types';
import { Uint8ArrayList } from 'uint8arraylist';
import * as pb from '../proto_ts/message.js';
/**

@@ -106,4 +106,4 @@ * Constructs a default StreamStat

constructor(opts: StreamInitOpts);
set source(_src: Source<Uint8ArrayList>);
get source(): Source<Uint8ArrayList>;
set source(_src: AsyncGenerator<Uint8ArrayList, any, unknown>);
get source(): AsyncGenerator<Uint8ArrayList, any, unknown>;
/**

@@ -110,0 +110,0 @@ * Write data to the remote peer.

@@ -35,5 +35,3 @@ import { logger } from '@libp2p/logger';

class StreamState {
constructor() {
this.state = StreamStates.OPEN;
}
state = StreamStates.OPEN;
isWriteClosed() {

@@ -102,25 +100,50 @@ return (this.state === StreamStates.CLOSED || this.state === StreamStates.WRITE_CLOSED);

export class WebRTCStream {
/**
* Unique identifier for a stream
*/
id;
/**
* Stats about this stream
*/
stat;
/**
* User defined stream metadata
*/
metadata;
/**
* The data channel used to send and receive data
*/
channel;
/**
* The current state of the stream
*/
streamState = new StreamState();
/**
* Read unwrapped protobuf data from the underlying datachannel.
* _src is exposed to the user via the `source` getter to .
*/
_src;
/**
* push data from the underlying datachannel to the length prefix decoder
* and then the protobuf decoder.
*/
_innersrc = pushable();
/**
* Deferred promise that resolves when the underlying datachannel is in the
* open state.
*/
opened = defer();
/**
* sinkCreated is set to true once the sinkFunction is invoked
*/
_sinkCalled = false;
/**
* Triggers a generator which can be used to close the sink.
*/
closeWritePromise = defer();
/**
* Callback to invoke when the stream is closed.
*/
closeCb;
constructor(opts) {
/**
* The current state of the stream
*/
this.streamState = new StreamState();
/**
* push data from the underlying datachannel to the length prefix decoder
* and then the protobuf decoder.
*/
this._innersrc = pushable();
/**
* Deferred promise that resolves when the underlying datachannel is in the
* open state.
*/
this.opened = defer();
/**
* sinkCreated is set to true once the sinkFunction is invoked
*/
this._sinkCalled = false;
/**
* Triggers a generator which can be used to close the sink.
*/
this.closeWritePromise = defer();
this.channel = opts.channel;

@@ -127,0 +150,0 @@ this.channel.binaryType = 'arraybuffer';

@@ -0,6 +1,6 @@

import { type CreateListenerOptions, type Listener, symbol, type Transport } from '@libp2p/interface-transport';
import type { WebRTCDialOptions } from './options.js';
import type { Connection } from '@libp2p/interface-connection';
import type { PeerId } from '@libp2p/interface-peer-id';
import { CreateListenerOptions, Listener, symbol, Transport } from '@libp2p/interface-transport';
import type { Multiaddr } from '@multiformats/multiaddr';
import type { WebRTCDialOptions } from './options.js';
/**

@@ -45,7 +45,7 @@ * Created by converting the hexadecimal protocol code to an integer.

*/
get [Symbol.toStringTag](): string;
readonly [Symbol.toStringTag] = "@libp2p/webrtc-direct";
/**
* Symbol.for('@libp2p/transport')
*/
get [symbol](): true;
readonly [symbol] = true;
/**

@@ -52,0 +52,0 @@ * Connect to a peer using a multiaddr

@@ -5,13 +5,13 @@ import { noise as Noise } from '@chainsafe/libp2p-noise';

import * as p from '@libp2p/peer-id';
import { protocols } from '@multiformats/multiaddr';
import * as multihashes from 'multihashes';
import { concat } from 'uint8arrays/concat';
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string';
import { concat } from 'uint8arrays/concat';
import { dataChannelError, inappropriateMultiaddr, unimplemented, invalidArgument } from './error.js';
import { WebRTCMultiaddrConnection } from './maconn.js';
import { DataChannelMuxerFactory } from './muxer.js';
import { isFirefox } from './peer_transport/util.js';
import * as sdp from './sdp.js';
import { WebRTCStream } from './stream.js';
import { genUfrag } from './util.js';
import { protocols } from '@multiformats/multiaddr';
import { isFirefox } from './peer_transport/util.js';
const log = logger('libp2p:webrtc:transport');

@@ -35,2 +35,6 @@ /**

export class WebRTCDirectTransport {
/**
* The peer for this transport
*/
components;
constructor(components) {

@@ -62,11 +66,7 @@ this.components = components;

*/
get [Symbol.toStringTag]() {
return '@libp2p/webrtc-direct';
}
[Symbol.toStringTag] = '@libp2p/webrtc-direct';
/**
* Symbol.for('@libp2p/transport')
*/
get [symbol]() {
return true;
}
[symbol] = true;
/**

@@ -182,3 +182,3 @@ * Connect to a peer using a multiaddr

await noise.secureInbound(myPeerId, wrappedDuplex, theirPeerId);
return await options.upgrader.upgradeOutbound(maConn, { skipProtection: true, skipEncryption: true, muxerFactory });
return options.upgrader.upgradeOutbound(maConn, { skipProtection: true, skipEncryption: true, muxerFactory });
}

@@ -185,0 +185,0 @@ /**

@@ -1,6 +0,4 @@

export declare const nopSource: {
[Symbol.asyncIterator](): AsyncGenerator<never, void, unknown>;
};
export declare const nopSource: () => AsyncGenerator<Uint8Array, any, unknown>;
export declare const nopSink: (_: any) => Promise<void>;
export declare const genUfrag: (len: number) => string;
//# sourceMappingURL=util.d.ts.map

@@ -1,4 +0,2 @@

export const nopSource = {
async *[Symbol.asyncIterator]() { }
};
export const nopSource = async function* nop() { };
export const nopSink = async (_) => { };

@@ -5,0 +3,0 @@ const charset = Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');

{
"name": "@libp2p/webrtc",
"version": "1.1.10",
"version": "1.1.11",
"description": "A libp2p transport using WebRTC connections",

@@ -140,22 +140,22 @@ "author": "",

"dependencies": {
"@chainsafe/libp2p-noise": "^11.0.0",
"@libp2p/interface-connection": "^4.0.0",
"@libp2p/interface-peer-id": "^2.0.0",
"@libp2p/interface-peer-store": "^2.0.0",
"@libp2p/interface-registrar": "^2.0.8",
"@libp2p/interface-stream-muxer": "^3.0.0",
"@libp2p/interface-transport": "^2.0.0",
"@libp2p/interfaces": "^3.2.0",
"@libp2p/logger": "^2.0.0",
"@libp2p/peer-id": "^2.0.0",
"@multiformats/multiaddr": "^12.1.1",
"@protobuf-ts/runtime": "^2.8.0",
"@chainsafe/libp2p-noise": "^11.0.4",
"@libp2p/interface-connection": "^5.0.2",
"@libp2p/interface-peer-id": "^2.0.2",
"@libp2p/interface-peer-store": "^2.0.2",
"@libp2p/interface-registrar": "^2.0.12",
"@libp2p/interface-stream-muxer": "^4.0.1",
"@libp2p/interface-transport": "^4.0.2",
"@libp2p/interfaces": "^3.3.2",
"@libp2p/logger": "^2.0.7",
"@libp2p/peer-id": "^2.0.3",
"@multiformats/multiaddr": "^12.1.2",
"@protobuf-ts/runtime": "^2.9.0",
"abortable-iterator": "^4.0.2",
"err-code": "^3.0.1",
"detect-browser": "^5.3.0",
"it-length-prefixed": "^8.0.3",
"it-merge": "^2.0.0",
"it-pb-stream": "^3.2.1",
"it-merge": "^3.0.0",
"it-pb-stream": "^4.0.1",
"it-pipe": "^3.0.1",
"it-pushable": "^3.1.0",
"it-stream-types": "^1.0.4",
"it-pushable": "^3.1.3",
"it-stream-types": "^2.0.1",
"multiformats": "^11.0.2",

@@ -165,18 +165,16 @@ "multihashes": "^4.0.3",

"protons-runtime": "^5.0.0",
"timeout-abort-controller": "^3.0.0",
"uint8arraylist": "^2.3.3",
"uint8arrays": "^4.0.2",
"detect-browser": "^5.3.0"
"uint8arraylist": "^2.4.3",
"uint8arrays": "^4.0.3"
},
"devDependencies": {
"@libp2p/interface-mocks": "^9.0.0",
"@libp2p/peer-id-factory": "^2.0.0",
"@protobuf-ts/plugin": "^2.8.0",
"@protobuf-ts/protoc": "^2.8.0",
"aegir": "^38.1.6",
"@libp2p/interface-mocks": "^11.0.2",
"@libp2p/peer-id-factory": "^2.0.3",
"@protobuf-ts/protoc": "^2.9.0",
"@types/sinon": "^10.0.14",
"aegir": "^39.0.5",
"eslint-plugin-etc": "^2.0.2",
"it-pair": "^2.0.3",
"it-pair": "^2.0.6",
"protons": "^7.0.2",
"sinon": "^15.0.1"
"sinon": "^15.0.4"
}
}

@@ -0,5 +1,5 @@

import { WebRTCTransport } from './peer_transport/transport.js'
import { WebRTCDirectTransport, type WebRTCDirectTransportComponents } from './transport.js'
import type { WebRTCTransportComponents, WebRTCTransportInit } from './peer_transport/transport.js'
import type { Transport } from '@libp2p/interface-transport'
import type { WebRTCTransportComponents, WebRTCTransportInit } from './peer_transport/transport.js'
import { WebRTCTransport } from './peer_transport/transport.js'
import { WebRTCDirectTransport, WebRTCDirectTransportComponents } from './transport.js'

@@ -6,0 +6,0 @@ function webRTCDirect (): (components: WebRTCDirectTransportComponents) => Transport {

@@ -0,8 +1,7 @@

import { logger } from '@libp2p/logger'
import { nopSink, nopSource } from './util.js'
import type { MultiaddrConnection, MultiaddrConnectionTimeline } from '@libp2p/interface-connection'
import { logger } from '@libp2p/logger'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { Source, Sink } from 'it-stream-types'
import { nopSink, nopSource } from './util.js'
const log = logger('libp2p:webrtc:connection')

@@ -46,3 +45,3 @@

*/
source: Source<Uint8Array> = nopSource
source: AsyncGenerator<Uint8Array, any, unknown> = nopSource()

@@ -52,3 +51,3 @@ /**

*/
sink: Sink<Uint8Array, Promise<void>> = nopSink
sink: Sink<Source<Uint8Array>, Promise<void>> = nopSink

@@ -55,0 +54,0 @@ constructor (init: WebRTCMultiaddrConnectionInit) {

@@ -0,8 +1,8 @@

import { WebRTCStream } from './stream.js'
import { nopSink, nopSource } from './util.js'
import type { Stream } from '@libp2p/interface-connection'
import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface-stream-muxer'
import type { Source, Sink } from 'it-stream-types'
import type { Uint8ArrayList } from 'uint8arraylist'
import { WebRTCStream } from './stream.js'
import { nopSink, nopSource } from './util.js'
export class DataChannelMuxerFactory implements StreamMuxerFactory {

@@ -65,3 +65,3 @@ /**

*/
source: Source<Uint8Array> = nopSource
source: AsyncGenerator<Uint8Array, any, unknown> = nopSource()

@@ -71,3 +71,3 @@ /**

*/
sink: Sink<Uint8Array, Promise<void>> = nopSink
sink: Sink<Source<Uint8Array | Uint8ArrayList>, Promise<void>> = nopSink

@@ -74,0 +74,0 @@ constructor (peerConnection: RTCPeerConnection, streams: Stream[], readonly protocol = '/webrtc', init?: StreamMuxerInit) {

@@ -1,12 +0,11 @@

import type { IncomingStreamData } from '@libp2p/interface-registrar'
import { logger } from '@libp2p/logger'
import { abortableDuplex } from 'abortable-iterator'
import { pbStream } from 'it-pb-stream'
import pDefer, { type DeferredPromise } from 'p-defer'
import { TimeoutController } from 'timeout-abort-controller'
import { DataChannelMuxerFactory } from '../muxer.js'
import * as pb from './pb/index.js'
import { readCandidatesUntilConnected, resolveOnConnected } from './util.js'
import * as pb from './pb/index.js'
import { abortableDuplex } from 'abortable-iterator'
import { logger } from '@libp2p/logger'
import type { Stream } from '@libp2p/interface-connection'
import type { IncomingStreamData } from '@libp2p/interface-registrar'
import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
import { DataChannelMuxerFactory } from '../muxer.js'

@@ -20,5 +19,4 @@ const DEFAULT_TIMEOUT = 30 * 1000

export async function handleIncomingStream ({ rtcConfiguration, stream: rawStream }: IncomingStreamOpts): Promise<[RTCPeerConnection, StreamMuxerFactory]> {
const timeoutController = new TimeoutController(DEFAULT_TIMEOUT)
const signal = timeoutController.signal
const stream = pbStream(abortableDuplex(rawStream, timeoutController.signal)).pb(pb.Message)
const signal = AbortSignal.timeout(DEFAULT_TIMEOUT)
const stream = pbStream(abortableDuplex(rawStream, signal)).pb(pb.Message)
const pc = new RTCPeerConnection(rtcConfiguration)

@@ -25,0 +23,0 @@ const muxerFactory = new DataChannelMuxerFactory(pc)

@@ -1,7 +0,7 @@

import type { PeerId } from '@libp2p/interface-peer-id'
import type { ListenerEvents, TransportManager, Upgrader, Listener } from '@libp2p/interface-transport'
import { EventEmitter } from '@libp2p/interfaces/events'
import { multiaddr, Multiaddr } from '@multiformats/multiaddr'
import { multiaddr, type Multiaddr } from '@multiformats/multiaddr'
import { inappropriateMultiaddr } from '../error.js'
import { TRANSPORT } from './transport.js'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { ListenerEvents, TransportManager, Upgrader, Listener } from '@libp2p/interface-transport'

@@ -8,0 +8,0 @@ export interface ListenerOptions {

@@ -8,4 +8,4 @@ /* eslint-disable import/export */

import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime'
import type { Codec } from 'protons-runtime'
import type { Uint8ArrayList } from 'uint8arraylist'
import type { Codec } from 'protons-runtime'

@@ -12,0 +12,0 @@ export interface Message {

@@ -1,16 +0,15 @@

import type { Connection } from '@libp2p/interface-connection'
import { CreateListenerOptions, DialOptions, Listener, symbol, Transport } from '@libp2p/interface-transport'
import type { TransportManager, Upgrader } from '@libp2p/interface-transport'
import { multiaddr, Multiaddr, protocols } from '@multiformats/multiaddr'
import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
import type { PeerId } from '@libp2p/interface-peer-id'
import { type CreateListenerOptions, type DialOptions, type Listener, symbol, type Transport, type TransportManager, type Upgrader } from '@libp2p/interface-transport'
import { CodeError } from '@libp2p/interfaces/errors'
import { logger } from '@libp2p/logger'
import { peerIdFromString } from '@libp2p/peer-id'
import { multiaddr, type Multiaddr, protocols } from '@multiformats/multiaddr'
import { codes } from '../error.js'
import { WebRTCMultiaddrConnection } from '../maconn.js'
import type { Startable } from '@libp2p/interfaces/startable'
import { initiateConnection, handleIncomingStream } from './handler.js'
import { WebRTCPeerListener } from './listener.js'
import type { Connection } from '@libp2p/interface-connection'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { PeerStore } from '@libp2p/interface-peer-store'
import { logger } from '@libp2p/logger'
import { initiateConnection, handleIncomingStream } from './handler.js'
import { CodeError } from '@libp2p/interfaces/errors'
import { codes } from '../error.js'
import type { IncomingStreamData, Registrar } from '@libp2p/interface-registrar'
import type { Startable } from '@libp2p/interfaces/startable'

@@ -49,3 +48,3 @@ const log = logger('libp2p:webrtc:peer')

async start (): Promise<void> {
await this.components.registrar.handle(SIGNALING_PROTO_ID, (data) => {
await this.components.registrar.handle(SIGNALING_PROTO_ID, (data: IncomingStreamData) => {
this._onProtocol(data).catch(err => { log.error('failed to handle incoming connect from %p', data.connection.remotePeer, err) })

@@ -65,9 +64,5 @@ })

get [Symbol.toStringTag] (): string {
return '@libp2p/webrtc'
}
readonly [Symbol.toStringTag] = '@libp2p/webrtc'
get [symbol] (): true {
return true
}
readonly [symbol] = true

@@ -74,0 +69,0 @@ filter (multiaddrs: Multiaddr[]): Multiaddr[] {

import { logger } from '@libp2p/logger'
import { detect } from 'detect-browser'
import * as pb from './pb/index.js'
import type { DeferredPromise } from 'p-defer'
import * as pb from './pb/index.js'
import { detect } from 'detect-browser'

@@ -6,0 +6,0 @@ const browser = detect()

import { logger } from '@libp2p/logger'
import type { Multiaddr } from '@multiformats/multiaddr'
import { bases } from 'multiformats/basics'
import * as multihashes from 'multihashes'
import type { HashCode, HashName } from 'multihashes'
import { inappropriateMultiaddr, invalidArgument, invalidFingerprint, unsupportedHashAlgorithm } from './error.js'
import { CERTHASH_CODE } from './transport.js'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { HashCode, HashName } from 'multihashes'

@@ -10,0 +9,0 @@ const log = logger('libp2p:webrtc:sdp')

@@ -1,2 +0,1 @@

import type { Stream, StreamStat, Direction } from '@libp2p/interface-connection'
import { logger } from '@libp2p/logger'

@@ -7,7 +6,7 @@ import * as lengthPrefixed from 'it-length-prefixed'

import { pushable } from 'it-pushable'
import defer, { DeferredPromise } from 'p-defer'
import type { Source } from 'it-stream-types'
import defer, { type DeferredPromise } from 'p-defer'
import { Uint8ArrayList } from 'uint8arraylist'
import * as pb from '../proto_ts/message.js'
import type { Stream, StreamStat, Direction } from '@libp2p/interface-connection'
import type { Source } from 'it-stream-types'

@@ -186,3 +185,3 @@ const log = logger('libp2p:webrtc:stream')

*/
private readonly _src: Source<Uint8ArrayList>
private readonly _src: AsyncGenerator<Uint8ArrayList, any, unknown>

@@ -287,5 +286,5 @@ /**

// If user attempts to set a new source this should be a noop
set source (_src: Source<Uint8ArrayList>) { }
set source (_src: AsyncGenerator<Uint8ArrayList, any, unknown>) { }
get source (): Source<Uint8ArrayList> {
get source (): AsyncGenerator<Uint8ArrayList, any, unknown> {
return this._src

@@ -292,0 +291,0 @@ }

import { noise as Noise } from '@chainsafe/libp2p-noise'
import type { Connection } from '@libp2p/interface-connection'
import type { PeerId } from '@libp2p/interface-peer-id'
import { CreateListenerOptions, Listener, symbol, Transport } from '@libp2p/interface-transport'
import { type CreateListenerOptions, type Listener, symbol, type Transport } from '@libp2p/interface-transport'
import { logger } from '@libp2p/logger'
import * as p from '@libp2p/peer-id'
import type { Multiaddr } from '@multiformats/multiaddr'
import { protocols } from '@multiformats/multiaddr'
import * as multihashes from 'multihashes'
import { concat } from 'uint8arrays/concat'
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string'
import { concat } from 'uint8arrays/concat'
import { dataChannelError, inappropriateMultiaddr, unimplemented, invalidArgument } from './error.js'
import { WebRTCMultiaddrConnection } from './maconn.js'
import { DataChannelMuxerFactory } from './muxer.js'
import type { WebRTCDialOptions } from './options.js'
import { isFirefox } from './peer_transport/util.js'
import * as sdp from './sdp.js'
import { WebRTCStream } from './stream.js'
import { genUfrag } from './util.js'
import { protocols } from '@multiformats/multiaddr'
import { isFirefox } from './peer_transport/util.js'
import type { WebRTCDialOptions } from './options.js'
import type { Connection } from '@libp2p/interface-connection'
import type { PeerId } from '@libp2p/interface-peer-id'
import type { Multiaddr } from '@multiformats/multiaddr'

@@ -86,5 +86,3 @@ const log = logger('libp2p:webrtc:transport')

*/
get [Symbol.toStringTag] (): string {
return '@libp2p/webrtc-direct'
}
readonly [Symbol.toStringTag] = '@libp2p/webrtc-direct'

@@ -94,5 +92,3 @@ /**

*/
get [symbol] (): true {
return true
}
readonly [symbol] = true

@@ -230,3 +226,3 @@ /**

return await options.upgrader.upgradeOutbound(maConn, { skipProtection: true, skipEncryption: true, muxerFactory })
return options.upgrader.upgradeOutbound(maConn, { skipProtection: true, skipEncryption: true, muxerFactory })
}

@@ -233,0 +229,0 @@

@@ -1,4 +0,2 @@

export const nopSource = {
async * [Symbol.asyncIterator] () {}
}
export const nopSource = async function * nop (): AsyncGenerator<Uint8Array, any, unknown> {}

@@ -5,0 +3,0 @@ export const nopSink = async (_: any): Promise<void> => {}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc