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(yjs): add WebRTC provider support alongside Hocuspocus #4142

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .changeset/three-humans-attack.md
Copy link
Member

Choose a reason for hiding this comment

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

Could you just write down a short migration snippet?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like no migration is necessary, since the providerType defaults to hocuspocus and hocuspocusProviderOptions hasn't been changed.

This should probably be a minor changeset rather than major.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@udecode/plate-yjs': major
---

- Added WebRTC provider support to plate-yjs plugin
- Created unified provider interface for consistent API
- Maintained backward compatibility with Hocuspocus
- Added configuration options for both providers
37 changes: 37 additions & 0 deletions apps/www/content/docs/cn/components/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,43 @@ toc: true

使用 [CLI](https://platejs.org/docs/components/cli) 安装最新版本的组件。

## 2025年4月 #21

### 4月1日 #21.1

Plate 47 - WebRTC 协作

- `plate-yjs`: WebRTC 提供程序支持的重大更新
- 添加 WebRTC 提供程序支持,实现点对点协作
- 创建统一的提供程序接口,提供一致的 API
- 保持与 Hocuspocus 的向后兼容性
- 为两种提供程序添加配置选项

```tsx
// WebRTC 提供程序配置
YjsPlugin.configure({
options: {
providerType: 'webrtc',
webrtcOptions: {
// WebRTC 特定选项
signaling: ['wss://your-signaling-server'],
password: 'optional-room-password',
},
},
});

// Hocuspocus 提供程序(现有方法)
YjsPlugin.configure({
options: {
providerType: 'hocuspocus', // 或未定义以保持向后兼容性
hocuspocusOptions: {
// Hocuspocus 特定选项
url: 'wss://your-hocuspocus-server',
},
},
});
```

## 2024年12月 #17

### 12月28日 #17.8
Expand Down
37 changes: 37 additions & 0 deletions apps/www/content/docs/en/components/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,43 @@ Since Plate UI is not a component library, a changelog is maintained here.

Use the [CLI](https://platejs.org/docs/components/cli) to install the latest version of the components.

## April 2025 #21

### April 1 #21.1

Plate 47 - WebRTC collaboration

- `plate-yjs`: Major update with WebRTC provider support
- Added WebRTC provider support for peer-to-peer collaboration
- Created unified provider interface for consistent API
- Maintained backward compatibility with Hocuspocus
- Added configuration options for both providers

```tsx
// WebRTC provider configuration
YjsPlugin.configure({
options: {
providerType: 'webrtc',
webrtcOptions: {
// WebRTC specific options
signaling: ['wss://your-signaling-server'],
password: 'optional-room-password',
},
},
});

// Hocuspocus provider (existing approach)
YjsPlugin.configure({
options: {
providerType: 'hocuspocus', // or undefined for backward compatibility
hocuspocusOptions: {
// Hocuspocus specific options
url: 'wss://your-hocuspocus-server',
},
},
});
```
Comment on lines +11 to +46
Copy link
Collaborator

Choose a reason for hiding this comment

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

The components/changelog.mdx file is only used for changes to Plate's UI components (which require a separate changelog since they aren't published as an NPM package). If you could move this sample code into the .changeset/three-humans-attack.md file, that would be great.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No problem I will do that.


## March 2025 #20

### March 2 #20.2
Expand Down
1 change: 1 addition & 0 deletions packages/code-block/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

export * from './BaseCodeBlockPlugin';
export * from './setCodeBlockToDecorations';
export * from './types';
export * from './withCodeBlock';
export * from './withInsertDataCodeBlock';
Expand Down
4 changes: 3 additions & 1 deletion packages/table/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @file Automatically generated by barrelsby. */
/**
* @file Automatically generated by barrelsby.
*/

export * from './BaseTablePlugin';
export * from './constants';
Expand Down
4 changes: 3 additions & 1 deletion packages/table/src/lib/transforms/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @file Automatically generated by barrelsby. */
/**
* @file Automatically generated by barrelsby.
*/

export * from './deleteColumn';
export * from './deleteRow';
Expand Down
4 changes: 3 additions & 1 deletion packages/table/src/react/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @file Automatically generated by barrelsby. */
/**
* @file Automatically generated by barrelsby.
*/

export * from './useCellIndices';
export * from './useTableMergeState';
70 changes: 67 additions & 3 deletions packages/yjs/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,75 @@
# Plate yjs plugin

This package implements the yjs plugin for Plate and Hocuspocus.
This package implements the yjs plugin for Plate with support for both Hocuspocus and WebRTC providers.

## Documentation

Check out
[Collaboration](https://platejs.org/docs/collaboration).
Check out [Collaboration](https://platejs.org/docs/collaboration) for the main documentation.

### Provider Options

The plugin supports two types of providers:

1. **Hocuspocus Provider** (Default)
- Server-based collaboration using WebSocket
- Suitable for large-scale applications
- Requires a Hocuspocus server
- Configuration:
```typescript
const options = {
providerType: 'hocuspocus',
hocuspocusProviderOptions: {
url: 'ws://localhost:1234',
name: 'document-name',
// ... other Hocuspocus options
}
};
```

2. **WebRTC Provider**
- Peer-to-peer collaboration using WebRTC
- No server required (except for signaling)
- Best for small to medium-sized groups
- Configuration:
```typescript
const options = {
providerType: 'webrtc',
webrtcProviderOptions: {
roomName: 'your-room-name',
password: 'optional-room-password',
signaling: ['wss://signaling.yjs.dev'], // Optional custom signaling servers
maxConns: 20, // Optional max connections
filterBcConns: true, // Optional: filter broadcast channel connections
}
};
```

## Example Usage

```typescript
import { createPlateUI } from '@udecode/plate';
import { YjsPlugin } from '@udecode/plate-yjs';

const plugins = [
// ... other plugins
YjsPlugin({
// Choose your provider type and options
providerType: 'webrtc', // or 'hocuspocus'
webrtcProviderOptions: {
roomName: 'my-document',
password: 'optional-password',
},
// Optional cursor options
cursorOptions: {
// ... cursor options
},
}),
];

const editor = createPlateUI({
plugins,
});
```

## License

Expand Down
1 change: 1 addition & 0 deletions packages/yjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"dependencies": {
"@hocuspocus/provider": "^2.15.2",
"@slate-yjs/core": "^1.0.2",
"y-webrtc": "10.3.0",
"yjs": "^13.6.23"
},
"devDependencies": {
Expand Down
Loading