warpr 1.0.0 → 1.0.9
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/README.md +24 -24
- package/ng-package.json +6 -6
- package/package.json +1 -1
- package/src/lib/components/stream-host/stream-host.component.html +5 -5
- package/src/lib/components/stream-host/stream-host.component.scss +31 -31
- package/src/lib/components/stream-host/stream-host.component.spec.ts +23 -23
- package/src/lib/components/stream-host/stream-host.component.ts +170 -170
- package/src/lib/data/frames.ts +37 -37
- package/src/lib/data/signaling-messages.ts +37 -37
- package/src/lib/data/streaming-messages.ts +136 -136
- package/src/lib/infrastructure/array-stream.ts +109 -109
- package/src/lib/infrastructure/events.ts +61 -61
- package/src/lib/infrastructure/message-assembler.ts +60 -60
- package/src/lib/networking/messaging-client.ts +7 -7
- package/src/lib/networking/web-socket-client.ts +50 -50
- package/src/lib/services/messaging.service.spec.ts +16 -16
- package/src/lib/services/messaging.service.ts +31 -31
- package/src/lib/services/streaming.service.spec.ts +16 -16
- package/src/lib/services/streaming.service.ts +150 -150
- package/src/public-api.ts +15 -15
- package/tsconfig.lib.json +14 -14
- package/tsconfig.lib.prod.json +10 -10
- package/tsconfig.spec.json +14 -14
- package/warpr-1.0.9.tgz +0 -0
- package/warpr-1.0.0.0.tgz +0 -0
- package/warpr-1.0.0.tgz +0 -0
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
export enum WarprSignalingMessageType {
|
|
3
|
-
ConnectionRequest = "ConnectionRequest",
|
|
4
|
-
PairingCompleteMessage = "PairingCompleteMessage",
|
|
5
|
-
PeerConnectionDescriptionMessage = "PeerConnectionDescriptionMessage",
|
|
6
|
-
PeerConnectionCandidateMessage = "PeerConnectionCandidateMessage",
|
|
7
|
-
StreamingSourcesMessage = "StreamingSourcesMessage",
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class ConnectionRequest {
|
|
11
|
-
public readonly $type = WarprSignalingMessageType.ConnectionRequest;
|
|
12
|
-
public SessionId?: string;
|
|
13
|
-
}
|
|
14
|
-
export class PairingCompleteMessage {
|
|
15
|
-
public readonly $type = WarprSignalingMessageType.PairingCompleteMessage;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class PeerConnectionDescriptionMessage {
|
|
19
|
-
public readonly $type = WarprSignalingMessageType.PeerConnectionDescriptionMessage;
|
|
20
|
-
public Description?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class PeerConnectionCandidateMessage {
|
|
24
|
-
public readonly $type = WarprSignalingMessageType.PeerConnectionCandidateMessage;
|
|
25
|
-
public Candidate?: string;
|
|
26
|
-
}
|
|
27
|
-
export class StreamingSourcesMessage {
|
|
28
|
-
public readonly $type = WarprSignalingMessageType.StreamingSourcesMessage;
|
|
29
|
-
public Sources?: string[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type WarprSignalingMessage =
|
|
33
|
-
ConnectionRequest |
|
|
34
|
-
PairingCompleteMessage |
|
|
35
|
-
PeerConnectionDescriptionMessage |
|
|
36
|
-
PeerConnectionCandidateMessage |
|
|
37
|
-
StreamingSourcesMessage;
|
|
1
|
+
|
|
2
|
+
export enum WarprSignalingMessageType {
|
|
3
|
+
ConnectionRequest = "ConnectionRequest",
|
|
4
|
+
PairingCompleteMessage = "PairingCompleteMessage",
|
|
5
|
+
PeerConnectionDescriptionMessage = "PeerConnectionDescriptionMessage",
|
|
6
|
+
PeerConnectionCandidateMessage = "PeerConnectionCandidateMessage",
|
|
7
|
+
StreamingSourcesMessage = "StreamingSourcesMessage",
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class ConnectionRequest {
|
|
11
|
+
public readonly $type = WarprSignalingMessageType.ConnectionRequest;
|
|
12
|
+
public SessionId?: string;
|
|
13
|
+
}
|
|
14
|
+
export class PairingCompleteMessage {
|
|
15
|
+
public readonly $type = WarprSignalingMessageType.PairingCompleteMessage;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class PeerConnectionDescriptionMessage {
|
|
19
|
+
public readonly $type = WarprSignalingMessageType.PeerConnectionDescriptionMessage;
|
|
20
|
+
public Description?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class PeerConnectionCandidateMessage {
|
|
24
|
+
public readonly $type = WarprSignalingMessageType.PeerConnectionCandidateMessage;
|
|
25
|
+
public Candidate?: string;
|
|
26
|
+
}
|
|
27
|
+
export class StreamingSourcesMessage {
|
|
28
|
+
public readonly $type = WarprSignalingMessageType.StreamingSourcesMessage;
|
|
29
|
+
public Sources?: string[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type WarprSignalingMessage =
|
|
33
|
+
ConnectionRequest |
|
|
34
|
+
PairingCompleteMessage |
|
|
35
|
+
PeerConnectionDescriptionMessage |
|
|
36
|
+
PeerConnectionCandidateMessage |
|
|
37
|
+
StreamingSourcesMessage;
|
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
export enum WarprStreamingMessageType {
|
|
2
|
-
PointerInputMessage = "PointerInputMessage",
|
|
3
|
-
ResizeSurfaceMessage = "ResizeSurfaceMessage"
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export type Point = {
|
|
7
|
-
X: number;
|
|
8
|
-
Y: number;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export enum PointerType {
|
|
12
|
-
Unknown = "Unknown",
|
|
13
|
-
Mouse = "Mouse",
|
|
14
|
-
Pen = "Pen",
|
|
15
|
-
Touch = "Touch"
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export enum PointerAction {
|
|
19
|
-
Unknown = "Unknown",
|
|
20
|
-
Pressed = "Pressed",
|
|
21
|
-
Moved = "Moved",
|
|
22
|
-
Released = "Released",
|
|
23
|
-
WheelChanged = "WheelChanged"
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export enum PointerFlags {
|
|
27
|
-
None = 0,
|
|
28
|
-
LeftButton = 1,
|
|
29
|
-
MiddleButton = 2,
|
|
30
|
-
RightButton = 4,
|
|
31
|
-
Wheel = 8,
|
|
32
|
-
Captured = 16
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export class PointerState {
|
|
36
|
-
public Buttons = 0;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type PointerStates = { [key: number]: PointerState };
|
|
40
|
-
|
|
41
|
-
export class PointerInputMessage {
|
|
42
|
-
public readonly $type = WarprStreamingMessageType.PointerInputMessage;
|
|
43
|
-
|
|
44
|
-
public Id = -1;
|
|
45
|
-
public Type = PointerType.Unknown;
|
|
46
|
-
public Action = PointerAction.Unknown;
|
|
47
|
-
public Position: Point = { X: 0, Y: 0 };
|
|
48
|
-
public Flags = PointerFlags.None;
|
|
49
|
-
public WheelDelta = 0;
|
|
50
|
-
|
|
51
|
-
constructor(event: PointerEvent, states: PointerStates, target: HTMLCanvasElement, wheelDelta: number) {
|
|
52
|
-
|
|
53
|
-
let state = states[event.pointerId];
|
|
54
|
-
if (state === undefined) {
|
|
55
|
-
state = new PointerState();
|
|
56
|
-
states[event.pointerId] = state;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
this.Id = event.pointerId;
|
|
60
|
-
|
|
61
|
-
switch (event.pointerType) {
|
|
62
|
-
case "mouse":
|
|
63
|
-
this.Type = PointerType.Mouse;
|
|
64
|
-
break;
|
|
65
|
-
case "pen":
|
|
66
|
-
this.Type = PointerType.Pen;
|
|
67
|
-
break;
|
|
68
|
-
case "touch":
|
|
69
|
-
this.Type = PointerType.Touch;
|
|
70
|
-
break;
|
|
71
|
-
default:
|
|
72
|
-
this.Type = PointerType.Mouse;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
switch (event.type) {
|
|
77
|
-
case "pointerdown":
|
|
78
|
-
this.Action = PointerAction.Pressed;
|
|
79
|
-
state.Buttons |= 1 << event.button
|
|
80
|
-
break;
|
|
81
|
-
case "pointerup":
|
|
82
|
-
this.Action = PointerAction.Released;
|
|
83
|
-
state.Buttons &= ~(1 << event.button)
|
|
84
|
-
break;
|
|
85
|
-
case "pointermove":
|
|
86
|
-
this.Action = PointerAction.Moved;
|
|
87
|
-
break;
|
|
88
|
-
case "wheel":
|
|
89
|
-
this.Action = PointerAction.WheelChanged;
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (state.Buttons & 1) this.Flags |= PointerFlags.LeftButton;
|
|
94
|
-
if (state.Buttons & 2) this.Flags |= PointerFlags.MiddleButton;
|
|
95
|
-
if (state.Buttons & 4) this.Flags |= PointerFlags.RightButton;
|
|
96
|
-
if (wheelDelta != 0) this.Flags |= PointerFlags.Wheel;
|
|
97
|
-
if (target.hasPointerCapture(event.pointerId)) this.Flags |= PointerFlags.Captured;
|
|
98
|
-
|
|
99
|
-
this.Position = PointerInputMessage.GetRemotePosition(event, target);
|
|
100
|
-
this.WheelDelta = -wheelDelta;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private static GetRemotePosition(event: PointerEvent, target: HTMLCanvasElement): Point {
|
|
104
|
-
let offsetX = 0;
|
|
105
|
-
let offsetY = 0;
|
|
106
|
-
let scale = 1;
|
|
107
|
-
let canvasAspectRatio = target.clientWidth / target.clientHeight;
|
|
108
|
-
let videoAspectRatio = target.width / target.height;
|
|
109
|
-
|
|
110
|
-
if (videoAspectRatio > canvasAspectRatio) {
|
|
111
|
-
offsetY = 0.5 * (target.clientHeight - target.clientWidth / videoAspectRatio);
|
|
112
|
-
scale = target.width / target.clientWidth;
|
|
113
|
-
} else {
|
|
114
|
-
offsetX = 0.5 * (target.clientWidth - target.clientHeight * videoAspectRatio);
|
|
115
|
-
scale = target.height / target.clientHeight;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
X: (event.x - offsetX) * scale,
|
|
120
|
-
Y: (event.y - offsetY) * scale
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export class ResizeSurfaceMessage {
|
|
126
|
-
public readonly $type = WarprStreamingMessageType.ResizeSurfaceMessage;
|
|
127
|
-
|
|
128
|
-
constructor(
|
|
129
|
-
public Width: number,
|
|
130
|
-
public Height: number
|
|
131
|
-
) { }
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export type WarprStreamingMessage =
|
|
135
|
-
PointerInputMessage |
|
|
136
|
-
ResizeSurfaceMessage;
|
|
1
|
+
export enum WarprStreamingMessageType {
|
|
2
|
+
PointerInputMessage = "PointerInputMessage",
|
|
3
|
+
ResizeSurfaceMessage = "ResizeSurfaceMessage"
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export type Point = {
|
|
7
|
+
X: number;
|
|
8
|
+
Y: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export enum PointerType {
|
|
12
|
+
Unknown = "Unknown",
|
|
13
|
+
Mouse = "Mouse",
|
|
14
|
+
Pen = "Pen",
|
|
15
|
+
Touch = "Touch"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export enum PointerAction {
|
|
19
|
+
Unknown = "Unknown",
|
|
20
|
+
Pressed = "Pressed",
|
|
21
|
+
Moved = "Moved",
|
|
22
|
+
Released = "Released",
|
|
23
|
+
WheelChanged = "WheelChanged"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export enum PointerFlags {
|
|
27
|
+
None = 0,
|
|
28
|
+
LeftButton = 1,
|
|
29
|
+
MiddleButton = 2,
|
|
30
|
+
RightButton = 4,
|
|
31
|
+
Wheel = 8,
|
|
32
|
+
Captured = 16
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export class PointerState {
|
|
36
|
+
public Buttons = 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type PointerStates = { [key: number]: PointerState };
|
|
40
|
+
|
|
41
|
+
export class PointerInputMessage {
|
|
42
|
+
public readonly $type = WarprStreamingMessageType.PointerInputMessage;
|
|
43
|
+
|
|
44
|
+
public Id = -1;
|
|
45
|
+
public Type = PointerType.Unknown;
|
|
46
|
+
public Action = PointerAction.Unknown;
|
|
47
|
+
public Position: Point = { X: 0, Y: 0 };
|
|
48
|
+
public Flags = PointerFlags.None;
|
|
49
|
+
public WheelDelta = 0;
|
|
50
|
+
|
|
51
|
+
constructor(event: PointerEvent, states: PointerStates, target: HTMLCanvasElement, wheelDelta: number) {
|
|
52
|
+
|
|
53
|
+
let state = states[event.pointerId];
|
|
54
|
+
if (state === undefined) {
|
|
55
|
+
state = new PointerState();
|
|
56
|
+
states[event.pointerId] = state;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
this.Id = event.pointerId;
|
|
60
|
+
|
|
61
|
+
switch (event.pointerType) {
|
|
62
|
+
case "mouse":
|
|
63
|
+
this.Type = PointerType.Mouse;
|
|
64
|
+
break;
|
|
65
|
+
case "pen":
|
|
66
|
+
this.Type = PointerType.Pen;
|
|
67
|
+
break;
|
|
68
|
+
case "touch":
|
|
69
|
+
this.Type = PointerType.Touch;
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
this.Type = PointerType.Mouse;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
switch (event.type) {
|
|
77
|
+
case "pointerdown":
|
|
78
|
+
this.Action = PointerAction.Pressed;
|
|
79
|
+
state.Buttons |= 1 << event.button
|
|
80
|
+
break;
|
|
81
|
+
case "pointerup":
|
|
82
|
+
this.Action = PointerAction.Released;
|
|
83
|
+
state.Buttons &= ~(1 << event.button)
|
|
84
|
+
break;
|
|
85
|
+
case "pointermove":
|
|
86
|
+
this.Action = PointerAction.Moved;
|
|
87
|
+
break;
|
|
88
|
+
case "wheel":
|
|
89
|
+
this.Action = PointerAction.WheelChanged;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (state.Buttons & 1) this.Flags |= PointerFlags.LeftButton;
|
|
94
|
+
if (state.Buttons & 2) this.Flags |= PointerFlags.MiddleButton;
|
|
95
|
+
if (state.Buttons & 4) this.Flags |= PointerFlags.RightButton;
|
|
96
|
+
if (wheelDelta != 0) this.Flags |= PointerFlags.Wheel;
|
|
97
|
+
if (target.hasPointerCapture(event.pointerId)) this.Flags |= PointerFlags.Captured;
|
|
98
|
+
|
|
99
|
+
this.Position = PointerInputMessage.GetRemotePosition(event, target);
|
|
100
|
+
this.WheelDelta = -wheelDelta;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private static GetRemotePosition(event: PointerEvent, target: HTMLCanvasElement): Point {
|
|
104
|
+
let offsetX = 0;
|
|
105
|
+
let offsetY = 0;
|
|
106
|
+
let scale = 1;
|
|
107
|
+
let canvasAspectRatio = target.clientWidth / target.clientHeight;
|
|
108
|
+
let videoAspectRatio = target.width / target.height;
|
|
109
|
+
|
|
110
|
+
if (videoAspectRatio > canvasAspectRatio) {
|
|
111
|
+
offsetY = 0.5 * (target.clientHeight - target.clientWidth / videoAspectRatio);
|
|
112
|
+
scale = target.width / target.clientWidth;
|
|
113
|
+
} else {
|
|
114
|
+
offsetX = 0.5 * (target.clientWidth - target.clientHeight * videoAspectRatio);
|
|
115
|
+
scale = target.height / target.clientHeight;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
X: (event.x - offsetX) * scale,
|
|
120
|
+
Y: (event.y - offsetY) * scale
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export class ResizeSurfaceMessage {
|
|
126
|
+
public readonly $type = WarprStreamingMessageType.ResizeSurfaceMessage;
|
|
127
|
+
|
|
128
|
+
constructor(
|
|
129
|
+
public Width: number,
|
|
130
|
+
public Height: number
|
|
131
|
+
) { }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type WarprStreamingMessage =
|
|
135
|
+
PointerInputMessage |
|
|
136
|
+
ResizeSurfaceMessage;
|
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
export class ArrayStream {
|
|
2
|
-
private _view: DataView;
|
|
3
|
-
private _position: number;
|
|
4
|
-
|
|
5
|
-
public constructor(buffer: ArrayBuffer) {
|
|
6
|
-
this._view = new DataView(buffer);
|
|
7
|
-
this._position = 0;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public get Position(): number {
|
|
11
|
-
return this._position;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public set Position(value: number) {
|
|
15
|
-
if (value < 0 || this._view.buffer.byteLength < value) {
|
|
16
|
-
throw new RangeError("The provided value lies outside the stream's bounds.");
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
this._position = value;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public ReadBool(): boolean {
|
|
23
|
-
let result = this._view.getUint8(this._position) != 0;
|
|
24
|
-
this._position += 1;
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public ReadUInt8(): number {
|
|
29
|
-
let result = this._view.getUint8(this._position);
|
|
30
|
-
this._position += 1;
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public ReadUInt16(): number {
|
|
35
|
-
let result = this._view.getUint16(this._position, true);
|
|
36
|
-
this._position += 2;
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public ReadUInt32(): number {
|
|
41
|
-
let result = this._view.getUint32(this._position, true);
|
|
42
|
-
this._position += 4;
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public ReadUInt64(): bigint {
|
|
47
|
-
let result = this._view.getBigUint64(this._position, true);
|
|
48
|
-
this._position += 8;
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public ReadInt8(): number {
|
|
53
|
-
let result = this._view.getInt8(this._position);
|
|
54
|
-
this._position += 1;
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public ReadInt16(): number {
|
|
59
|
-
let result = this._view.getInt16(this._position, true);
|
|
60
|
-
this._position += 2;
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
public ReadInt32(): number {
|
|
65
|
-
let result = this._view.getInt32(this._position, true);
|
|
66
|
-
this._position += 4;
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public ReadInt64(): bigint {
|
|
71
|
-
let result = this._view.getBigInt64(this._position, true);
|
|
72
|
-
this._position += 8;
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public ReadSingle(): number {
|
|
77
|
-
let result = this._view.getFloat32(this._position, true);
|
|
78
|
-
this._position += 4;
|
|
79
|
-
return result;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public ReadDouble(): number {
|
|
83
|
-
let result = this._view.getFloat64(this._position, true);
|
|
84
|
-
this._position += 8;
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public ReadBuffer(): ArrayBuffer {
|
|
89
|
-
let length = this.ReadUInt32();
|
|
90
|
-
let result = this._view.buffer.slice(this._position, this._position + length);
|
|
91
|
-
this._position += length;
|
|
92
|
-
return result;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
public ReadToEnd(): ArrayBuffer {
|
|
96
|
-
let length = this._view.buffer.byteLength - this._position;
|
|
97
|
-
let result = this._view.buffer.slice(this._position, this._position + length);
|
|
98
|
-
this._position += length;
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
public ReadString() {
|
|
103
|
-
let length = this.ReadUInt32();
|
|
104
|
-
let decoder = new TextDecoder();
|
|
105
|
-
let result = decoder.decode(this._view.buffer.slice(this._position, this._position + length));
|
|
106
|
-
this._position += length;
|
|
107
|
-
return result;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
1
|
+
export class ArrayStream {
|
|
2
|
+
private _view: DataView;
|
|
3
|
+
private _position: number;
|
|
4
|
+
|
|
5
|
+
public constructor(buffer: ArrayBuffer) {
|
|
6
|
+
this._view = new DataView(buffer);
|
|
7
|
+
this._position = 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public get Position(): number {
|
|
11
|
+
return this._position;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public set Position(value: number) {
|
|
15
|
+
if (value < 0 || this._view.buffer.byteLength < value) {
|
|
16
|
+
throw new RangeError("The provided value lies outside the stream's bounds.");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this._position = value;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public ReadBool(): boolean {
|
|
23
|
+
let result = this._view.getUint8(this._position) != 0;
|
|
24
|
+
this._position += 1;
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public ReadUInt8(): number {
|
|
29
|
+
let result = this._view.getUint8(this._position);
|
|
30
|
+
this._position += 1;
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public ReadUInt16(): number {
|
|
35
|
+
let result = this._view.getUint16(this._position, true);
|
|
36
|
+
this._position += 2;
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public ReadUInt32(): number {
|
|
41
|
+
let result = this._view.getUint32(this._position, true);
|
|
42
|
+
this._position += 4;
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public ReadUInt64(): bigint {
|
|
47
|
+
let result = this._view.getBigUint64(this._position, true);
|
|
48
|
+
this._position += 8;
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public ReadInt8(): number {
|
|
53
|
+
let result = this._view.getInt8(this._position);
|
|
54
|
+
this._position += 1;
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public ReadInt16(): number {
|
|
59
|
+
let result = this._view.getInt16(this._position, true);
|
|
60
|
+
this._position += 2;
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public ReadInt32(): number {
|
|
65
|
+
let result = this._view.getInt32(this._position, true);
|
|
66
|
+
this._position += 4;
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public ReadInt64(): bigint {
|
|
71
|
+
let result = this._view.getBigInt64(this._position, true);
|
|
72
|
+
this._position += 8;
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public ReadSingle(): number {
|
|
77
|
+
let result = this._view.getFloat32(this._position, true);
|
|
78
|
+
this._position += 4;
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public ReadDouble(): number {
|
|
83
|
+
let result = this._view.getFloat64(this._position, true);
|
|
84
|
+
this._position += 8;
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public ReadBuffer(): ArrayBuffer {
|
|
89
|
+
let length = this.ReadUInt32();
|
|
90
|
+
let result = this._view.buffer.slice(this._position, this._position + length);
|
|
91
|
+
this._position += length;
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
public ReadToEnd(): ArrayBuffer {
|
|
96
|
+
let length = this._view.buffer.byteLength - this._position;
|
|
97
|
+
let result = this._view.buffer.slice(this._position, this._position + length);
|
|
98
|
+
this._position += length;
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public ReadString() {
|
|
103
|
+
let length = this.ReadUInt32();
|
|
104
|
+
let decoder = new TextDecoder();
|
|
105
|
+
let result = decoder.decode(this._view.buffer.slice(this._position, this._position + length));
|
|
106
|
+
this._position += length;
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
}
|