nerdbank-streams 2.10.22-alpha → 2.10.37-alpha
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/js/Channel.d.ts +9 -8
- package/js/Channel.js +21 -14
- package/js/Channel.js.map +1 -1
- package/js/ControlCode.d.ts +6 -6
- package/js/ControlCode.js +6 -6
- package/js/ControlCode.js.map +1 -1
- package/js/Deferred.js.map +1 -1
- package/js/FrameHeader.d.ts +2 -2
- package/js/FrameHeader.js +2 -2
- package/js/FrameHeader.js.map +1 -1
- package/js/FullDuplexStream.d.ts +1 -1
- package/js/FullDuplexStream.js +2 -0
- package/js/FullDuplexStream.js.map +1 -1
- package/js/MultiplexingStream.d.ts +19 -19
- package/js/MultiplexingStream.js +67 -63
- package/js/MultiplexingStream.js.map +1 -1
- package/js/MultiplexingStreamFormatters.d.ts +9 -7
- package/js/MultiplexingStreamFormatters.js +44 -20
- package/js/MultiplexingStreamFormatters.js.map +1 -1
- package/js/MultiplexingStreamOptions.d.ts +1 -1
- package/js/QualifiedChannelId.js +10 -4
- package/js/QualifiedChannelId.js.map +1 -1
- package/js/Utilities.d.ts +3 -3
- package/js/Utilities.js +10 -10
- package/js/Utilities.js.map +1 -1
- package/js/index.d.ts +8 -8
- package/js/index.js.map +1 -1
- package/package.json +16 -6
- package/src/AcceptanceParameters.ts +2 -2
- package/src/Channel.ts +279 -277
- package/src/ChannelOptions.ts +2 -2
- package/src/ControlCode.ts +25 -25
- package/src/Deferred.ts +61 -61
- package/src/FrameHeader.ts +35 -35
- package/src/FullDuplexStream.ts +25 -23
- package/src/IChannelOfferEventArgs.ts +12 -12
- package/src/IDisposableObservable.ts +2 -2
- package/src/MultiplexingStream.ts +731 -727
- package/src/MultiplexingStreamFormatters.ts +355 -332
- package/src/MultiplexingStreamOptions.ts +16 -16
- package/src/OfferParameters.ts +4 -4
- package/src/QualifiedChannelId.ts +27 -21
- package/src/Utilities.ts +159 -162
- package/src/index.ts +8 -8
package/src/Deferred.ts
CHANGED
|
@@ -2,74 +2,74 @@
|
|
|
2
2
|
* A TaskCompletionSource-like class that allows promises to be resolved or rejected whenever.
|
|
3
3
|
*/
|
|
4
4
|
export class Deferred<T> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
public readonly promise: Promise<T>
|
|
6
|
+
private resolvePromise!: (value: T | PromiseLike<T>) => void
|
|
7
|
+
private rejectPromise!: (reason?: any) => void
|
|
8
|
+
private _isResolved: boolean = false
|
|
9
|
+
private _isRejected: boolean = false
|
|
10
|
+
private _error: any
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
constructor(public state?: any) {
|
|
13
|
+
this.promise = new Promise<T>((resolve, reject) => {
|
|
14
|
+
this.resolvePromise = resolve
|
|
15
|
+
this.rejectPromise = reject
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Gets a value indicating whether this promise has been completed.
|
|
21
|
+
*/
|
|
22
|
+
public get isCompleted() {
|
|
23
|
+
return this._isResolved || this._isRejected
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Gets a value indicating whether this promise is resolved.
|
|
28
|
+
*/
|
|
29
|
+
public get isResolved() {
|
|
30
|
+
return this._isResolved
|
|
31
|
+
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Gets a value indicating whether this promise is rejected.
|
|
35
|
+
*/
|
|
36
|
+
public get isRejected() {
|
|
37
|
+
return this._isRejected
|
|
38
|
+
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Gets the reason for promise rejection, if applicable.
|
|
42
|
+
*/
|
|
43
|
+
public get error() {
|
|
44
|
+
return this._error
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the promise.
|
|
49
|
+
* @param value The result of the promise.
|
|
50
|
+
*/
|
|
51
|
+
public resolve(value: T | PromiseLike<T>): boolean {
|
|
52
|
+
if (this.isCompleted) {
|
|
53
|
+
return false
|
|
54
|
+
}
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
this.resolvePromise(value)
|
|
57
|
+
this._isResolved = true
|
|
58
|
+
return true
|
|
59
|
+
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Rejects the promise.
|
|
63
|
+
* @param reason The reason for rejecting the promise.
|
|
64
|
+
*/
|
|
65
|
+
public reject(reason?: any): boolean {
|
|
66
|
+
if (this.isCompleted) {
|
|
67
|
+
return false
|
|
68
|
+
}
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
this.rejectPromise(reason)
|
|
71
|
+
this._error = reason
|
|
72
|
+
this._isRejected = true
|
|
73
|
+
return true
|
|
74
|
+
}
|
|
75
75
|
}
|
package/src/FrameHeader.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { ControlCode } from
|
|
2
|
-
import { requireInteger } from
|
|
3
|
-
import { QualifiedChannelId } from
|
|
1
|
+
import { ControlCode } from './ControlCode'
|
|
2
|
+
import { requireInteger } from './Utilities'
|
|
3
|
+
import { QualifiedChannelId } from './QualifiedChannelId'
|
|
4
4
|
|
|
5
5
|
export class FrameHeader {
|
|
6
|
-
|
|
6
|
+
private _channel?: QualifiedChannelId
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Initializes a new instance of the `FrameHeader` class.
|
|
10
|
+
* @param code The kind of frame this is.
|
|
11
|
+
* @param channel The channel that this frame refers to or carries a payload for.
|
|
12
|
+
*/
|
|
13
|
+
constructor(public readonly code: ControlCode, channel?: QualifiedChannelId) {
|
|
14
|
+
if (channel) {
|
|
15
|
+
requireInteger('channelId', channel.id, 4, 'signed')
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
this.code = code
|
|
19
|
+
this._channel = channel
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
/** The channel that this frame refers to or carries a payload for. */
|
|
23
|
+
get channel(): QualifiedChannelId | undefined {
|
|
24
|
+
return this._channel
|
|
25
|
+
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Gets the channel that this frame refers to or carries a payload for.
|
|
29
|
+
*/
|
|
30
|
+
public get requiredChannel(): QualifiedChannelId {
|
|
31
|
+
if (this.channel) {
|
|
32
|
+
return this.channel
|
|
33
|
+
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
throw new Error('Expected channel not present in frame header.')
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
/** Changes the channel.source property to reflect the opposite perspective (i.e. remote and local values switch). */
|
|
39
|
+
public flipChannelPerspective() {
|
|
40
|
+
if (this._channel) {
|
|
41
|
+
this._channel = { id: this._channel.id, source: this._channel.source * -1 }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
44
|
}
|
package/src/FullDuplexStream.ts
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import { Duplex, PassThrough } from
|
|
1
|
+
import { Duplex, PassThrough } from 'stream'
|
|
2
2
|
|
|
3
3
|
export class FullDuplexStream {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5
|
+
public static CreatePair(): { first: Duplex; second: Duplex } {
|
|
6
|
+
const pass1 = new PassThrough()
|
|
7
|
+
const pass2 = new PassThrough()
|
|
8
|
+
return {
|
|
9
|
+
first: FullDuplexStream.Splice(pass1, pass2),
|
|
10
|
+
second: FullDuplexStream.Splice(pass2, pass1),
|
|
11
|
+
}
|
|
12
|
+
}
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
15
|
+
public static Splice(readable: NodeJS.ReadableStream, writable: NodeJS.WritableStream): Duplex {
|
|
16
|
+
const duplex = new Duplex({
|
|
17
|
+
write(chunk, encoding, callback) {
|
|
18
|
+
writable.write(chunk, encoding, callback)
|
|
19
|
+
},
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
final(callback) {
|
|
22
|
+
writable.end(callback)
|
|
23
|
+
},
|
|
24
|
+
})
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
// All reads and events come directly from the readable stream.
|
|
27
|
+
duplex.read = readable.read.bind(readable)
|
|
28
|
+
duplex.on = readable.on.bind(readable) as any
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
return duplex
|
|
31
|
+
}
|
|
30
32
|
}
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
* Describes an offer for a channel.
|
|
3
3
|
*/
|
|
4
4
|
export interface IChannelOfferEventArgs {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Gets the unique ID of the channel.
|
|
7
|
+
*/
|
|
8
|
+
readonly id: number
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Gets the name of the channel.
|
|
12
|
+
*/
|
|
13
|
+
readonly name: string
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Gets a value indicating whether the channel has already been accepted.
|
|
17
|
+
*/
|
|
18
|
+
readonly isAccepted: boolean
|
|
19
19
|
}
|