@libp2p/webrtc 1.0.3 → 1.0.5

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/src/sdp.ts CHANGED
@@ -2,6 +2,7 @@ import { logger } from '@libp2p/logger'
2
2
  import type { Multiaddr } from '@multiformats/multiaddr'
3
3
  import { bases } from 'multiformats/basics'
4
4
  import * as multihashes from 'multihashes'
5
+ import type { HashCode, HashName } from 'multihashes'
5
6
 
6
7
  import { inappropriateMultiaddr, invalidArgument, invalidFingerprint, unsupportedHashAlgorithm } from './error.js'
7
8
  import { CERTHASH_CODE } from './transport.js'
@@ -44,7 +45,7 @@ export function certhash (ma: Multiaddr): string {
44
45
  /**
45
46
  * Convert a certhash into a multihash
46
47
  */
47
- export function decodeCerthash (certhash: string) {
48
+ export function decodeCerthash (certhash: string): { code: HashCode, name: HashName, length: number, digest: Uint8Array } {
48
49
  const mbdecoded = mbdecoder.decode(certhash)
49
50
  return multihashes.decode(mbdecoded)
50
51
  }
package/src/stream.ts CHANGED
@@ -156,55 +156,55 @@ export class WebRTCStream implements Stream {
156
156
  /**
157
157
  * Unique identifier for a stream
158
158
  */
159
- id: string;
159
+ id: string
160
160
 
161
161
  /**
162
162
  * Stats about this stream
163
163
  */
164
- stat: StreamStat;
164
+ stat: StreamStat
165
165
 
166
166
  /**
167
167
  * User defined stream metadata
168
168
  */
169
- metadata: Record<string, any>;
169
+ metadata: Record<string, any>
170
170
 
171
171
  /**
172
172
  * The data channel used to send and receive data
173
173
  */
174
- private readonly channel: RTCDataChannel;
174
+ private readonly channel: RTCDataChannel
175
175
 
176
176
  /**
177
177
  * The current state of the stream
178
178
  */
179
- streamState = new StreamState();
179
+ streamState = new StreamState()
180
180
 
181
181
  /**
182
182
  * Read unwrapped protobuf data from the underlying datachannel.
183
183
  * _src is exposed to the user via the `source` getter to .
184
184
  */
185
- private readonly _src: Source<Uint8ArrayList>;
185
+ private readonly _src: Source<Uint8ArrayList>
186
186
 
187
187
  /**
188
188
  * push data from the underlying datachannel to the length prefix decoder
189
189
  * and then the protobuf decoder.
190
190
  */
191
- private readonly _innersrc = pushable();
191
+ private readonly _innersrc = pushable()
192
192
 
193
193
  /**
194
194
  * Deferred promise that resolves when the underlying datachannel is in the
195
195
  * open state.
196
196
  */
197
- opened: DeferredPromise<void> = defer();
197
+ opened: DeferredPromise<void> = defer()
198
198
 
199
199
  /**
200
200
  * sinkCreated is set to true once the sinkFunction is invoked
201
201
  */
202
- _sinkCalled: boolean = false;
202
+ _sinkCalled: boolean = false
203
203
 
204
204
  /**
205
205
  * Triggers a generator which can be used to close the sink.
206
206
  */
207
- closeWritePromise: DeferredPromise<void> = defer();
207
+ closeWritePromise: DeferredPromise<void> = defer()
208
208
 
209
209
  /**
210
210
  * Callback to invoke when the stream is closed.
@@ -436,7 +436,7 @@ export class WebRTCStream implements Stream {
436
436
  private _sendFlag (flag: pb.Message_Flag): void {
437
437
  try {
438
438
  log.trace('Sending flag: %s', flag.toString())
439
- const msgbuf = pb.Message.toBinary({ flag: flag })
439
+ const msgbuf = pb.Message.toBinary({ flag })
440
440
  this.channel.send(lengthPrefixed.encode.single(msgbuf).subarray())
441
441
  } catch (err) {
442
442
  if (err instanceof Error) {
package/src/util.ts CHANGED
@@ -2,7 +2,7 @@ export const nopSource = {
2
2
  async * [Symbol.asyncIterator] () {}
3
3
  }
4
4
 
5
- export const nopSink = async (_: any) => {}
5
+ export const nopSink = async (_: any): Promise<void> => {}
6
6
 
7
7
  const charset = Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/')
8
8
  export const genUfrag = (len: number): string => [...Array(len)].map(() => charset.at(Math.floor(Math.random() * charset.length))).join('')