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 sync data between different device #1525

Merged
merged 19 commits into from
Mar 22, 2024
Merged

✨ feat: support sync data between different device #1525

merged 19 commits into from
Mar 22, 2024

Conversation

arvinxx
Copy link
Contributor

@arvinxx arvinxx commented Mar 10, 2024

@arvinxx arvinxx marked this pull request as draft March 10, 2024 14:50
Copy link

vercel bot commented Mar 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lobe-chat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 22, 2024 5:54am

@lobehubbot
Copy link
Member

👍 @arvinxx

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.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

Copy link

codecov bot commented Mar 10, 2024

Codecov Report

Attention: Patch coverage is 38.92340% with 295 lines in your changes are missing coverage. Please review.

Project coverage is 91.06%. Comparing base (04d8e53) to head (838ab25).
Report is 12 commits behind head on main.

❗ Current head 838ab25 differs from pull request most recent head bd76f4e. Consider uploading reports for the commit bd76f4e to get more accurate results

Files Patch % Lines
src/database/core/sync.ts 21.20% 223 Missing ⚠️
src/store/global/slices/common/action.ts 12.12% 58 Missing ⚠️
src/services/global.ts 35.29% 11 Missing ⚠️
src/database/core/model.ts 93.61% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1525      +/-   ##
==========================================
- Coverage   92.57%   91.06%   -1.52%     
==========================================
  Files         239      235       -4     
  Lines       13066    13091      +25     
  Branches     1562     1545      -17     
==========================================
- Hits        12096    11921     -175     
- Misses        970     1170     +200     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@arvinxx arvinxx changed the title ✨ feat: support sync data between local and remote server [WIP] ✨ feat: support sync data between local and remote server Mar 10, 2024
@arvinxx
Copy link
Contributor Author

arvinxx commented Mar 12, 2024

  • 基础同步逻辑
    • peer 进入时,进入监听触发态(会触发自己数据的更新)
    • peer 进入时,同步现有成员的数据
  • webrtc 信令服务器(自部署?) https://github.com/arvinxx/y-webrtc-signaling
  • Redis 同步逻辑?

1 数据库基础操作,需要触发 sync 变更逻辑。 需要抽取基础方法并重构现有实现逻辑

2 监听 ymap 对象变更,触发db 变更,需要考虑优化成bulk操作

3 当第一次建联时,需要已有节点向刚建联节点广播现有的数据。

问题: 多个节点第一次达成同步状态后,后续新的节点进入时,新节点没有触发新的「synced」 动作。(非常怀疑是这个问题:yjs/y-webrtc#19 (comment)

经验:多个 YJS Map 的 set 行为,可以用事务存成一个变更
经验:每次变更如果携带的数据量过大,会导致 WebRTC 无法正常发出(例如 messages 有几百条就无法正常发出),相关 issue: yjs/y-webrtc#20

问题: 在 y-websocket 中,我们可以与后端/全局事实来源同步。但是,当只有客户端(或根本没有客户端)时,我们什么时候应该发出 sync?当没有中央真相来源时,我们什么时候才能真正与全球状态同步?

In y-websocket we can sync with the backend / the global source of truth. But when should we emit sync when there are only clients (or no client at all)? When are we truly synced with the global state when there is no central source of truth?
yjs/y-webrtc#54 (comment)

问题:似乎没有办法在 WebRTC 模块里感知到信令服务器的连接成功与否?yjs/y-webrtc#49

有,在 provider.signalingConns 方法中可以看到该信令服务器连接情况

[{
    "_observers": {},
    "url": "wss://y-webrtc-eu.fly.dev",
    "ws": {},
    "binaryType": null,
    "connected": false,
    "connecting": true,
    "unsuccessfulReconnects": 0,
    "lastMessageReceived": 0,
    "shouldConnect": true,
    "_checkInterval": 480,
    "providers": {}
}]

https://discuss.yjs.dev/t/issues-connecting-to-y-webrtc-signalling-server-deployed-on-app-engine/1748

@lobehubbot
Copy link
Member

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


1 Basic database operations need to trigger sync change logic. Need to extract basic methods and reconstruct existing implementation logic

@arvinxx arvinxx marked this pull request as ready for review March 22, 2024 07:04
@arvinxx arvinxx changed the title [WIP] ✨ feat: support sync data between different device ✨ feat: support sync data between different device Mar 22, 2024
@arvinxx arvinxx merged commit 60d9186 into main Mar 22, 2024
8 checks passed
@arvinxx arvinxx deleted the feat/sync branch March 22, 2024 08:07
@lobehubbot
Copy link
Member

❤️ Great PR @arvinxx ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.
项目的成长离不开用户反馈和贡献,感谢您的贡献! 如果您对 LobeHub 开发者社区感兴趣,请加入我们的 discord,然后私信 @arvinxx@canisminor1990。他们会邀请您加入我们的私密开发者频道。我们将会讨论关于 Lobe Chat 的开发,分享和讨论全球范围内的 AI 消息。

github-actions bot pushed a commit that referenced this pull request Mar 22, 2024
## [Version 0.141.0](v0.140.1...v0.141.0)
<sup>Released on **2024-03-22**</sup>

#### ✨ Features

- **misc**: Using YJS and WebRTC to support sync data between different devices.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Using YJS and WebRTC to support sync data between different devices, closes [#1525](#1525) ([60d9186](60d9186))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Member

🎉 This PR is included in version 0.141.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit to bentwnghk/lobe-chat that referenced this pull request Mar 22, 2024
## [Version&nbsp;1.21.0](v1.20.1...v1.21.0)
<sup>Released on **2024-03-22**</sup>

#### ✨ Features

- **misc**: Add gemini 1.5 pro support, using YJS and WebRTC to support sync data between different devices.

#### 🐛 Bug Fixes

- **misc**: Fix code block display issue, hide unnecessary models, rename.

#### 💄 Styles

- **misc**:  add Moonshot Kimi Reverse model to Moonshot model provider., The bottom safe area height of iOS.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Add gemini 1.5 pro support, closes [lobehub#1669](https://github.com/bentwnghk/lobe-chat/issues/1669) ([2b280af](2b280af))
* **misc**: Using YJS and WebRTC to support sync data between different devices, closes [lobehub#1525](https://github.com/bentwnghk/lobe-chat/issues/1525) ([60d9186](60d9186))

#### What's fixed

* **misc**: Fix code block display issue, closes [lobehub#1675](https://github.com/bentwnghk/lobe-chat/issues/1675) ([7707dda](7707dda))
* **misc**: Hide unnecessary models ([da9f947](da9f947))
* **misc**: Rename ([49d77ee](49d77ee))

#### Styles

* **misc**:  add Moonshot Kimi Reverse model to Moonshot model provider., closes [lobehub#1659](https://github.com/bentwnghk/lobe-chat/issues/1659) ([5bae263](5bae263))
* **misc**: The bottom safe area height of iOS, closes [lobehub#1637](https://github.com/bentwnghk/lobe-chat/issues/1637) [lobehub#1181](https://github.com/bentwnghk/lobe-chat/issues/1181) ([44fae5e](44fae5e))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
jjcruise pushed a commit to jjcruise/lobe-chat that referenced this pull request Mar 26, 2024
…evices (lobehub#1525)

* ✨ feat: support sync with webrtc

* 🎨 chore: improve code

* 🎨 chore: improve code

* 🐛 fix: fix dont sync when a node enter first

* ✨ feat: support webrtc config settings

* ✨ feat: add device info card

* ✨ feat: finish sync settings

* ✨ feat: finish sync settings page

* ♻️ refactor: refactor the db to support yjs sync

* 🐛 fix: disconnect when user disable sync

* ♻️ refactor: refactor the console with debug

* 🚸 style: add experiment feature tag

* 📱 style: fix with mobile

* 🌐 chore: add i18n

* 💄 style: improve random name action

* 🚸 style: add default Device Name

* 🚸 style: add mobile experiment tag

* 🚨 ci: fix lint
jjcruise pushed a commit to jjcruise/lobe-chat that referenced this pull request Mar 26, 2024
## [Version&nbsp;0.141.0](lobehub/lobe-chat@v0.140.1...v0.141.0)
<sup>Released on **2024-03-22**</sup>

#### ✨ Features

- **misc**: Using YJS and WebRTC to support sync data between different devices.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Using YJS and WebRTC to support sync data between different devices, closes [lobehub#1525](lobehub#1525) ([60d9186](lobehub@60d9186))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
OskarMast added a commit to OskarMast/OpenAI_Integraion_platform that referenced this pull request Apr 5, 2024
## [Version&nbsp;0.141.0](lobehub/lobe-chat@v0.140.1...v0.141.0)
<sup>Released on **2024-03-22**</sup>

#### ✨ Features

- **misc**: Using YJS and WebRTC to support sync data between different devices.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's improved

* **misc**: Using YJS and WebRTC to support sync data between different devices, closes [#1525](lobehub/lobe-chat#1525) ([60d9186](lobehub/lobe-chat@60d9186))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment