@minecraft/server-net 1.0.0-beta.1.26.20-preview.20 → 1.0.0-beta.1.26.20-preview.23
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/index.d.ts +259 -44
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -244,9 +244,11 @@ export enum PacketId {
|
|
|
244
244
|
ServerboundLoadingScreenPacket = 'ServerboundLoadingScreenPacket',
|
|
245
245
|
ServerboundPackSettingChangePacket = 'ServerboundPackSettingChangePacket',
|
|
246
246
|
ServerPlayerPostMovePositionPacket = 'ServerPlayerPostMovePositionPacket',
|
|
247
|
+
ServerPresenceInfoPacket = 'ServerPresenceInfoPacket',
|
|
247
248
|
ServerSettingsRequestPacket = 'ServerSettingsRequestPacket',
|
|
248
249
|
ServerSettingsResponsePacket = 'ServerSettingsResponsePacket',
|
|
249
250
|
ServerStatsPacket = 'ServerStatsPacket',
|
|
251
|
+
ServerStoreInfoPacket = 'ServerStoreInfoPacket',
|
|
250
252
|
ServerToClientHandshakePacket = 'ServerToClientHandshakePacket',
|
|
251
253
|
SetActorDataPacket = 'SetActorDataPacket',
|
|
252
254
|
SetActorLinkPacket = 'SetActorLinkPacket',
|
|
@@ -306,25 +308,42 @@ export enum PacketId {
|
|
|
306
308
|
VoxelShapesPacket = 'VoxelShapesPacket',
|
|
307
309
|
}
|
|
308
310
|
|
|
311
|
+
export class CloseAfterEventSignal {
|
|
312
|
+
private constructor();
|
|
313
|
+
/**
|
|
314
|
+
* @remarks
|
|
315
|
+
* This function can't be called in restricted-execution mode.
|
|
316
|
+
*
|
|
317
|
+
* This function can be called in early-execution mode.
|
|
318
|
+
*
|
|
319
|
+
*/
|
|
320
|
+
subscribe(callback: (arg0: WebSocketClientCloseAfterEvent) => void): (arg0: WebSocketClientCloseAfterEvent) => void;
|
|
321
|
+
/**
|
|
322
|
+
* @remarks
|
|
323
|
+
* This function can't be called in restricted-execution mode.
|
|
324
|
+
*
|
|
325
|
+
* This function can be called in early-execution mode.
|
|
326
|
+
*
|
|
327
|
+
*/
|
|
328
|
+
unsubscribe(callback: (arg0: WebSocketClientCloseAfterEvent) => void): void;
|
|
329
|
+
}
|
|
330
|
+
|
|
309
331
|
/**
|
|
310
332
|
* @example simpleHttpRequest.ts
|
|
311
333
|
* ```typescript
|
|
312
334
|
* import { HttpRequest, HttpHeader, HttpRequestMethod, http } from '@minecraft/server-net';
|
|
313
335
|
*
|
|
314
336
|
* async function updateScore() {
|
|
315
|
-
*
|
|
337
|
+
* const req = new HttpRequest('http://localhost:3000/updateScore');
|
|
316
338
|
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
339
|
+
* req.body = JSON.stringify({
|
|
340
|
+
* score: 22,
|
|
341
|
+
* });
|
|
320
342
|
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* new HttpHeader('Content-Type', 'application/json'),
|
|
324
|
-
* new HttpHeader('auth', 'my-auth-token'),
|
|
325
|
-
* ];
|
|
343
|
+
* req.method = HttpRequestMethod.Post;
|
|
344
|
+
* req.headers = [new HttpHeader('Content-Type', 'application/json'), new HttpHeader('auth', 'my-auth-token')];
|
|
326
345
|
*
|
|
327
|
-
*
|
|
346
|
+
* await http.request(req);
|
|
328
347
|
* }
|
|
329
348
|
* ```
|
|
330
349
|
*/
|
|
@@ -366,19 +385,16 @@ export class HttpClient {
|
|
|
366
385
|
* import { HttpRequest, HttpHeader, HttpRequestMethod, http } from '@minecraft/server-net';
|
|
367
386
|
*
|
|
368
387
|
* async function updateScore() {
|
|
369
|
-
*
|
|
388
|
+
* const req = new HttpRequest('http://localhost:3000/updateScore');
|
|
370
389
|
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
390
|
+
* req.body = JSON.stringify({
|
|
391
|
+
* score: 22,
|
|
392
|
+
* });
|
|
374
393
|
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
* new HttpHeader('Content-Type', 'application/json'),
|
|
378
|
-
* new HttpHeader('auth', 'my-auth-token'),
|
|
379
|
-
* ];
|
|
394
|
+
* req.method = HttpRequestMethod.Post;
|
|
395
|
+
* req.headers = [new HttpHeader('Content-Type', 'application/json'), new HttpHeader('auth', 'my-auth-token')];
|
|
380
396
|
*
|
|
381
|
-
*
|
|
397
|
+
* await http.request(req);
|
|
382
398
|
* }
|
|
383
399
|
* ```
|
|
384
400
|
*/
|
|
@@ -393,19 +409,16 @@ export class HttpClient {
|
|
|
393
409
|
* import { HttpRequest, HttpHeader, HttpRequestMethod, http } from '@minecraft/server-net';
|
|
394
410
|
*
|
|
395
411
|
* async function updateScore() {
|
|
396
|
-
*
|
|
412
|
+
* const req = new HttpRequest('http://localhost:3000/updateScore');
|
|
397
413
|
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
414
|
+
* req.body = JSON.stringify({
|
|
415
|
+
* score: 22,
|
|
416
|
+
* });
|
|
401
417
|
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
* new HttpHeader('Content-Type', 'application/json'),
|
|
405
|
-
* new HttpHeader('auth', 'my-auth-token'),
|
|
406
|
-
* ];
|
|
418
|
+
* req.method = HttpRequestMethod.Post;
|
|
419
|
+
* req.headers = [new HttpHeader('Content-Type', 'application/json'), new HttpHeader('auth', 'my-auth-token')];
|
|
407
420
|
*
|
|
408
|
-
*
|
|
421
|
+
* await http.request(req);
|
|
409
422
|
* }
|
|
410
423
|
* ```
|
|
411
424
|
*/
|
|
@@ -436,19 +449,16 @@ export class HttpHeader {
|
|
|
436
449
|
* import { HttpRequest, HttpHeader, HttpRequestMethod, http } from '@minecraft/server-net';
|
|
437
450
|
*
|
|
438
451
|
* async function updateScore() {
|
|
439
|
-
*
|
|
452
|
+
* const req = new HttpRequest('http://localhost:3000/updateScore');
|
|
440
453
|
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
454
|
+
* req.body = JSON.stringify({
|
|
455
|
+
* score: 22,
|
|
456
|
+
* });
|
|
444
457
|
*
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
* new HttpHeader('Content-Type', 'application/json'),
|
|
448
|
-
* new HttpHeader('auth', 'my-auth-token'),
|
|
449
|
-
* ];
|
|
458
|
+
* req.method = HttpRequestMethod.Post;
|
|
459
|
+
* req.headers = [new HttpHeader('Content-Type', 'application/json'), new HttpHeader('auth', 'my-auth-token')];
|
|
450
460
|
*
|
|
451
|
-
*
|
|
461
|
+
* await http.request(req);
|
|
452
462
|
* }
|
|
453
463
|
* ```
|
|
454
464
|
*/
|
|
@@ -532,8 +542,13 @@ export class HttpRequest {
|
|
|
532
542
|
setMethod(method: HttpRequestMethod): HttpRequest;
|
|
533
543
|
/**
|
|
534
544
|
* @remarks
|
|
545
|
+
* Sets the maximum amount of time, in seconds, before the
|
|
546
|
+
* request times out and is cancelled.
|
|
547
|
+
*
|
|
535
548
|
* This function can be called in early-execution mode.
|
|
536
549
|
*
|
|
550
|
+
* @param timeout
|
|
551
|
+
* The timeout value, in seconds.
|
|
537
552
|
*/
|
|
538
553
|
setTimeout(timeout: number): HttpRequest;
|
|
539
554
|
}
|
|
@@ -573,6 +588,28 @@ export class HttpResponse {
|
|
|
573
588
|
readonly status: number;
|
|
574
589
|
}
|
|
575
590
|
|
|
591
|
+
export class MessageAfterEventSignal {
|
|
592
|
+
private constructor();
|
|
593
|
+
/**
|
|
594
|
+
* @remarks
|
|
595
|
+
* This function can't be called in restricted-execution mode.
|
|
596
|
+
*
|
|
597
|
+
* This function can be called in early-execution mode.
|
|
598
|
+
*
|
|
599
|
+
*/
|
|
600
|
+
subscribe(
|
|
601
|
+
callback: (arg0: WebSocketClientReceiveAfterEvent) => void,
|
|
602
|
+
): (arg0: WebSocketClientReceiveAfterEvent) => void;
|
|
603
|
+
/**
|
|
604
|
+
* @remarks
|
|
605
|
+
* This function can't be called in restricted-execution mode.
|
|
606
|
+
*
|
|
607
|
+
* This function can be called in early-execution mode.
|
|
608
|
+
*
|
|
609
|
+
*/
|
|
610
|
+
unsubscribe(callback: (arg0: WebSocketClientReceiveAfterEvent) => void): void;
|
|
611
|
+
}
|
|
612
|
+
|
|
576
613
|
export class NetworkBeforeEvents {
|
|
577
614
|
private constructor();
|
|
578
615
|
/**
|
|
@@ -697,6 +734,97 @@ export class PacketSendBeforeEventSignal {
|
|
|
697
734
|
unsubscribe(callback: (arg0: PacketSendBeforeEvent) => void): void;
|
|
698
735
|
}
|
|
699
736
|
|
|
737
|
+
/**
|
|
738
|
+
* Used to manage WebSocket connections.
|
|
739
|
+
*/
|
|
740
|
+
export class WebSocket {
|
|
741
|
+
private constructor();
|
|
742
|
+
/**
|
|
743
|
+
* @remarks
|
|
744
|
+
* Attempts to connect a WebSocket client.
|
|
745
|
+
*
|
|
746
|
+
* This function can't be called in restricted-execution mode.
|
|
747
|
+
*
|
|
748
|
+
* @param uri
|
|
749
|
+
* URL to make connection to.
|
|
750
|
+
* @returns
|
|
751
|
+
* An awaitable promise that contains the WebSocket client that
|
|
752
|
+
* was connected.
|
|
753
|
+
*/
|
|
754
|
+
connect(uri: string): Promise<WebSocketClient>;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* An active WebSocket client.
|
|
759
|
+
*/
|
|
760
|
+
export class WebSocketClient {
|
|
761
|
+
private constructor();
|
|
762
|
+
/**
|
|
763
|
+
* @remarks
|
|
764
|
+
* Contains a set of events related to this WebSocket client.
|
|
765
|
+
*
|
|
766
|
+
*/
|
|
767
|
+
readonly afterEvents: WebSocketClientAfterEvents;
|
|
768
|
+
/**
|
|
769
|
+
* @remarks
|
|
770
|
+
* Set to true if the socket is current connected to the
|
|
771
|
+
* server.
|
|
772
|
+
*
|
|
773
|
+
*/
|
|
774
|
+
readonly isOpen: boolean;
|
|
775
|
+
/**
|
|
776
|
+
* @remarks
|
|
777
|
+
* Closes the connection with the server.
|
|
778
|
+
*
|
|
779
|
+
* This function can't be called in restricted-execution mode.
|
|
780
|
+
*
|
|
781
|
+
* @throws This function can throw errors.
|
|
782
|
+
*
|
|
783
|
+
* {@link WebSocketNotConnectedError}
|
|
784
|
+
*/
|
|
785
|
+
close(): void;
|
|
786
|
+
/**
|
|
787
|
+
* @remarks
|
|
788
|
+
* Sends the provided payload to the server.
|
|
789
|
+
*
|
|
790
|
+
* This function can't be called in restricted-execution mode.
|
|
791
|
+
*
|
|
792
|
+
* @param payload
|
|
793
|
+
* The payload that will be included in the network packet.
|
|
794
|
+
* @throws This function can throw errors.
|
|
795
|
+
*
|
|
796
|
+
* {@link RequestBodyTooLargeError}
|
|
797
|
+
*
|
|
798
|
+
* {@link WebSocketNotConnectedError}
|
|
799
|
+
*/
|
|
800
|
+
send(payload: string): void;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
export class WebSocketClientAfterEvents {
|
|
804
|
+
private constructor();
|
|
805
|
+
/**
|
|
806
|
+
* @remarks
|
|
807
|
+
* This property can be read in early-execution mode.
|
|
808
|
+
*
|
|
809
|
+
*/
|
|
810
|
+
readonly close: CloseAfterEventSignal;
|
|
811
|
+
/**
|
|
812
|
+
* @remarks
|
|
813
|
+
* This property can be read in early-execution mode.
|
|
814
|
+
*
|
|
815
|
+
*/
|
|
816
|
+
readonly message: MessageAfterEventSignal;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
export class WebSocketClientCloseAfterEvent {
|
|
820
|
+
private constructor();
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
export class WebSocketClientReceiveAfterEvent {
|
|
824
|
+
private constructor();
|
|
825
|
+
readonly message: string;
|
|
826
|
+
}
|
|
827
|
+
|
|
700
828
|
/**
|
|
701
829
|
* Options for events triggered by network packets.
|
|
702
830
|
*/
|
|
@@ -753,20 +881,39 @@ export class InternalHttpRequestError extends Error {
|
|
|
753
881
|
private constructor();
|
|
754
882
|
/**
|
|
755
883
|
* @remarks
|
|
756
|
-
*
|
|
884
|
+
* This property can be read in early-execution mode.
|
|
757
885
|
*
|
|
886
|
+
*/
|
|
887
|
+
readonly errorCode: number;
|
|
888
|
+
/**
|
|
889
|
+
* @remarks
|
|
758
890
|
* This property can be read in early-execution mode.
|
|
759
891
|
*
|
|
760
892
|
*/
|
|
761
|
-
readonly
|
|
893
|
+
readonly errorMessage: string;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/**
|
|
897
|
+
* An error thrown when a platform-level WebSocket error
|
|
898
|
+
* occurs. Information provided in this class may be useful
|
|
899
|
+
* for diagnostics purposes but will differ from platform to
|
|
900
|
+
* platform.
|
|
901
|
+
*/
|
|
902
|
+
// @ts-ignore Class inheritance allowed for native defined classes
|
|
903
|
+
export class InternalWebSocketError extends Error {
|
|
904
|
+
private constructor();
|
|
762
905
|
/**
|
|
763
906
|
* @remarks
|
|
764
|
-
*
|
|
907
|
+
* This property can be read in early-execution mode.
|
|
765
908
|
*
|
|
909
|
+
*/
|
|
910
|
+
readonly errorCode: number;
|
|
911
|
+
/**
|
|
912
|
+
* @remarks
|
|
766
913
|
* This property can be read in early-execution mode.
|
|
767
914
|
*
|
|
768
915
|
*/
|
|
769
|
-
readonly
|
|
916
|
+
readonly errorMessage: string;
|
|
770
917
|
}
|
|
771
918
|
|
|
772
919
|
/**
|
|
@@ -836,5 +983,73 @@ export class UriNotAllowedError extends Error {
|
|
|
836
983
|
readonly uri: string;
|
|
837
984
|
}
|
|
838
985
|
|
|
986
|
+
/**
|
|
987
|
+
* An error thrown when the connection with the WebSocket
|
|
988
|
+
* server has failed.
|
|
989
|
+
*/
|
|
990
|
+
// @ts-ignore Class inheritance allowed for native defined classes
|
|
991
|
+
export class WebSocketConnectionFailedError extends Error {
|
|
992
|
+
private constructor();
|
|
993
|
+
/**
|
|
994
|
+
* @remarks
|
|
995
|
+
* The error code received when attempting to connect with the
|
|
996
|
+
* server.
|
|
997
|
+
*
|
|
998
|
+
* This property can be read in early-execution mode.
|
|
999
|
+
*
|
|
1000
|
+
*/
|
|
1001
|
+
readonly errorCode: number;
|
|
1002
|
+
/**
|
|
1003
|
+
* @remarks
|
|
1004
|
+
* The URI provided to make this connection attempt that
|
|
1005
|
+
* failed.
|
|
1006
|
+
*
|
|
1007
|
+
* This property can be read in early-execution mode.
|
|
1008
|
+
*
|
|
1009
|
+
*/
|
|
1010
|
+
readonly uri: string;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* An error that is thrown when the maximum number of connected
|
|
1015
|
+
* WebSockets is reached.
|
|
1016
|
+
*/
|
|
1017
|
+
// @ts-ignore Class inheritance allowed for native defined classes
|
|
1018
|
+
export class WebSocketLimitExceededError extends Error {
|
|
1019
|
+
private constructor();
|
|
1020
|
+
/**
|
|
1021
|
+
* @remarks
|
|
1022
|
+
* Number of WebSocket connections already active when
|
|
1023
|
+
* rejected.
|
|
1024
|
+
*
|
|
1025
|
+
* This property can be read in early-execution mode.
|
|
1026
|
+
*
|
|
1027
|
+
*/
|
|
1028
|
+
readonly connectedSockets: number;
|
|
1029
|
+
/**
|
|
1030
|
+
* @remarks
|
|
1031
|
+
* Configured maximum active WebSocket connections.
|
|
1032
|
+
*
|
|
1033
|
+
* This property can be read in early-execution mode.
|
|
1034
|
+
*
|
|
1035
|
+
*/
|
|
1036
|
+
readonly maxConcurrentConnections: number;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
/**
|
|
1040
|
+
* An error thrown when attempting to use a WebSocket while the
|
|
1041
|
+
* socket is not connected to a server.
|
|
1042
|
+
*/
|
|
1043
|
+
// @ts-ignore Class inheritance allowed for native defined classes
|
|
1044
|
+
export class WebSocketNotConnectedError extends Error {
|
|
1045
|
+
private constructor();
|
|
1046
|
+
}
|
|
1047
|
+
|
|
839
1048
|
export const beforeEvents: NetworkBeforeEvents;
|
|
840
1049
|
export const http: HttpClient;
|
|
1050
|
+
/**
|
|
1051
|
+
* @remarks
|
|
1052
|
+
* Used to manage WebSocket connections.
|
|
1053
|
+
*
|
|
1054
|
+
*/
|
|
1055
|
+
export const websocket: WebSocket;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minecraft/server-net",
|
|
3
|
-
"version": "1.0.0-beta.1.26.20-preview.
|
|
3
|
+
"version": "1.0.0-beta.1.26.20-preview.23",
|
|
4
4
|
"description": "",
|
|
5
5
|
"contributors": [
|
|
6
6
|
{
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"peerDependencies": {
|
|
16
16
|
"@minecraft/common": "^1.0.0",
|
|
17
17
|
"@minecraft/server": "^1.17.0 || ^2.0.0",
|
|
18
|
-
"@minecraft/server-admin": "^1.0.0-beta.1.26.20-preview.
|
|
18
|
+
"@minecraft/server-admin": "^1.0.0-beta.1.26.20-preview.23"
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT"
|
|
21
21
|
}
|