@darco2903/altv-web-api 1.1.0 → 1.3.0
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/dist/client.d.ts +127 -0
- package/dist/contract/index.d.ts +442 -0
- package/dist/contract/mediaStream.d.ts +443 -0
- package/dist/contract/mediaStream.js +21 -0
- package/dist/socket/mediaStream.d.ts +12 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/scene.d.ts +309 -0
- package/dist/types/scene.js +73 -0
- package/package.json +1 -1
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Half size of the square ground (meters), x and z stay within ±SCENE_SIZE */
|
|
3
|
+
export declare const SCENE_SIZE = 40;
|
|
4
|
+
export declare const SCENE_MAX_SPEAKERS = 16;
|
|
5
|
+
export declare const SCENE_MAX_CARS = 4;
|
|
6
|
+
/** Front left, front right, rear left, rear right */
|
|
7
|
+
export declare const CAR_DOORS = 4;
|
|
8
|
+
export declare const sceneSpeakerSchema: z.ZodObject<{
|
|
9
|
+
id: z.ZodString;
|
|
10
|
+
x: z.ZodNumber;
|
|
11
|
+
/** Height of the speaker center */
|
|
12
|
+
y: z.ZodNumber;
|
|
13
|
+
z: z.ZodNumber;
|
|
14
|
+
/** The speaker faces its local +z, rotated like a three.js object (Euler order YXZ) */
|
|
15
|
+
yaw: z.ZodNumber;
|
|
16
|
+
pitch: z.ZodNumber;
|
|
17
|
+
/** Only projects forward (cone), otherwise all around */
|
|
18
|
+
directional: z.ZodBoolean;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
id: string;
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
z: number;
|
|
24
|
+
yaw: number;
|
|
25
|
+
pitch: number;
|
|
26
|
+
directional: boolean;
|
|
27
|
+
}, {
|
|
28
|
+
id: string;
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
z: number;
|
|
32
|
+
yaw: number;
|
|
33
|
+
pitch: number;
|
|
34
|
+
directional: boolean;
|
|
35
|
+
}>;
|
|
36
|
+
export declare const sceneCarSchema: z.ZodObject<{
|
|
37
|
+
id: z.ZodString;
|
|
38
|
+
x: z.ZodNumber;
|
|
39
|
+
z: z.ZodNumber;
|
|
40
|
+
/** The car front faces its local -z */
|
|
41
|
+
yaw: z.ZodNumber;
|
|
42
|
+
/** Open doors, see CAR_DOORS for the order */
|
|
43
|
+
doors: z.ZodArray<z.ZodBoolean, "many">;
|
|
44
|
+
/** Open (lowered) windows, one per door */
|
|
45
|
+
windows: z.ZodArray<z.ZodBoolean, "many">;
|
|
46
|
+
/** The radio plays the stream */
|
|
47
|
+
radio: z.ZodBoolean;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
id: string;
|
|
50
|
+
x: number;
|
|
51
|
+
z: number;
|
|
52
|
+
yaw: number;
|
|
53
|
+
doors: boolean[];
|
|
54
|
+
windows: boolean[];
|
|
55
|
+
radio: boolean;
|
|
56
|
+
}, {
|
|
57
|
+
id: string;
|
|
58
|
+
x: number;
|
|
59
|
+
z: number;
|
|
60
|
+
yaw: number;
|
|
61
|
+
doors: boolean[];
|
|
62
|
+
windows: boolean[];
|
|
63
|
+
radio: boolean;
|
|
64
|
+
}>;
|
|
65
|
+
/** Where the stream is heard, shared by every listener of the stream */
|
|
66
|
+
export declare const mediaStreamSceneSchema: z.ZodObject<{
|
|
67
|
+
speakers: z.ZodArray<z.ZodObject<{
|
|
68
|
+
id: z.ZodString;
|
|
69
|
+
x: z.ZodNumber;
|
|
70
|
+
/** Height of the speaker center */
|
|
71
|
+
y: z.ZodNumber;
|
|
72
|
+
z: z.ZodNumber;
|
|
73
|
+
/** The speaker faces its local +z, rotated like a three.js object (Euler order YXZ) */
|
|
74
|
+
yaw: z.ZodNumber;
|
|
75
|
+
pitch: z.ZodNumber;
|
|
76
|
+
/** Only projects forward (cone), otherwise all around */
|
|
77
|
+
directional: z.ZodBoolean;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
id: string;
|
|
80
|
+
x: number;
|
|
81
|
+
y: number;
|
|
82
|
+
z: number;
|
|
83
|
+
yaw: number;
|
|
84
|
+
pitch: number;
|
|
85
|
+
directional: boolean;
|
|
86
|
+
}, {
|
|
87
|
+
id: string;
|
|
88
|
+
x: number;
|
|
89
|
+
y: number;
|
|
90
|
+
z: number;
|
|
91
|
+
yaw: number;
|
|
92
|
+
pitch: number;
|
|
93
|
+
directional: boolean;
|
|
94
|
+
}>, "many">;
|
|
95
|
+
cars: z.ZodArray<z.ZodObject<{
|
|
96
|
+
id: z.ZodString;
|
|
97
|
+
x: z.ZodNumber;
|
|
98
|
+
z: z.ZodNumber;
|
|
99
|
+
/** The car front faces its local -z */
|
|
100
|
+
yaw: z.ZodNumber;
|
|
101
|
+
/** Open doors, see CAR_DOORS for the order */
|
|
102
|
+
doors: z.ZodArray<z.ZodBoolean, "many">;
|
|
103
|
+
/** Open (lowered) windows, one per door */
|
|
104
|
+
windows: z.ZodArray<z.ZodBoolean, "many">;
|
|
105
|
+
/** The radio plays the stream */
|
|
106
|
+
radio: z.ZodBoolean;
|
|
107
|
+
}, "strip", z.ZodTypeAny, {
|
|
108
|
+
id: string;
|
|
109
|
+
x: number;
|
|
110
|
+
z: number;
|
|
111
|
+
yaw: number;
|
|
112
|
+
doors: boolean[];
|
|
113
|
+
windows: boolean[];
|
|
114
|
+
radio: boolean;
|
|
115
|
+
}, {
|
|
116
|
+
id: string;
|
|
117
|
+
x: number;
|
|
118
|
+
z: number;
|
|
119
|
+
yaw: number;
|
|
120
|
+
doors: boolean[];
|
|
121
|
+
windows: boolean[];
|
|
122
|
+
radio: boolean;
|
|
123
|
+
}>, "many">;
|
|
124
|
+
}, "strip", z.ZodTypeAny, {
|
|
125
|
+
speakers: {
|
|
126
|
+
id: string;
|
|
127
|
+
x: number;
|
|
128
|
+
y: number;
|
|
129
|
+
z: number;
|
|
130
|
+
yaw: number;
|
|
131
|
+
pitch: number;
|
|
132
|
+
directional: boolean;
|
|
133
|
+
}[];
|
|
134
|
+
cars: {
|
|
135
|
+
id: string;
|
|
136
|
+
x: number;
|
|
137
|
+
z: number;
|
|
138
|
+
yaw: number;
|
|
139
|
+
doors: boolean[];
|
|
140
|
+
windows: boolean[];
|
|
141
|
+
radio: boolean;
|
|
142
|
+
}[];
|
|
143
|
+
}, {
|
|
144
|
+
speakers: {
|
|
145
|
+
id: string;
|
|
146
|
+
x: number;
|
|
147
|
+
y: number;
|
|
148
|
+
z: number;
|
|
149
|
+
yaw: number;
|
|
150
|
+
pitch: number;
|
|
151
|
+
directional: boolean;
|
|
152
|
+
}[];
|
|
153
|
+
cars: {
|
|
154
|
+
id: string;
|
|
155
|
+
x: number;
|
|
156
|
+
z: number;
|
|
157
|
+
yaw: number;
|
|
158
|
+
doors: boolean[];
|
|
159
|
+
windows: boolean[];
|
|
160
|
+
radio: boolean;
|
|
161
|
+
}[];
|
|
162
|
+
}>;
|
|
163
|
+
export declare const sceneActionSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
164
|
+
type: z.ZodLiteral<"addSpeaker">;
|
|
165
|
+
speaker: z.ZodObject<Omit<{
|
|
166
|
+
id: z.ZodString;
|
|
167
|
+
x: z.ZodNumber;
|
|
168
|
+
/** Height of the speaker center */
|
|
169
|
+
y: z.ZodNumber;
|
|
170
|
+
z: z.ZodNumber;
|
|
171
|
+
/** The speaker faces its local +z, rotated like a three.js object (Euler order YXZ) */
|
|
172
|
+
yaw: z.ZodNumber;
|
|
173
|
+
pitch: z.ZodNumber;
|
|
174
|
+
/** Only projects forward (cone), otherwise all around */
|
|
175
|
+
directional: z.ZodBoolean;
|
|
176
|
+
}, "id">, "strip", z.ZodTypeAny, {
|
|
177
|
+
x: number;
|
|
178
|
+
y: number;
|
|
179
|
+
z: number;
|
|
180
|
+
yaw: number;
|
|
181
|
+
pitch: number;
|
|
182
|
+
directional: boolean;
|
|
183
|
+
}, {
|
|
184
|
+
x: number;
|
|
185
|
+
y: number;
|
|
186
|
+
z: number;
|
|
187
|
+
yaw: number;
|
|
188
|
+
pitch: number;
|
|
189
|
+
directional: boolean;
|
|
190
|
+
}>;
|
|
191
|
+
}, "strip", z.ZodTypeAny, {
|
|
192
|
+
type: "addSpeaker";
|
|
193
|
+
speaker: {
|
|
194
|
+
x: number;
|
|
195
|
+
y: number;
|
|
196
|
+
z: number;
|
|
197
|
+
yaw: number;
|
|
198
|
+
pitch: number;
|
|
199
|
+
directional: boolean;
|
|
200
|
+
};
|
|
201
|
+
}, {
|
|
202
|
+
type: "addSpeaker";
|
|
203
|
+
speaker: {
|
|
204
|
+
x: number;
|
|
205
|
+
y: number;
|
|
206
|
+
z: number;
|
|
207
|
+
yaw: number;
|
|
208
|
+
pitch: number;
|
|
209
|
+
directional: boolean;
|
|
210
|
+
};
|
|
211
|
+
}>, z.ZodObject<{
|
|
212
|
+
type: z.ZodLiteral<"addCar">;
|
|
213
|
+
car: z.ZodObject<Pick<{
|
|
214
|
+
id: z.ZodString;
|
|
215
|
+
x: z.ZodNumber;
|
|
216
|
+
z: z.ZodNumber;
|
|
217
|
+
/** The car front faces its local -z */
|
|
218
|
+
yaw: z.ZodNumber;
|
|
219
|
+
/** Open doors, see CAR_DOORS for the order */
|
|
220
|
+
doors: z.ZodArray<z.ZodBoolean, "many">;
|
|
221
|
+
/** Open (lowered) windows, one per door */
|
|
222
|
+
windows: z.ZodArray<z.ZodBoolean, "many">;
|
|
223
|
+
/** The radio plays the stream */
|
|
224
|
+
radio: z.ZodBoolean;
|
|
225
|
+
}, "x" | "z" | "yaw">, "strip", z.ZodTypeAny, {
|
|
226
|
+
x: number;
|
|
227
|
+
z: number;
|
|
228
|
+
yaw: number;
|
|
229
|
+
}, {
|
|
230
|
+
x: number;
|
|
231
|
+
z: number;
|
|
232
|
+
yaw: number;
|
|
233
|
+
}>;
|
|
234
|
+
}, "strip", z.ZodTypeAny, {
|
|
235
|
+
type: "addCar";
|
|
236
|
+
car: {
|
|
237
|
+
x: number;
|
|
238
|
+
z: number;
|
|
239
|
+
yaw: number;
|
|
240
|
+
};
|
|
241
|
+
}, {
|
|
242
|
+
type: "addCar";
|
|
243
|
+
car: {
|
|
244
|
+
x: number;
|
|
245
|
+
z: number;
|
|
246
|
+
yaw: number;
|
|
247
|
+
};
|
|
248
|
+
}>, z.ZodObject<{
|
|
249
|
+
type: z.ZodLiteral<"remove">;
|
|
250
|
+
id: z.ZodString;
|
|
251
|
+
}, "strip", z.ZodTypeAny, {
|
|
252
|
+
type: "remove";
|
|
253
|
+
id: string;
|
|
254
|
+
}, {
|
|
255
|
+
type: "remove";
|
|
256
|
+
id: string;
|
|
257
|
+
}>, z.ZodObject<{
|
|
258
|
+
type: z.ZodLiteral<"carDoor">;
|
|
259
|
+
id: z.ZodString;
|
|
260
|
+
index: z.ZodNumber;
|
|
261
|
+
open: z.ZodBoolean;
|
|
262
|
+
}, "strip", z.ZodTypeAny, {
|
|
263
|
+
type: "carDoor";
|
|
264
|
+
id: string;
|
|
265
|
+
index: number;
|
|
266
|
+
open: boolean;
|
|
267
|
+
}, {
|
|
268
|
+
type: "carDoor";
|
|
269
|
+
id: string;
|
|
270
|
+
index: number;
|
|
271
|
+
open: boolean;
|
|
272
|
+
}>, z.ZodObject<{
|
|
273
|
+
type: z.ZodLiteral<"carWindow">;
|
|
274
|
+
id: z.ZodString;
|
|
275
|
+
index: z.ZodNumber;
|
|
276
|
+
open: z.ZodBoolean;
|
|
277
|
+
}, "strip", z.ZodTypeAny, {
|
|
278
|
+
type: "carWindow";
|
|
279
|
+
id: string;
|
|
280
|
+
index: number;
|
|
281
|
+
open: boolean;
|
|
282
|
+
}, {
|
|
283
|
+
type: "carWindow";
|
|
284
|
+
id: string;
|
|
285
|
+
index: number;
|
|
286
|
+
open: boolean;
|
|
287
|
+
}>, z.ZodObject<{
|
|
288
|
+
type: z.ZodLiteral<"carRadio">;
|
|
289
|
+
id: z.ZodString;
|
|
290
|
+
on: z.ZodBoolean;
|
|
291
|
+
}, "strip", z.ZodTypeAny, {
|
|
292
|
+
type: "carRadio";
|
|
293
|
+
id: string;
|
|
294
|
+
on: boolean;
|
|
295
|
+
}, {
|
|
296
|
+
type: "carRadio";
|
|
297
|
+
id: string;
|
|
298
|
+
on: boolean;
|
|
299
|
+
}>, z.ZodObject<{
|
|
300
|
+
type: z.ZodLiteral<"reset">;
|
|
301
|
+
}, "strip", z.ZodTypeAny, {
|
|
302
|
+
type: "reset";
|
|
303
|
+
}, {
|
|
304
|
+
type: "reset";
|
|
305
|
+
}>]>;
|
|
306
|
+
export type SceneSpeaker = z.infer<typeof sceneSpeakerSchema>;
|
|
307
|
+
export type SceneCar = z.infer<typeof sceneCarSchema>;
|
|
308
|
+
export type MediaStreamScene = z.infer<typeof mediaStreamSceneSchema>;
|
|
309
|
+
export type SceneAction = z.infer<typeof sceneActionSchema>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Half size of the square ground (meters), x and z stay within ±SCENE_SIZE */
|
|
3
|
+
export const SCENE_SIZE = 40;
|
|
4
|
+
export const SCENE_MAX_SPEAKERS = 16;
|
|
5
|
+
export const SCENE_MAX_CARS = 4;
|
|
6
|
+
/** Front left, front right, rear left, rear right */
|
|
7
|
+
export const CAR_DOORS = 4;
|
|
8
|
+
const coordinate = z.number().min(-SCENE_SIZE).max(SCENE_SIZE);
|
|
9
|
+
/** Radians, rotation around the vertical axis */
|
|
10
|
+
const yaw = z.number().min(-2 * Math.PI).max(2 * Math.PI);
|
|
11
|
+
export const sceneSpeakerSchema = z.object({
|
|
12
|
+
id: z.string(),
|
|
13
|
+
x: coordinate,
|
|
14
|
+
/** Height of the speaker center */
|
|
15
|
+
y: z.number().min(0).max(10),
|
|
16
|
+
z: coordinate,
|
|
17
|
+
/** The speaker faces its local +z, rotated like a three.js object (Euler order YXZ) */
|
|
18
|
+
yaw,
|
|
19
|
+
pitch: z.number().min(-Math.PI / 2).max(Math.PI / 2),
|
|
20
|
+
/** Only projects forward (cone), otherwise all around */
|
|
21
|
+
directional: z.boolean(),
|
|
22
|
+
});
|
|
23
|
+
export const sceneCarSchema = z.object({
|
|
24
|
+
id: z.string(),
|
|
25
|
+
x: coordinate,
|
|
26
|
+
z: coordinate,
|
|
27
|
+
/** The car front faces its local -z */
|
|
28
|
+
yaw,
|
|
29
|
+
/** Open doors, see CAR_DOORS for the order */
|
|
30
|
+
doors: z.array(z.boolean()).length(CAR_DOORS),
|
|
31
|
+
/** Open (lowered) windows, one per door */
|
|
32
|
+
windows: z.array(z.boolean()).length(CAR_DOORS),
|
|
33
|
+
/** The radio plays the stream */
|
|
34
|
+
radio: z.boolean(),
|
|
35
|
+
});
|
|
36
|
+
/** Where the stream is heard, shared by every listener of the stream */
|
|
37
|
+
export const mediaStreamSceneSchema = z.object({
|
|
38
|
+
speakers: z.array(sceneSpeakerSchema),
|
|
39
|
+
cars: z.array(sceneCarSchema),
|
|
40
|
+
});
|
|
41
|
+
const carId = z.string();
|
|
42
|
+
const doorIndex = z
|
|
43
|
+
.number()
|
|
44
|
+
.int()
|
|
45
|
+
.min(0)
|
|
46
|
+
.max(CAR_DOORS - 1);
|
|
47
|
+
export const sceneActionSchema = z.discriminatedUnion("type", [
|
|
48
|
+
z.object({
|
|
49
|
+
type: z.literal("addSpeaker"),
|
|
50
|
+
speaker: sceneSpeakerSchema.omit({ id: true }),
|
|
51
|
+
}),
|
|
52
|
+
z.object({
|
|
53
|
+
type: z.literal("addCar"),
|
|
54
|
+
car: sceneCarSchema.pick({ x: true, z: true, yaw: true }),
|
|
55
|
+
}),
|
|
56
|
+
/** Removes a speaker or a car */
|
|
57
|
+
z.object({ type: z.literal("remove"), id: z.string() }),
|
|
58
|
+
z.object({
|
|
59
|
+
type: z.literal("carDoor"),
|
|
60
|
+
id: carId,
|
|
61
|
+
index: doorIndex,
|
|
62
|
+
open: z.boolean(),
|
|
63
|
+
}),
|
|
64
|
+
z.object({
|
|
65
|
+
type: z.literal("carWindow"),
|
|
66
|
+
id: carId,
|
|
67
|
+
index: doorIndex,
|
|
68
|
+
open: z.boolean(),
|
|
69
|
+
}),
|
|
70
|
+
z.object({ type: z.literal("carRadio"), id: carId, on: z.boolean() }),
|
|
71
|
+
/** Back to the default scene */
|
|
72
|
+
z.object({ type: z.literal("reset") }),
|
|
73
|
+
]);
|