Skip to content
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

✨ feat: support Liveblocks sync #2611

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

CloudPassenger
Copy link
Contributor

@CloudPassenger CloudPassenger commented May 22, 2024

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • ⚡️ perf
  • 📝 docs

🔀 变更说明 | Description of Change

This pull request introduces a new feature that improves data synchronisation in LobeChat by integrating the real-time online service provided by Liveblocks.

While the existing WebRTC solution provides a highly encrypted environment, it requires devices to be online at the same time and fails to synchronise data when P2P connections are unstable. By using servers hosted by Liveblocks, we can significantly improve the performance and reliability of data synchronisation.

During deployment, setting the LIVEBLOCKS_SECRET_KEY allows the use of the Liveblocks instance configured on the server. Users can also use their public key to connect to their own storage instance, providing a balance between convenience and security.

If login authentication is enabled in LobeChat, the user identifier is used as the sync room name by default, seamlessly integrating user authentication and data synchronisation.

Currently, the implementation has passed testing and can achieve bi-directional synchronisation between WebRTC P2P and the Liveblocks server. A demo video is attached:

Lobechat.-.WebRTC.Liveblocks.Sync.mp4

📝 补充信息 | Additional Information

This is a demo version that only integrates the new sync features. In a later update I will update more UI components like the <SyncStatusInspector /> to make Liveblocks synchronisation compatible.

Copy link

vercel bot commented May 22, 2024

@CloudPassenger is attempting to deploy a commit to the LobeHub Team on Vercel.

A member of the Team first needs to authorize it.

@lobehubbot
Copy link
Member

👍 @CloudPassenger

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

@arvinxx
Copy link
Contributor

arvinxx commented May 22, 2024

Amazing Work! plz rebase main branch~ 😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a common method , move it to the uilts folder?

src/config/app.ts Outdated Show resolved Hide resolved
@@ -22,6 +23,7 @@ export const FeatureFlagsSchema = z.object({
export type IFeatureFlags = z.infer<typeof FeatureFlagsSchema>;

export const DEFAULT_FEATURE_FLAGS: IFeatureFlags = {
liveblocks_sync: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be false by default, and enable it by add +liveblocks_sync

// ====== 2. init webrtc provider ====== //
this.logger(`[WebRTC] init provider... room: ${channel.name}`);
const { WebrtcProvider } = await import('y-webrtc');
if (channel.webrtc.enabled) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there can be two methods: connectWithWebRTC and connectWithLiveBlocks ,

move the implement into these method and make the connect as entry.

const { t } = useTranslation('common');
const [haveConfig, setSettings] = useUserStore((s) => [
!!syncSettingsSelectors.webrtcConfig(s).channelName,
!!channelSyncConfig(method)(s),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make channelSyncConfig as a selector

@ZeroDeng01
Copy link

Amazing Work! plz rebase main branch~ 😅

非常需要一个稳定的同步功能,希望早日上线👍

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Amazing Work! plz rebase main branch~ 😅

We really need a stable synchronization function and hope it will be online soon👍

@CloudPassenger
Copy link
Contributor Author

Sorry, I've been very busy these days so my progress has slowed down, I'll try to keep on top of this pull request and make changes, I'm really sorry. :(

@arvinxx
Copy link
Contributor

arvinxx commented Jun 10, 2024

Sorry, I've been very busy these days so my progress has slowed down, I'll try to keep on top of this pull request and make changes, I'm really sorry. :(

Take you time, it not hurry for it~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants