nimeshnayaju / y-presence Goto Github PK
View Code? Open in Web Editor NEWSimple react hooks to manage multiplayer presence using Yjs
License: MIT License
Simple react hooks to manage multiplayer presence using Yjs
License: MIT License
Hi,
This may be a very silly and rookie question. Can we implement live cursors using WebRTC instead of WebSocket?
I tried but looks like only local user state is set and tracked.
Hi, i am currently working on team project using yjs, y-presence and react(typescript).
i got this error and i can't solve it. can i please get some help? thank you in advance.
ERROR in ./node_modules/y-presence/dist/index.mjs 2:0-99
Module not found: Error: Can't resolve 'use-sync-external-store/shim/with-selector' in '/Users/kcw2297/Desktop/Drawing-Duo/node_modules/y-presence/dist'
Did you mean 'with-selector.js'?
BREAKING CHANGE: The request 'use-sync-external-store/shim/with-selector' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '.mjs' file, or a '.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
Thanks for the library, it is great. Also would be nice to have an ability to return only other users from useUsers
. Maybe useUsers
should have optional options
argument for selector function and equality function, where in addition excludeSelf
could be presented. What do you think?
Example:
const otherUsers = useUsers(awareness, {
selector: (state) => state,
excludeSelf: true,
});
useSelf works well in most situations. But when I use it with TipTap editor and CollaborationCursor extension here comes an issue:
In a component that renders tipTap editor I need to update the presence of the user like this:
const self = useSelf();
useEffect(() => {
if (!self || !editor) return;
editor.commands.updateUser({
name: self.username,
color: self.color,
});
}, [self, editor]);
Unfortunately this code makes tiptap editor opened websocket to go mad and infinity send a huge amount of messages.
I have create this hook:
import { isEqual } from "lodash-es";
import { useSelf as usePresenceSelf } from "y-presence";
export const useSelf = () => {
const self = usePresenceSelf(awareness) as YUser;
const selfRef = useRef(self);
useEffect(() => {
if (isEqual(self, selfRef.current)) return;
selfRef.current = self;
}, [self]);
return selfRef.current;
};
Now update is working as expected and there is no infinite loop of messages anymore.
Should this be added in the y-presence lib? What do you think?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.