@minecraft/server-net 1.0.0-beta.1.26.20-preview.20 → 1.0.0-beta.1.26.20-preview.22

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.
Files changed (2) hide show
  1. package/index.d.ts +254 -44
  2. 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
- * const req = new HttpRequest('http://localhost:3000/updateScore');
337
+ * const req = new HttpRequest('http://localhost:3000/updateScore');
316
338
  *
317
- * req.body = JSON.stringify({
318
- * score: 22,
319
- * });
339
+ * req.body = JSON.stringify({
340
+ * score: 22,
341
+ * });
320
342
  *
321
- * req.method = HttpRequestMethod.Post;
322
- * req.headers = [
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
- * await http.request(req);
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
- * const req = new HttpRequest('http://localhost:3000/updateScore');
388
+ * const req = new HttpRequest('http://localhost:3000/updateScore');
370
389
  *
371
- * req.body = JSON.stringify({
372
- * score: 22,
373
- * });
390
+ * req.body = JSON.stringify({
391
+ * score: 22,
392
+ * });
374
393
  *
375
- * req.method = HttpRequestMethod.Post;
376
- * req.headers = [
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
- * await http.request(req);
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
- * const req = new HttpRequest('http://localhost:3000/updateScore');
412
+ * const req = new HttpRequest('http://localhost:3000/updateScore');
397
413
  *
398
- * req.body = JSON.stringify({
399
- * score: 22,
400
- * });
414
+ * req.body = JSON.stringify({
415
+ * score: 22,
416
+ * });
401
417
  *
402
- * req.method = HttpRequestMethod.Post;
403
- * req.headers = [
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
- * await http.request(req);
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
- * const req = new HttpRequest('http://localhost:3000/updateScore');
452
+ * const req = new HttpRequest('http://localhost:3000/updateScore');
440
453
  *
441
- * req.body = JSON.stringify({
442
- * score: 22,
443
- * });
454
+ * req.body = JSON.stringify({
455
+ * score: 22,
456
+ * });
444
457
  *
445
- * req.method = HttpRequestMethod.Post;
446
- * req.headers = [
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
- * await http.request(req);
461
+ * await http.request(req);
452
462
  * }
453
463
  * ```
454
464
  */
@@ -573,6 +583,28 @@ export class HttpResponse {
573
583
  readonly status: number;
574
584
  }
575
585
 
586
+ export class MessageAfterEventSignal {
587
+ private constructor();
588
+ /**
589
+ * @remarks
590
+ * This function can't be called in restricted-execution mode.
591
+ *
592
+ * This function can be called in early-execution mode.
593
+ *
594
+ */
595
+ subscribe(
596
+ callback: (arg0: WebSocketClientReceiveAfterEvent) => void,
597
+ ): (arg0: WebSocketClientReceiveAfterEvent) => void;
598
+ /**
599
+ * @remarks
600
+ * This function can't be called in restricted-execution mode.
601
+ *
602
+ * This function can be called in early-execution mode.
603
+ *
604
+ */
605
+ unsubscribe(callback: (arg0: WebSocketClientReceiveAfterEvent) => void): void;
606
+ }
607
+
576
608
  export class NetworkBeforeEvents {
577
609
  private constructor();
578
610
  /**
@@ -697,6 +729,97 @@ export class PacketSendBeforeEventSignal {
697
729
  unsubscribe(callback: (arg0: PacketSendBeforeEvent) => void): void;
698
730
  }
699
731
 
732
+ /**
733
+ * Used to manage WebSocket connections.
734
+ */
735
+ export class WebSocket {
736
+ private constructor();
737
+ /**
738
+ * @remarks
739
+ * Attempts to connect a WebSocket client.
740
+ *
741
+ * This function can't be called in restricted-execution mode.
742
+ *
743
+ * @param uri
744
+ * URL to make connection to.
745
+ * @returns
746
+ * An awaitable promise that contains the WebSocket client that
747
+ * was connected.
748
+ */
749
+ connect(uri: string): Promise<WebSocketClient>;
750
+ }
751
+
752
+ /**
753
+ * An active WebSocket client.
754
+ */
755
+ export class WebSocketClient {
756
+ private constructor();
757
+ /**
758
+ * @remarks
759
+ * Contains a set of events related to this WebSocket client.
760
+ *
761
+ */
762
+ readonly afterEvents: WebSocketClientAfterEvents;
763
+ /**
764
+ * @remarks
765
+ * Set to true if the socket is current connected to the
766
+ * server.
767
+ *
768
+ */
769
+ readonly isOpen: boolean;
770
+ /**
771
+ * @remarks
772
+ * Closes the connection with the server.
773
+ *
774
+ * This function can't be called in restricted-execution mode.
775
+ *
776
+ * @throws This function can throw errors.
777
+ *
778
+ * {@link WebSocketNotConnectedError}
779
+ */
780
+ close(): void;
781
+ /**
782
+ * @remarks
783
+ * Sends the provided payload to the server.
784
+ *
785
+ * This function can't be called in restricted-execution mode.
786
+ *
787
+ * @param payload
788
+ * The payload that will be included in the network packet.
789
+ * @throws This function can throw errors.
790
+ *
791
+ * {@link RequestBodyTooLargeError}
792
+ *
793
+ * {@link WebSocketNotConnectedError}
794
+ */
795
+ send(payload: string): void;
796
+ }
797
+
798
+ export class WebSocketClientAfterEvents {
799
+ private constructor();
800
+ /**
801
+ * @remarks
802
+ * This property can be read in early-execution mode.
803
+ *
804
+ */
805
+ readonly close: CloseAfterEventSignal;
806
+ /**
807
+ * @remarks
808
+ * This property can be read in early-execution mode.
809
+ *
810
+ */
811
+ readonly message: MessageAfterEventSignal;
812
+ }
813
+
814
+ export class WebSocketClientCloseAfterEvent {
815
+ private constructor();
816
+ }
817
+
818
+ export class WebSocketClientReceiveAfterEvent {
819
+ private constructor();
820
+ readonly message: string;
821
+ }
822
+
700
823
  /**
701
824
  * Options for events triggered by network packets.
702
825
  */
@@ -753,20 +876,39 @@ export class InternalHttpRequestError extends Error {
753
876
  private constructor();
754
877
  /**
755
878
  * @remarks
756
- * The platform-provided numeric error code for the error.
879
+ * This property can be read in early-execution mode.
757
880
  *
881
+ */
882
+ readonly errorCode: number;
883
+ /**
884
+ * @remarks
758
885
  * This property can be read in early-execution mode.
759
886
  *
760
887
  */
761
- readonly code: number;
888
+ readonly errorMessage: string;
889
+ }
890
+
891
+ /**
892
+ * An error thrown when a platform-level WebSocket error
893
+ * occurs. Information provided in this class may be useful
894
+ * for diagnostics purposes but will differ from platform to
895
+ * platform.
896
+ */
897
+ // @ts-ignore Class inheritance allowed for native defined classes
898
+ export class InternalWebSocketError extends Error {
899
+ private constructor();
762
900
  /**
763
901
  * @remarks
764
- * The platform-provided message for the error.
902
+ * This property can be read in early-execution mode.
765
903
  *
904
+ */
905
+ readonly errorCode: number;
906
+ /**
907
+ * @remarks
766
908
  * This property can be read in early-execution mode.
767
909
  *
768
910
  */
769
- readonly message: string;
911
+ readonly errorMessage: string;
770
912
  }
771
913
 
772
914
  /**
@@ -836,5 +978,73 @@ export class UriNotAllowedError extends Error {
836
978
  readonly uri: string;
837
979
  }
838
980
 
981
+ /**
982
+ * An error thrown when the connection with the WebSocket
983
+ * server has failed.
984
+ */
985
+ // @ts-ignore Class inheritance allowed for native defined classes
986
+ export class WebSocketConnectionFailedError extends Error {
987
+ private constructor();
988
+ /**
989
+ * @remarks
990
+ * The error code received when attempting to connect with the
991
+ * server.
992
+ *
993
+ * This property can be read in early-execution mode.
994
+ *
995
+ */
996
+ readonly errorCode: number;
997
+ /**
998
+ * @remarks
999
+ * The URI provided to make this connection attempt that
1000
+ * failed.
1001
+ *
1002
+ * This property can be read in early-execution mode.
1003
+ *
1004
+ */
1005
+ readonly uri: string;
1006
+ }
1007
+
1008
+ /**
1009
+ * An error that is thrown when the maximum number of connected
1010
+ * WebSockets is reached.
1011
+ */
1012
+ // @ts-ignore Class inheritance allowed for native defined classes
1013
+ export class WebSocketLimitExceededError extends Error {
1014
+ private constructor();
1015
+ /**
1016
+ * @remarks
1017
+ * Number of WebSocket connections already active when
1018
+ * rejected.
1019
+ *
1020
+ * This property can be read in early-execution mode.
1021
+ *
1022
+ */
1023
+ readonly connectedSockets: number;
1024
+ /**
1025
+ * @remarks
1026
+ * Configured maximum active WebSocket connections.
1027
+ *
1028
+ * This property can be read in early-execution mode.
1029
+ *
1030
+ */
1031
+ readonly maxConcurrentConnections: number;
1032
+ }
1033
+
1034
+ /**
1035
+ * An error thrown when attempting to use a WebSocket while the
1036
+ * socket is not connected to a server.
1037
+ */
1038
+ // @ts-ignore Class inheritance allowed for native defined classes
1039
+ export class WebSocketNotConnectedError extends Error {
1040
+ private constructor();
1041
+ }
1042
+
839
1043
  export const beforeEvents: NetworkBeforeEvents;
840
1044
  export const http: HttpClient;
1045
+ /**
1046
+ * @remarks
1047
+ * Used to manage WebSocket connections.
1048
+ *
1049
+ */
1050
+ 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.20",
3
+ "version": "1.0.0-beta.1.26.20-preview.22",
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.20"
18
+ "@minecraft/server-admin": "^1.0.0-beta.1.26.20-preview.22"
19
19
  },
20
20
  "license": "MIT"
21
21
  }