@emeryld/rrroutes-client 2.0.13 → 2.1.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/index.cjs +41 -52
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +42 -53
- package/dist/index.mjs.map +1 -1
- package/dist/sockets/socket.client.context.d.ts +3 -2
- package/dist/sockets/socket.client.debug.d.ts +5 -6
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -581,11 +581,11 @@ function SocketProvider(props) {
|
|
|
581
581
|
});
|
|
582
582
|
const client = React.useMemo(() => {
|
|
583
583
|
if (!socket) {
|
|
584
|
-
dbg(providerDebugRef.current, { type: "client", phase: "
|
|
584
|
+
dbg(providerDebugRef.current, { type: "client", phase: "init", missing: true });
|
|
585
585
|
return null;
|
|
586
586
|
}
|
|
587
587
|
const c = new SocketClient(events, { ...baseOptions, socket });
|
|
588
|
-
dbg(providerDebugRef.current, { type: "client", phase: "
|
|
588
|
+
dbg(providerDebugRef.current, { type: "client", phase: "init", missing: false });
|
|
589
589
|
return c;
|
|
590
590
|
}, [events, baseOptions, socket]);
|
|
591
591
|
React.useEffect(() => {
|
|
@@ -602,12 +602,8 @@ function SocketProvider(props) {
|
|
|
602
602
|
}
|
|
603
603
|
};
|
|
604
604
|
}, [client, destroyLeaveMeta]);
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: fallback ?? children });
|
|
608
|
-
}
|
|
609
|
-
dbg(providerDebugRef.current, { type: "render", phase: "provide" });
|
|
610
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SocketCtx.Provider, { value: client, children });
|
|
605
|
+
dbg(providerDebugRef.current, { type: "render", hasClient: !!client });
|
|
606
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SocketCtx.Provider, { value: client, children: client == null ? fallback ?? children : children });
|
|
611
607
|
}
|
|
612
608
|
function useSocketClient() {
|
|
613
609
|
const ctx = React.useContext(SocketCtx);
|
|
@@ -652,31 +648,24 @@ var SocketClient = class {
|
|
|
652
648
|
intervalMs: hb.intervalMs ?? 15e3,
|
|
653
649
|
timeoutMs: hb.timeoutMs ?? 7500
|
|
654
650
|
};
|
|
655
|
-
this.dbg({
|
|
656
|
-
type: "lifecycle",
|
|
657
|
-
phase: "init_start",
|
|
658
|
-
socketId: this.socket?.id ?? void 0,
|
|
659
|
-
details: {
|
|
660
|
-
environment: this.environment
|
|
661
|
-
}
|
|
662
|
-
});
|
|
663
651
|
if (!this.socket) {
|
|
664
652
|
this.dbg({
|
|
665
653
|
type: "lifecycle",
|
|
666
|
-
phase: "
|
|
654
|
+
phase: "init",
|
|
667
655
|
err: "Socket reference is null during initialization"
|
|
668
656
|
});
|
|
669
657
|
} else {
|
|
670
658
|
this.dbg({
|
|
671
659
|
type: "lifecycle",
|
|
672
|
-
phase: "
|
|
660
|
+
phase: "init",
|
|
673
661
|
socketId: this.socket.id,
|
|
674
662
|
details: {
|
|
675
663
|
heartbeatIntervalMs: this.hb.intervalMs,
|
|
676
|
-
heartbeatTimeoutMs: this.hb.timeoutMs
|
|
664
|
+
heartbeatTimeoutMs: this.hb.timeoutMs,
|
|
665
|
+
environment: this.environment
|
|
677
666
|
}
|
|
678
667
|
});
|
|
679
|
-
this.logSocketConfigSnapshot("
|
|
668
|
+
this.logSocketConfigSnapshot("constructor");
|
|
680
669
|
}
|
|
681
670
|
this.onConnect = () => {
|
|
682
671
|
if (!this.socket) {
|
|
@@ -691,7 +680,7 @@ var SocketClient = class {
|
|
|
691
680
|
nsp: this.getNamespace(this.socket)
|
|
692
681
|
}
|
|
693
682
|
});
|
|
694
|
-
this.logSocketConfigSnapshot("
|
|
683
|
+
this.logSocketConfigSnapshot("connect_event");
|
|
695
684
|
this.getSysEvent("sys:connect")({
|
|
696
685
|
socket: this.socket,
|
|
697
686
|
client: this
|
|
@@ -711,7 +700,7 @@ var SocketClient = class {
|
|
|
711
700
|
nsp: this.getNamespace(this.socket)
|
|
712
701
|
}
|
|
713
702
|
});
|
|
714
|
-
this.logSocketConfigSnapshot("
|
|
703
|
+
this.logSocketConfigSnapshot("reconnect_event");
|
|
715
704
|
this.getSysEvent("sys:reconnect")({
|
|
716
705
|
attempt,
|
|
717
706
|
socket: this.socket,
|
|
@@ -731,7 +720,7 @@ var SocketClient = class {
|
|
|
731
720
|
roomsTracked: this.roomCounts.size
|
|
732
721
|
}
|
|
733
722
|
});
|
|
734
|
-
this.logSocketConfigSnapshot("
|
|
723
|
+
this.logSocketConfigSnapshot("disconnect_event");
|
|
735
724
|
this.getSysEvent("sys:disconnect")({
|
|
736
725
|
reason: String(reason),
|
|
737
726
|
socket: this.socket,
|
|
@@ -749,7 +738,7 @@ var SocketClient = class {
|
|
|
749
738
|
err: String(err),
|
|
750
739
|
details: this.getVerboseDetails({ rawError: err })
|
|
751
740
|
});
|
|
752
|
-
this.logSocketConfigSnapshot("
|
|
741
|
+
this.logSocketConfigSnapshot("connect_error_event");
|
|
753
742
|
this.getSysEvent("sys:connect_error")({
|
|
754
743
|
error: String(err),
|
|
755
744
|
socket: this.socket,
|
|
@@ -758,14 +747,14 @@ var SocketClient = class {
|
|
|
758
747
|
};
|
|
759
748
|
this.onPong = (raw) => {
|
|
760
749
|
if (!this.socket) {
|
|
761
|
-
this.dbg({ type: "heartbeat",
|
|
750
|
+
this.dbg({ type: "heartbeat", phase: "pong_recv", err: "Socket is null" });
|
|
762
751
|
throw new Error("Socket is null in onPong handler");
|
|
763
752
|
}
|
|
764
753
|
const parsed = this.config.pongPayload.safeParse(raw);
|
|
765
754
|
if (!parsed.success) {
|
|
766
755
|
this.dbg({
|
|
767
756
|
type: "heartbeat",
|
|
768
|
-
|
|
757
|
+
phase: "validation_failed",
|
|
769
758
|
err: `pong payload validation failed: ${parsed.error.message}`,
|
|
770
759
|
details: this.getValidationDetails(parsed.error)
|
|
771
760
|
});
|
|
@@ -774,7 +763,7 @@ var SocketClient = class {
|
|
|
774
763
|
const validated = parsed.data;
|
|
775
764
|
this.dbg({
|
|
776
765
|
type: "heartbeat",
|
|
777
|
-
|
|
766
|
+
phase: "pong_recv",
|
|
778
767
|
payload: validated
|
|
779
768
|
});
|
|
780
769
|
this.getSysEvent("sys:pong")({
|
|
@@ -821,16 +810,16 @@ var SocketClient = class {
|
|
|
821
810
|
secure: typeof opts.secure === "boolean" ? opts.secure : void 0
|
|
822
811
|
};
|
|
823
812
|
}
|
|
824
|
-
logSocketConfigSnapshot(
|
|
813
|
+
logSocketConfigSnapshot(reason) {
|
|
825
814
|
if (!this.debug.logger || !this.debug.config) return;
|
|
826
815
|
const snapshot = this.snapshotSocketConfig(this.socket);
|
|
827
816
|
this.dbg({
|
|
828
817
|
type: "config",
|
|
829
|
-
phase,
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
818
|
+
phase: reason,
|
|
819
|
+
...snapshot == null ? { err: "Socket is missing. " } : {
|
|
820
|
+
socketId: this.socket?.id,
|
|
821
|
+
snapshot
|
|
822
|
+
}
|
|
834
823
|
});
|
|
835
824
|
}
|
|
836
825
|
getValidationDetails(error) {
|
|
@@ -898,7 +887,7 @@ var SocketClient = class {
|
|
|
898
887
|
if (!this.socket) {
|
|
899
888
|
this.dbg({
|
|
900
889
|
type: "heartbeat",
|
|
901
|
-
|
|
890
|
+
phase: "start",
|
|
902
891
|
err: "Socket is null"
|
|
903
892
|
});
|
|
904
893
|
return;
|
|
@@ -906,7 +895,7 @@ var SocketClient = class {
|
|
|
906
895
|
const socket = this.socket;
|
|
907
896
|
this.dbg({
|
|
908
897
|
type: "heartbeat",
|
|
909
|
-
|
|
898
|
+
phase: "start",
|
|
910
899
|
details: {
|
|
911
900
|
intervalMs: this.hb.intervalMs,
|
|
912
901
|
timeoutMs: this.hb.timeoutMs
|
|
@@ -916,7 +905,7 @@ var SocketClient = class {
|
|
|
916
905
|
if (!socket) {
|
|
917
906
|
this.dbg({
|
|
918
907
|
type: "heartbeat",
|
|
919
|
-
|
|
908
|
+
phase: "tick_skip",
|
|
920
909
|
err: "Socket missing during heartbeat tick"
|
|
921
910
|
});
|
|
922
911
|
return;
|
|
@@ -929,7 +918,7 @@ var SocketClient = class {
|
|
|
929
918
|
if (!check.success) {
|
|
930
919
|
this.dbg({
|
|
931
920
|
type: "heartbeat",
|
|
932
|
-
|
|
921
|
+
phase: "validation_failed",
|
|
933
922
|
err: "ping payload validation failed",
|
|
934
923
|
details: this.getValidationDetails(check.error)
|
|
935
924
|
});
|
|
@@ -942,7 +931,7 @@ var SocketClient = class {
|
|
|
942
931
|
socket.emit("sys:ping", dataToSend);
|
|
943
932
|
this.dbg({
|
|
944
933
|
type: "heartbeat",
|
|
945
|
-
|
|
934
|
+
phase: "ping_emit",
|
|
946
935
|
payload: dataToSend
|
|
947
936
|
});
|
|
948
937
|
};
|
|
@@ -963,7 +952,7 @@ var SocketClient = class {
|
|
|
963
952
|
}
|
|
964
953
|
this.dbg({
|
|
965
954
|
type: "heartbeat",
|
|
966
|
-
|
|
955
|
+
phase: "stop",
|
|
967
956
|
details: {
|
|
968
957
|
hadTimer
|
|
969
958
|
}
|
|
@@ -994,7 +983,7 @@ var SocketClient = class {
|
|
|
994
983
|
}
|
|
995
984
|
joinRooms(rooms, meta) {
|
|
996
985
|
if (!this.socket) {
|
|
997
|
-
this.dbg({ type: "room",
|
|
986
|
+
this.dbg({ type: "room", phase: "join", rooms: this.toArray(rooms), err: "Socket is null" });
|
|
998
987
|
throw new Error("Socket is null in joinRooms method");
|
|
999
988
|
}
|
|
1000
989
|
if (!this.getSysEvent("sys:room_join")({
|
|
@@ -1003,7 +992,7 @@ var SocketClient = class {
|
|
|
1003
992
|
socket: this.socket,
|
|
1004
993
|
client: this
|
|
1005
994
|
})) {
|
|
1006
|
-
this.dbg({ type: "room",
|
|
995
|
+
this.dbg({ type: "room", phase: "join", rooms: this.toArray(rooms), err: "sys:room_join handler aborted join" });
|
|
1007
996
|
return;
|
|
1008
997
|
}
|
|
1009
998
|
const list = this.toArray(rooms);
|
|
@@ -1022,7 +1011,7 @@ var SocketClient = class {
|
|
|
1022
1011
|
this.rollbackJoinIncrement(toJoin);
|
|
1023
1012
|
this.dbg({
|
|
1024
1013
|
type: "room",
|
|
1025
|
-
|
|
1014
|
+
phase: "join",
|
|
1026
1015
|
rooms: toJoin,
|
|
1027
1016
|
err: "payload validation failed",
|
|
1028
1017
|
details: this.getValidationDetails(payloadResult.error)
|
|
@@ -1032,12 +1021,12 @@ var SocketClient = class {
|
|
|
1032
1021
|
const payload = payloadResult.data;
|
|
1033
1022
|
const normalizedRooms = this.toArray(payload.rooms);
|
|
1034
1023
|
this.socket.emit("sys:room_join", payload);
|
|
1035
|
-
this.dbg({ type: "room",
|
|
1024
|
+
this.dbg({ type: "room", phase: "join", rooms: normalizedRooms });
|
|
1036
1025
|
}
|
|
1037
1026
|
}
|
|
1038
1027
|
leaveRooms(rooms, meta) {
|
|
1039
1028
|
if (!this.socket) {
|
|
1040
|
-
this.dbg({ type: "room",
|
|
1029
|
+
this.dbg({ type: "room", phase: "leave", rooms: this.toArray(rooms), err: "Socket is null" });
|
|
1041
1030
|
throw new Error("Socket is null in leaveRooms method");
|
|
1042
1031
|
}
|
|
1043
1032
|
if (!this.getSysEvent("sys:room_leave")({
|
|
@@ -1046,7 +1035,7 @@ var SocketClient = class {
|
|
|
1046
1035
|
socket: this.socket,
|
|
1047
1036
|
client: this
|
|
1048
1037
|
})) {
|
|
1049
|
-
this.dbg({ type: "room",
|
|
1038
|
+
this.dbg({ type: "room", phase: "leave", rooms: this.toArray(rooms), err: "sys:room_leave handler aborted leave" });
|
|
1050
1039
|
return;
|
|
1051
1040
|
}
|
|
1052
1041
|
const list = this.toArray(rooms);
|
|
@@ -1067,7 +1056,7 @@ var SocketClient = class {
|
|
|
1067
1056
|
this.rollbackLeaveDecrement(toLeave);
|
|
1068
1057
|
this.dbg({
|
|
1069
1058
|
type: "room",
|
|
1070
|
-
|
|
1059
|
+
phase: "leave",
|
|
1071
1060
|
rooms: toLeave,
|
|
1072
1061
|
err: "payload validation failed",
|
|
1073
1062
|
details: this.getValidationDetails(payloadResult.error)
|
|
@@ -1077,14 +1066,14 @@ var SocketClient = class {
|
|
|
1077
1066
|
const payload = payloadResult.data;
|
|
1078
1067
|
const normalizedRooms = this.toArray(payload.rooms);
|
|
1079
1068
|
this.socket.emit("sys:room_leave", payload);
|
|
1080
|
-
this.dbg({ type: "room",
|
|
1069
|
+
this.dbg({ type: "room", phase: "leave", rooms: normalizedRooms });
|
|
1081
1070
|
}
|
|
1082
1071
|
}
|
|
1083
1072
|
on(event, handler) {
|
|
1084
1073
|
const schema = this.events[event].message;
|
|
1085
|
-
this.dbg({ type: "register",
|
|
1074
|
+
this.dbg({ type: "register", phase: "register", event });
|
|
1086
1075
|
if (!this.socket) {
|
|
1087
|
-
this.dbg({ type: "register",
|
|
1076
|
+
this.dbg({ type: "register", phase: "register", event, err: "Socket is null" });
|
|
1088
1077
|
return () => {
|
|
1089
1078
|
};
|
|
1090
1079
|
}
|
|
@@ -1152,7 +1141,7 @@ var SocketClient = class {
|
|
|
1152
1141
|
s.delete(entry);
|
|
1153
1142
|
if (s.size === 0) this.handlerMap.delete(String(event));
|
|
1154
1143
|
}
|
|
1155
|
-
this.dbg({ type: "register",
|
|
1144
|
+
this.dbg({ type: "register", phase: "unregister", event });
|
|
1156
1145
|
};
|
|
1157
1146
|
}
|
|
1158
1147
|
/**
|
|
@@ -1221,7 +1210,7 @@ var SocketClient = class {
|
|
|
1221
1210
|
nsp: this.getNamespace(this.socket)
|
|
1222
1211
|
}
|
|
1223
1212
|
});
|
|
1224
|
-
this.logSocketConfigSnapshot("
|
|
1213
|
+
this.logSocketConfigSnapshot("disconnect_call");
|
|
1225
1214
|
}
|
|
1226
1215
|
connect() {
|
|
1227
1216
|
if (!this.socket) {
|
|
@@ -1241,7 +1230,7 @@ var SocketClient = class {
|
|
|
1241
1230
|
nsp: this.getNamespace(this.socket)
|
|
1242
1231
|
}
|
|
1243
1232
|
});
|
|
1244
|
-
this.logSocketConfigSnapshot("
|
|
1233
|
+
this.logSocketConfigSnapshot("connect_call");
|
|
1245
1234
|
}
|
|
1246
1235
|
};
|
|
1247
1236
|
// Annotate the CommonJS export names for ESM import in node:
|