Skip to content

Implement participant indicator for sessions #2948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7e4e904
Added classes for cursors UI
izruff Mar 25, 2024
b4667c7
Added basic implementation of participant cursors
izruff Mar 26, 2024
9adcc57
Added support for multiple cursors
izruff Apr 1, 2024
f21962a
Added more info to user presence
izruff Apr 1, 2024
21d10e5
Added user name and color identifier into cursors
izruff Apr 2, 2024
dfddbce
Fixed formatting
izruff Apr 2, 2024
db56aaa
added functions to check for cursors and clean up cursors when user e…
wrjgold Apr 2, 2024
49e0966
Added random colour generator
wrjgold Apr 3, 2024
4e95042
Passed cursor manager to ShareAce binding instead of handling in fron…
izruff Apr 5, 2024
b737786
Removed comments and added credits
izruff Apr 17, 2024
a60c9ca
Merge branch 'master' into feat/participant-indicator
RichDom2185 May 2, 2024
ac63847
Merge branch 'master' into feat/participant-indicator
RichDom2185 May 3, 2024
fea0c21
Merge branch 'master' into feat/participant-indicator
RichDom2185 May 5, 2024
4091fdc
Merge branch 'master' into feat/participant-indicator
RichDom2185 May 5, 2024
5d87a7e
Install `ace-collab-ext` dependency
RichDom2185 May 12, 2024
1fb59fb
Replace files with those from library
RichDom2185 May 12, 2024
aeb6d1d
Restore CSS import
RichDom2185 May 12, 2024
490968c
Merge branch 'master' into feat/participant-indicator
RichDom2185 May 12, 2024
6eccfd4
Merge branch 'master' into feat/participant-indicator
RichDom2185 May 12, 2024
ca2dcd1
Merge branch 'master' into feat/participant-indicator
RichDom2185 May 13, 2024
b4f4743
Merge branch 'master' into feat/participant-indicator
RichDom2185 May 15, 2024
07b133d
Merge branch 'master' into feat/participant-indicator
RichDom2185 Jun 30, 2024
b9929de
Fix hooks warning
RichDom2185 Jun 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@babel/preset-typescript": "^7.24.1",
"@babel/runtime": "^7.24.5",
"@convergencelabs/ace-collab-ext": "^0.6.0",
"@craco/craco": "^7.1.0",
"@svgr/webpack": "^8.0.0",
"@testing-library/jest-dom": "^6.0.0",
Expand Down
32 changes: 29 additions & 3 deletions src/commons/editor/UseShareAce.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import '@convergencelabs/ace-collab-ext/dist/css/ace-collab-ext.css';

import { AceMultiCursorManager } from '@convergencelabs/ace-collab-ext';
import * as Sentry from '@sentry/browser';
import sharedbAce from '@sourceacademy/sharedb-ace';
import React from 'react';
import React, { useMemo } from 'react';

import { getDocInfoFromSessionId, getSessionUrl } from '../collabEditing/CollabEditingHelper';
import { useSession } from '../utils/Hooks';
import { showSuccessMessage } from '../utils/notifications/NotificationsHelper';
import { EditorHook } from './Editor';

Expand All @@ -21,20 +25,27 @@ const useShareAce: EditorHook = (inProps, outProps, keyBindings, reactAceRef) =>

const { editorSessionId, sessionDetails } = inProps;

const { name } = useSession();

const user = useMemo(() => ({ name, color: getColor() }), [name]);

React.useEffect(() => {
if (!editorSessionId || !sessionDetails) {
return;
}

const editor = reactAceRef.current!.editor;
const cursorManager = new AceMultiCursorManager(editor.getSession());
const ShareAce = new sharedbAce(sessionDetails.docId, {
user,
cursorManager,
WsUrl: getSessionUrl(editorSessionId, true),
pluginWsUrl: null,
namespace: 'sa'
});

ShareAce.on('ready', () => {
ShareAce.add(editor, ['contents'], []);
ShareAce.add(editor, cursorManager, ['contents'], []);
propsRef.current.handleSetSharedbConnected!(true);

// Disables editor in a read-only session
Expand Down Expand Up @@ -87,8 +98,23 @@ const useShareAce: EditorHook = (inProps, outProps, keyBindings, reactAceRef) =>

// Resets editor to normal after leaving the session
editor.setReadOnly(false);

// Removes all cursors
cursorManager.removeAll();
};
}, [editorSessionId, sessionDetails, reactAceRef]);
}, [editorSessionId, sessionDetails, reactAceRef, user]);
};

function getColor() {
return (
'hsl(' +
360 * Math.random() +
',' +
(25 + 70 * Math.random()) +
'%,' +
(50 + 20 * Math.random()) +
'%)'
);
}

export default useShareAce;
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,13 @@
resolved "https://registry.yarnpkg.com/@commander-js/extra-typings/-/extra-typings-12.0.1.tgz#4a74a9ccf1d19ef24e71df59359c6d90a605a469"
integrity sha512-OvkMobb1eMqOCuJdbuSin/KJkkZr7n24/UNV+Lcz/0Dhepf3r2p9PaGwpRpAWej7A+gQnny4h8mGhpFl4giKkg==

"@convergencelabs/ace-collab-ext@^0.6.0":
version "0.6.0"
resolved "https://registry.yarnpkg.com/@convergencelabs/ace-collab-ext/-/ace-collab-ext-0.6.0.tgz#dc914080f84312916940ed1e0d476fed7582a691"
integrity sha512-QizJXn66bHu688jrMD6X18YmePu0YXmL8a/4EOxMOPFepDioS34oz1TTmL7oq1AHRBhCRAxKHJao53LbqyJ8vQ==
dependencies:
ace-builds "^1.4.12"

"@craco/craco@^7.1.0":
version "7.1.0"
resolved "https://registry.yarnpkg.com/@craco/craco/-/craco-7.1.0.tgz#12bd394c7f0334e214302e4d35a1768f68042fbb"
Expand Down Expand Up @@ -3684,7 +3691,7 @@ accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.8:
mime-types "~2.1.34"
negotiator "0.6.3"

ace-builds@^1.4.14:
ace-builds@^1.4.12, ace-builds@^1.4.14:
version "1.15.3"
resolved "https://registry.yarnpkg.com/ace-builds/-/ace-builds-1.15.3.tgz#9e35d174acb80297c6f236be2c8bb8574786f719"
integrity sha512-hq8+4DfQcUYcUyAF3vF7UoGFXwNxXST5A2IdarUOp9/Xg1thWTfxusPI2HAlTvXRTVjLDQOj9O34uPoTehEs0A==
Expand Down
Loading