@poolse/react 2.8.4 → 2.10.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 +111 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -3
- package/dist/index.d.ts +68 -3
- package/dist/index.js +111 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1063,6 +1063,112 @@ function formatDayLabel(iso, now = /* @__PURE__ */ new Date()) {
|
|
|
1063
1063
|
}
|
|
1064
1064
|
return d.toLocaleDateString(void 0, { day: "numeric", month: "short", year: "numeric" });
|
|
1065
1065
|
}
|
|
1066
|
+
function useCallRoom(conversationId, opts) {
|
|
1067
|
+
const poolse = usePoolse();
|
|
1068
|
+
const [status, setStatus] = react.useState("idle");
|
|
1069
|
+
const [participants, setParticipants] = react.useState([]);
|
|
1070
|
+
const [cameraEnabled, setCamera] = react.useState(false);
|
|
1071
|
+
const [micEnabled, setMic] = react.useState(false);
|
|
1072
|
+
const [error, setError] = react.useState(null);
|
|
1073
|
+
const [sfuAvailable, setSfuAvailable] = react.useState(null);
|
|
1074
|
+
const optsRef = react.useRef(opts);
|
|
1075
|
+
const joined = react.useRef(false);
|
|
1076
|
+
const room = react.useMemo(() => {
|
|
1077
|
+
if (!conversationId) return null;
|
|
1078
|
+
return poolse.call(conversationId, {
|
|
1079
|
+
livekit: optsRef.current.livekit,
|
|
1080
|
+
...optsRef.current.video !== void 0 ? { video: optsRef.current.video } : {},
|
|
1081
|
+
...optsRef.current.muted !== void 0 ? { muted: optsRef.current.muted } : {}
|
|
1082
|
+
});
|
|
1083
|
+
}, [poolse, conversationId]);
|
|
1084
|
+
const sync = react.useCallback((target) => {
|
|
1085
|
+
if (!target) return;
|
|
1086
|
+
setCamera(target.isCameraEnabled());
|
|
1087
|
+
setMic(target.isMicrophoneEnabled());
|
|
1088
|
+
}, []);
|
|
1089
|
+
react.useEffect(() => {
|
|
1090
|
+
if (!room) {
|
|
1091
|
+
setStatus("idle");
|
|
1092
|
+
setParticipants([]);
|
|
1093
|
+
return;
|
|
1094
|
+
}
|
|
1095
|
+
setStatus(room.getStatus());
|
|
1096
|
+
setParticipants(room.getParticipants());
|
|
1097
|
+
const offStatus = room.onStatus(setStatus);
|
|
1098
|
+
const offRoster = room.onParticipants((next) => {
|
|
1099
|
+
setParticipants(next);
|
|
1100
|
+
sync(room);
|
|
1101
|
+
});
|
|
1102
|
+
const offError = room.onError(setError);
|
|
1103
|
+
return () => {
|
|
1104
|
+
offStatus();
|
|
1105
|
+
offRoster();
|
|
1106
|
+
offError();
|
|
1107
|
+
if (joined.current) {
|
|
1108
|
+
joined.current = false;
|
|
1109
|
+
room.leave();
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
}, [room, sync]);
|
|
1113
|
+
const join = react.useCallback(async () => {
|
|
1114
|
+
if (!room) return false;
|
|
1115
|
+
setError(null);
|
|
1116
|
+
try {
|
|
1117
|
+
const connected = await room.join();
|
|
1118
|
+
joined.current = connected;
|
|
1119
|
+
setSfuAvailable(connected);
|
|
1120
|
+
sync(room);
|
|
1121
|
+
return connected;
|
|
1122
|
+
} catch (err) {
|
|
1123
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
1124
|
+
setSfuAvailable(true);
|
|
1125
|
+
return false;
|
|
1126
|
+
}
|
|
1127
|
+
}, [room, sync]);
|
|
1128
|
+
const leave = react.useCallback(() => {
|
|
1129
|
+
if (!joined.current) return;
|
|
1130
|
+
joined.current = false;
|
|
1131
|
+
room?.leave();
|
|
1132
|
+
}, [room]);
|
|
1133
|
+
const setCameraEnabled = react.useCallback(
|
|
1134
|
+
async (enabled) => {
|
|
1135
|
+
if (!room) return;
|
|
1136
|
+
await room.setCameraEnabled(enabled);
|
|
1137
|
+
sync(room);
|
|
1138
|
+
},
|
|
1139
|
+
[room, sync]
|
|
1140
|
+
);
|
|
1141
|
+
const setMicrophoneEnabled = react.useCallback(
|
|
1142
|
+
async (enabled) => {
|
|
1143
|
+
if (!room) return;
|
|
1144
|
+
await room.setMicrophoneEnabled(enabled);
|
|
1145
|
+
sync(room);
|
|
1146
|
+
},
|
|
1147
|
+
[room, sync]
|
|
1148
|
+
);
|
|
1149
|
+
const toggleCamera = react.useCallback(async () => {
|
|
1150
|
+
if (!room) return;
|
|
1151
|
+
await setCameraEnabled(!room.isCameraEnabled());
|
|
1152
|
+
}, [room, setCameraEnabled]);
|
|
1153
|
+
const toggleMic = react.useCallback(async () => {
|
|
1154
|
+
if (!room) return;
|
|
1155
|
+
await setMicrophoneEnabled(!room.isMicrophoneEnabled());
|
|
1156
|
+
}, [room, setMicrophoneEnabled]);
|
|
1157
|
+
return {
|
|
1158
|
+
status,
|
|
1159
|
+
participants,
|
|
1160
|
+
cameraEnabled,
|
|
1161
|
+
micEnabled,
|
|
1162
|
+
error,
|
|
1163
|
+
sfuAvailable,
|
|
1164
|
+
join,
|
|
1165
|
+
leave,
|
|
1166
|
+
setCameraEnabled,
|
|
1167
|
+
toggleCamera,
|
|
1168
|
+
setMicrophoneEnabled,
|
|
1169
|
+
toggleMic
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1066
1172
|
function useVoiceRoom(conversationId, opts = {}) {
|
|
1067
1173
|
const poolse = usePoolse();
|
|
1068
1174
|
const [status, setStatus] = react.useState("idle");
|
|
@@ -1177,11 +1283,11 @@ function useCalls(userId, opts = {}) {
|
|
|
1177
1283
|
};
|
|
1178
1284
|
}, [calls]);
|
|
1179
1285
|
const call = react.useCallback(
|
|
1180
|
-
async (conversationId) => {
|
|
1286
|
+
async (conversationId, media2 = "audio") => {
|
|
1181
1287
|
if (!calls) return;
|
|
1182
1288
|
setError(null);
|
|
1183
1289
|
try {
|
|
1184
|
-
const placed = await calls.invite(conversationId);
|
|
1290
|
+
const placed = await calls.invite(conversationId, media2);
|
|
1185
1291
|
setOutgoing(placed);
|
|
1186
1292
|
setPhase("ringing-out");
|
|
1187
1293
|
} catch (err) {
|
|
@@ -1272,11 +1378,13 @@ function useCalls(userId, opts = {}) {
|
|
|
1272
1378
|
setActiveConversationId(null);
|
|
1273
1379
|
setError(null);
|
|
1274
1380
|
}, []);
|
|
1381
|
+
const media = incoming?.media ?? outgoing?.media ?? "audio";
|
|
1275
1382
|
return {
|
|
1276
1383
|
phase,
|
|
1277
1384
|
incoming,
|
|
1278
1385
|
outgoing,
|
|
1279
1386
|
activeConversationId,
|
|
1387
|
+
media,
|
|
1280
1388
|
error,
|
|
1281
1389
|
call,
|
|
1282
1390
|
accept,
|
|
@@ -1314,6 +1422,7 @@ exports.sameDay = sameDay;
|
|
|
1314
1422
|
exports.sameGroup = sameGroup;
|
|
1315
1423
|
exports.useAttachmentUpload = useAttachmentUpload;
|
|
1316
1424
|
exports.useAttachmentUrl = useAttachmentUrl;
|
|
1425
|
+
exports.useCallRoom = useCallRoom;
|
|
1317
1426
|
exports.useCalls = useCalls;
|
|
1318
1427
|
exports.useConversation = useConversation;
|
|
1319
1428
|
exports.useConversations = useConversations;
|