Skip to content

Commit 8b7fa39

Browse files
committed
Implement end session due to inactivity that triggers after 15s
1 parent 81b48c9 commit 8b7fa39

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

apps/frontend/src/components/CollaborativeEditor/CollaborativeEditor.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ const CollaborativeEditor = forwardRef(
179179
},
180180
}));
181181

182+
let sessionEndTimeout: any;
183+
182184
useEffect(() => {
183185
if (process.env.NEXT_PUBLIC_SIGNALLING_SERVICE_URL === undefined) {
184186
error("Missing Signalling Service Url");
@@ -213,6 +215,27 @@ const CollaborativeEditor = forwardRef(
213215
// Listen for awareness changes
214216
provider.awareness.on("change", () => {
215217
const updatedStates = provider.awareness.getStates();
218+
219+
// Check the length of updatedStates, if it is equal to 1, we trigger endsession in 15s but if updated to 2, cancel endsession
220+
if (sessionEndTimeout && updatedStates.size == 2) {
221+
clearTimeout(sessionEndTimeout);
222+
sessionEndTimeout = null;
223+
}
224+
225+
// If there's only one participant, set a timeout for 15 seconds
226+
if (updatedStates.size === 1) {
227+
sessionEndTimeout = setTimeout(() => {
228+
// Trigger end session logic here
229+
info(
230+
`Session has ended due to inactivity from matched user ${props.matchedUser}`
231+
);
232+
props.handleCloseCollaboration("peer");
233+
if (props.providerRef.current) {
234+
props.providerRef.current.disconnect();
235+
}
236+
}, 15000); // 15 seconds
237+
}
238+
216239
for (const [clientID, state] of Array.from(updatedStates)) {
217240
if (state.sessionEnded && state.user.name !== props.user) {
218241
if (!sessionEndNotified) {

apps/frontend/src/components/VideoPanel/VideoPanel.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ const VideoPanel = () => {
149149

150150
const toggleMute = () => {
151151
if (userStream) {
152-
console.log(userStream.getAudioTracks());
153152
const audioTrack = userStream.getAudioTracks()[0];
154153

155154
if (audioTrack) {

0 commit comments

Comments
 (0)