@moqtap/trace 0.1.1 → 0.1.2
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 +21 -21
- package/README.md +33 -33
- package/dist/index.d.cts +13 -11
- package/dist/index.d.ts +13 -11
- package/package.json +2 -2
- package/src/binary.ts +156 -153
- package/src/index.ts +6 -6
- package/src/json.ts +7 -7
- package/src/recorder.ts +82 -79
- package/src/types.ts +60 -60
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 moqtap
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 moqtap
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -21,82 +21,82 @@ npm install @moqtap/trace @moqtap/codec
|
|
|
21
21
|
### Recording a session
|
|
22
22
|
|
|
23
23
|
```typescript
|
|
24
|
-
import { createRecorder, writeMoqtrace } from '@moqtap/trace'
|
|
25
|
-
import {
|
|
24
|
+
import { createRecorder, writeMoqtrace } from '@moqtap/trace'
|
|
25
|
+
import { createDraft17SessionState } from '@moqtap/codec/draft17/session'
|
|
26
26
|
|
|
27
27
|
const recorder = createRecorder({
|
|
28
|
-
protocol: 'moq-transport-
|
|
28
|
+
protocol: 'moq-transport-17',
|
|
29
29
|
perspective: 'client',
|
|
30
30
|
detail: 'control',
|
|
31
|
-
})
|
|
31
|
+
})
|
|
32
32
|
|
|
33
33
|
// Wrap a session to auto-capture control messages and state transitions
|
|
34
|
-
const session =
|
|
35
|
-
const traced = recorder.wrapSession(session)
|
|
34
|
+
const session = createDraft17SessionState('client')
|
|
35
|
+
const traced = recorder.wrapSession(session)
|
|
36
36
|
|
|
37
37
|
// Use `traced` instead of `session` — all send/receive calls are recorded
|
|
38
|
-
traced.send(
|
|
39
|
-
traced.receive(
|
|
38
|
+
traced.send(setupMessage)
|
|
39
|
+
traced.receive(setupMessage)
|
|
40
40
|
|
|
41
41
|
// Manually record events the session layer doesn't see
|
|
42
|
-
recorder.recordStreamOpened(4n, 0, 0)
|
|
43
|
-
recorder.annotate('connected', { relay: 'cdn.example.com' })
|
|
42
|
+
recorder.recordStreamOpened(4n, 0, 0) // outgoing subgroup stream
|
|
43
|
+
recorder.annotate('connected', { relay: 'cdn.example.com' })
|
|
44
44
|
|
|
45
45
|
// Finalize and serialize
|
|
46
|
-
const trace = recorder.finalize()
|
|
47
|
-
const bytes = writeMoqtrace(trace)
|
|
46
|
+
const trace = recorder.finalize()
|
|
47
|
+
const bytes = writeMoqtrace(trace) // → Uint8Array (.moqtrace binary)
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
### Reading a trace file
|
|
51
51
|
|
|
52
52
|
```typescript
|
|
53
|
-
import { readMoqtrace, readMoqtraceHeader } from '@moqtap/trace'
|
|
53
|
+
import { readMoqtrace, readMoqtraceHeader } from '@moqtap/trace'
|
|
54
54
|
|
|
55
55
|
// Quick metadata peek (no event parsing)
|
|
56
|
-
const header = readMoqtraceHeader(bytes)
|
|
57
|
-
console.log(header.protocol)
|
|
58
|
-
console.log(header.perspective)
|
|
59
|
-
console.log(header.detail)
|
|
56
|
+
const header = readMoqtraceHeader(bytes)
|
|
57
|
+
console.log(header.protocol) // "moq-transport-17"
|
|
58
|
+
console.log(header.perspective) // "client"
|
|
59
|
+
console.log(header.detail) // "control"
|
|
60
60
|
|
|
61
61
|
// Full parse
|
|
62
|
-
const trace = readMoqtrace(bytes)
|
|
62
|
+
const trace = readMoqtrace(bytes)
|
|
63
63
|
for (const event of trace.events) {
|
|
64
|
-
console.log(event.type, event.timestamp)
|
|
64
|
+
console.log(event.type, event.timestamp)
|
|
65
65
|
}
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
### Streaming writer (for large traces)
|
|
69
69
|
|
|
70
70
|
```typescript
|
|
71
|
-
import { createMoqtraceWriter } from '@moqtap/trace'
|
|
71
|
+
import { createMoqtraceWriter } from '@moqtap/trace'
|
|
72
72
|
|
|
73
|
-
const writer = createMoqtraceWriter(header)
|
|
74
|
-
outputStream.write(writer.preamble())
|
|
73
|
+
const writer = createMoqtraceWriter(header)
|
|
74
|
+
outputStream.write(writer.preamble())
|
|
75
75
|
|
|
76
76
|
for (const event of events) {
|
|
77
|
-
outputStream.write(writer.writeEvent(event))
|
|
77
|
+
outputStream.write(writer.writeEvent(event))
|
|
78
78
|
}
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
## Detail Levels
|
|
82
82
|
|
|
83
|
-
| Level
|
|
84
|
-
|
|
85
|
-
| `control`
|
|
86
|
-
| `headers`
|
|
87
|
-
| `headers+sizes` | + payload byte lengths
|
|
88
|
-
| `headers+data`
|
|
89
|
-
| `full`
|
|
83
|
+
| Level | What's recorded |
|
|
84
|
+
| --------------- | --------------------------------------------------------- |
|
|
85
|
+
| `control` | Control messages only (setup, subscribe, publish, goaway) |
|
|
86
|
+
| `headers` | + data stream headers (subgroup/fetch, object metadata) |
|
|
87
|
+
| `headers+sizes` | + payload byte lengths |
|
|
88
|
+
| `headers+data` | + full payload bytes |
|
|
89
|
+
| `full` | + raw wire bytes (pre-decode) |
|
|
90
90
|
|
|
91
91
|
## JSON Export
|
|
92
92
|
|
|
93
93
|
For human-readable debugging (not lossless — bigint/Uint8Array become strings):
|
|
94
94
|
|
|
95
95
|
```typescript
|
|
96
|
-
import { traceToJSON } from '@moqtap/trace'
|
|
96
|
+
import { traceToJSON } from '@moqtap/trace'
|
|
97
97
|
|
|
98
|
-
const json = traceToJSON(trace)
|
|
99
|
-
console.log(json)
|
|
98
|
+
const json = traceToJSON(trace)
|
|
99
|
+
console.log(json)
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
## File Format
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SessionState } from '@moqtap/codec/session';
|
|
2
2
|
|
|
3
|
-
type DetailLevel =
|
|
4
|
-
type Perspective =
|
|
3
|
+
type DetailLevel = 'control' | 'headers' | 'headers+sizes' | 'headers+data' | 'full';
|
|
4
|
+
type Perspective = 'client' | 'server' | 'observer';
|
|
5
5
|
interface TraceHeader {
|
|
6
6
|
readonly protocol: string;
|
|
7
7
|
readonly perspective: Perspective;
|
|
@@ -19,25 +19,25 @@ interface BaseEvent {
|
|
|
19
19
|
readonly timestamp: number;
|
|
20
20
|
}
|
|
21
21
|
interface ControlMessageEvent extends BaseEvent {
|
|
22
|
-
readonly type:
|
|
22
|
+
readonly type: 'control';
|
|
23
23
|
readonly direction: 0 | 1;
|
|
24
24
|
readonly messageType: number;
|
|
25
25
|
readonly message: Record<string, unknown>;
|
|
26
26
|
readonly raw?: Uint8Array;
|
|
27
27
|
}
|
|
28
28
|
interface StreamOpenedEvent extends BaseEvent {
|
|
29
|
-
readonly type:
|
|
29
|
+
readonly type: 'stream-opened';
|
|
30
30
|
readonly streamId: bigint;
|
|
31
31
|
readonly direction: 0 | 1;
|
|
32
32
|
readonly streamType: 0 | 1 | 2;
|
|
33
33
|
}
|
|
34
34
|
interface StreamClosedEvent extends BaseEvent {
|
|
35
|
-
readonly type:
|
|
35
|
+
readonly type: 'stream-closed';
|
|
36
36
|
readonly streamId: bigint;
|
|
37
37
|
readonly errorCode: number;
|
|
38
38
|
}
|
|
39
39
|
interface ObjectHeaderEvent extends BaseEvent {
|
|
40
|
-
readonly type:
|
|
40
|
+
readonly type: 'object-header';
|
|
41
41
|
readonly streamId: bigint;
|
|
42
42
|
readonly groupId: bigint;
|
|
43
43
|
readonly objectId: bigint;
|
|
@@ -45,7 +45,7 @@ interface ObjectHeaderEvent extends BaseEvent {
|
|
|
45
45
|
readonly objectStatus: number;
|
|
46
46
|
}
|
|
47
47
|
interface ObjectPayloadEvent extends BaseEvent {
|
|
48
|
-
readonly type:
|
|
48
|
+
readonly type: 'object-payload';
|
|
49
49
|
readonly streamId: bigint;
|
|
50
50
|
readonly groupId: bigint;
|
|
51
51
|
readonly objectId: bigint;
|
|
@@ -53,17 +53,17 @@ interface ObjectPayloadEvent extends BaseEvent {
|
|
|
53
53
|
readonly payload?: Uint8Array;
|
|
54
54
|
}
|
|
55
55
|
interface StateChangeEvent extends BaseEvent {
|
|
56
|
-
readonly type:
|
|
56
|
+
readonly type: 'state-change';
|
|
57
57
|
readonly from: string;
|
|
58
58
|
readonly to: string;
|
|
59
59
|
}
|
|
60
60
|
interface TraceErrorEvent extends BaseEvent {
|
|
61
|
-
readonly type:
|
|
61
|
+
readonly type: 'error';
|
|
62
62
|
readonly errorCode: number;
|
|
63
63
|
readonly reason: string;
|
|
64
64
|
}
|
|
65
65
|
interface AnnotationEvent extends BaseEvent {
|
|
66
|
-
readonly type:
|
|
66
|
+
readonly type: 'annotation';
|
|
67
67
|
readonly label: string;
|
|
68
68
|
readonly data: unknown;
|
|
69
69
|
}
|
|
@@ -121,7 +121,9 @@ declare function traceToJSON(trace: Trace): string;
|
|
|
121
121
|
|
|
122
122
|
interface TraceRecorder {
|
|
123
123
|
/** Wrap a SessionState to auto-record control messages and state changes. */
|
|
124
|
-
wrapSession
|
|
124
|
+
wrapSession<M extends {
|
|
125
|
+
type: string;
|
|
126
|
+
}, T extends string>(session: SessionState<M, T>): SessionState<M, T>;
|
|
125
127
|
/** Record an arbitrary event manually. */
|
|
126
128
|
record(event: TraceEvent): void;
|
|
127
129
|
/** Record a stream-opened event. Ignored at 'control' detail level. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SessionState } from '@moqtap/codec/session';
|
|
2
2
|
|
|
3
|
-
type DetailLevel =
|
|
4
|
-
type Perspective =
|
|
3
|
+
type DetailLevel = 'control' | 'headers' | 'headers+sizes' | 'headers+data' | 'full';
|
|
4
|
+
type Perspective = 'client' | 'server' | 'observer';
|
|
5
5
|
interface TraceHeader {
|
|
6
6
|
readonly protocol: string;
|
|
7
7
|
readonly perspective: Perspective;
|
|
@@ -19,25 +19,25 @@ interface BaseEvent {
|
|
|
19
19
|
readonly timestamp: number;
|
|
20
20
|
}
|
|
21
21
|
interface ControlMessageEvent extends BaseEvent {
|
|
22
|
-
readonly type:
|
|
22
|
+
readonly type: 'control';
|
|
23
23
|
readonly direction: 0 | 1;
|
|
24
24
|
readonly messageType: number;
|
|
25
25
|
readonly message: Record<string, unknown>;
|
|
26
26
|
readonly raw?: Uint8Array;
|
|
27
27
|
}
|
|
28
28
|
interface StreamOpenedEvent extends BaseEvent {
|
|
29
|
-
readonly type:
|
|
29
|
+
readonly type: 'stream-opened';
|
|
30
30
|
readonly streamId: bigint;
|
|
31
31
|
readonly direction: 0 | 1;
|
|
32
32
|
readonly streamType: 0 | 1 | 2;
|
|
33
33
|
}
|
|
34
34
|
interface StreamClosedEvent extends BaseEvent {
|
|
35
|
-
readonly type:
|
|
35
|
+
readonly type: 'stream-closed';
|
|
36
36
|
readonly streamId: bigint;
|
|
37
37
|
readonly errorCode: number;
|
|
38
38
|
}
|
|
39
39
|
interface ObjectHeaderEvent extends BaseEvent {
|
|
40
|
-
readonly type:
|
|
40
|
+
readonly type: 'object-header';
|
|
41
41
|
readonly streamId: bigint;
|
|
42
42
|
readonly groupId: bigint;
|
|
43
43
|
readonly objectId: bigint;
|
|
@@ -45,7 +45,7 @@ interface ObjectHeaderEvent extends BaseEvent {
|
|
|
45
45
|
readonly objectStatus: number;
|
|
46
46
|
}
|
|
47
47
|
interface ObjectPayloadEvent extends BaseEvent {
|
|
48
|
-
readonly type:
|
|
48
|
+
readonly type: 'object-payload';
|
|
49
49
|
readonly streamId: bigint;
|
|
50
50
|
readonly groupId: bigint;
|
|
51
51
|
readonly objectId: bigint;
|
|
@@ -53,17 +53,17 @@ interface ObjectPayloadEvent extends BaseEvent {
|
|
|
53
53
|
readonly payload?: Uint8Array;
|
|
54
54
|
}
|
|
55
55
|
interface StateChangeEvent extends BaseEvent {
|
|
56
|
-
readonly type:
|
|
56
|
+
readonly type: 'state-change';
|
|
57
57
|
readonly from: string;
|
|
58
58
|
readonly to: string;
|
|
59
59
|
}
|
|
60
60
|
interface TraceErrorEvent extends BaseEvent {
|
|
61
|
-
readonly type:
|
|
61
|
+
readonly type: 'error';
|
|
62
62
|
readonly errorCode: number;
|
|
63
63
|
readonly reason: string;
|
|
64
64
|
}
|
|
65
65
|
interface AnnotationEvent extends BaseEvent {
|
|
66
|
-
readonly type:
|
|
66
|
+
readonly type: 'annotation';
|
|
67
67
|
readonly label: string;
|
|
68
68
|
readonly data: unknown;
|
|
69
69
|
}
|
|
@@ -121,7 +121,9 @@ declare function traceToJSON(trace: Trace): string;
|
|
|
121
121
|
|
|
122
122
|
interface TraceRecorder {
|
|
123
123
|
/** Wrap a SessionState to auto-record control messages and state changes. */
|
|
124
|
-
wrapSession
|
|
124
|
+
wrapSession<M extends {
|
|
125
|
+
type: string;
|
|
126
|
+
}, T extends string>(session: SessionState<M, T>): SessionState<M, T>;
|
|
125
127
|
/** Record an arbitrary event manually. */
|
|
126
128
|
record(event: TraceEvent): void;
|
|
127
129
|
/** Record a stream-opened event. Ignored at 'control' detail level. */
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moqtap/trace",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "MoQT session trace format — record, serialize, and analyze .moqtrace files",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "moqtap",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/moqtap/moqtap-js.git",
|
|
10
|
+
"url": "git+https://github.com/moqtap/moqtap-js.git",
|
|
11
11
|
"directory": "packages/trace"
|
|
12
12
|
},
|
|
13
13
|
"homepage": "https://github.com/moqtap/moqtap-js/tree/master/packages/trace",
|