Skip to content

Commit 371746f

Browse files
committed
Adds documentation for message chunking feature
Documents the new chunking feature for handling large messages, including rationale, operational details, and configuration steps for both Unity (C#) and JavaScript environments. Highlights the importance of synchronized chunk size limits to address platform-specific message size restrictions like Android WebView.
1 parent 5055b0e commit 371746f

File tree

2 files changed

+99
-4
lines changed

2 files changed

+99
-4
lines changed

webview_rpc_runtime_library/README.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,58 @@ Download the latest release from the [WebViewRPC Code Generator repository](http
168168
- **Mac**: `protoc-gen-webviewrpc`
169169
- **Linux**: Not provided (requires manual build).
170170

171+
## Chunking for Large Messages
172+
173+
To handle environments with message size limitations, such as certain Android WebViews where the JavaScript bridge limit is around 1KB, WebView RPC includes a chunking feature. This allows large messages to be split into smaller chunks and reassembled on the receiving end.
174+
175+
### How It Works
176+
177+
When chunking is enabled, any message exceeding `MaxChunkSize` is automatically divided into smaller parts. Each chunk is sent individually and then reassembled by the receiver. This process is handled transparently by the library.
178+
179+
### Configuration
180+
181+
Chunking must be enabled and configured on both the C# (Unity) and JavaScript (WebView) sides to work correctly.
182+
183+
#### Unity (C#) Configuration
184+
185+
In your Unity script, configure the settings before initializing the client or server.
186+
187+
```csharp
188+
using WebViewRPC;
189+
// ...
190+
191+
void Start()
192+
{
193+
// Enable chunking and set the max chunk size (e.g., 900 bytes)
194+
WebViewRpcConfiguration.EnableChunking = true;
195+
WebViewRpcConfiguration.MaxChunkSize = 900;
196+
197+
// ... initialize your RPC client/server
198+
}
199+
```
200+
201+
#### JavaScript Configuration
202+
203+
Similarly, configure the settings in your JavaScript code.
204+
205+
```javascript
206+
import { WebViewRpcConfiguration } from 'app-webview-rpc';
207+
208+
// Enable chunking and set the max chunk size
209+
WebViewRpcConfiguration.enableChunking = true;
210+
WebViewRpcConfiguration.maxChunkSize = 900;
211+
212+
// ... initialize your RPC client/server
213+
```
214+
215+
> [!NOTE]
216+
> Both the C# and JavaScript sides must have the same `MaxChunkSize` for chunking to function reliably. It is recommended to set this value to around 900 bytes to safely stay under the typical 1KB limit on Android.
217+
171218
## Quick Start
172219

173220
HelloWorld is a simple RPC service that receives a `HelloRequest` message and returns a `HelloResponse` message. In this example, we will implement HelloWorld and verify communication between the Unity client and the WebView client.
174221

175-
The HelloWorld service takes a `HelloRequest` and returns a `HelloResponse`. First, lets look at the example where the C# side acts as the server and the JavaScript side acts as the client.
222+
The HelloWorld service takes a `HelloRequest` and returns a `HelloResponse`. First, let's look at the example where the C# side acts as the server and the JavaScript side acts as the client.
176223

177224
### Defining the protobuf File
178225

@@ -265,7 +312,7 @@ protoc \
265312
- The bridge code mediates communication between C# and JavaScript.
266313
- WebViewRpc is abstracted so it can be used with any WebView library.
267314
- Implement the bridge code according to your chosen WebView library.
268-
- Below is an example using Viewplexs CanvasWebViewPrefab.
315+
- Below is an example using Viewplex's CanvasWebViewPrefab.
269316

270317
```csharp
271318
using System;
@@ -335,7 +382,7 @@ export class VuplexBridge {
335382
if (this._isVuplexReady && window.vuplex) {
336383
window.vuplex.postMessage(base64Str);
337384
} else {
338-
// If vuplex isnt ready yet, store messages in a queue
385+
// If vuplex isn't ready yet, store messages in a queue
339386
this._pendingMessages.push(base64Str);
340387
}
341388
}
@@ -379,7 +426,7 @@ public class WebViewRpcTester : MonoBehaviour
379426

380427
private async Task InitializeWebView(CanvasWebViewPrefab webView)
381428
{
382-
// Example uses Viewplexs CanvasWebViewPrefab
429+
// Example uses Viewplex's CanvasWebViewPrefab
383430
await webView.WaitUntilInitialized();
384431
webView.WebView.LoadUrl("http://localhost:8081");
385432
await webView.WebView.WaitForNextPageLoadToFinish();

webview_rpc_runtime_library/README_ko.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,54 @@ protoc --version # Ensure compiler version is 3+
146146
- Linux: 제공하지 않습니다.(직접 빌드 필요)
147147

148148

149+
## 대용량 메시지를 위한 청킹(분할 전송) 기능
150+
151+
특정 안드로이드 WebView와 같이 JavaScript 브리지 통신에 약 1KB의 메시지 크기 제한이 있는 환경에 대응하기 위해, WebView RPC는 청킹(Chunking) 기능을 포함하고 있습니다. 이 기능을 사용하면 대용량 메시지를 작은 조각으로 나누어 전송하고 수신 측에서 재조립할 수 있습니다.
152+
153+
### 동작 방식
154+
155+
청킹이 활성화되면, `MaxChunkSize`를 초과하는 모든 메시지는 자동으로 더 작은 부분으로 분할됩니다. 각 청크는 개별적으로 전송된 후 수신자에 의해 재조립됩니다. 이 과정은 라이브러리 내부에서 투명하게 처리됩니다.
156+
157+
### 설정 방법
158+
159+
청킹 기능이 올바르게 동작하려면 C#(Unity)와 JavaScript(웹뷰) 양쪽 모두에서 활성화하고 설정해야 합니다.
160+
161+
#### Unity (C#) 설정
162+
163+
Unity 스크립트에서 클라이언트 또는 서버를 초기화하기 전에 설정을 구성합니다.
164+
165+
```csharp
166+
using WebViewRPC;
167+
// ...
168+
169+
void Start()
170+
{
171+
// 청킹 활성화 및 최대 청크 크기 설정 (예: 900바이트)
172+
WebViewRpcConfiguration.EnableChunking = true;
173+
WebViewRpcConfiguration.MaxChunkSize = 900;
174+
175+
// ... RPC 클라이언트/서버 초기화
176+
}
177+
```
178+
179+
#### JavaScript 설정
180+
181+
마찬가지로 JavaScript 코드에서도 설정을 구성합니다.
182+
183+
```javascript
184+
import { WebViewRpcConfiguration } from 'app-webview-rpc';
185+
186+
// 청킹 활성화 및 최대 청크 크기 설정
187+
WebViewRpcConfiguration.enableChunking = true;
188+
WebViewRpcConfiguration.maxChunkSize = 900;
189+
190+
// ... RPC 클라이언트/서버 초기화
191+
```
192+
193+
> [!NOTE]
194+
> 청킹이 안정적으로 동작하려면 C#과 JavaScript 양쪽의 `MaxChunkSize`가 동일해야 합니다. 안드로이드의 일반적인 1KB 제한을 안전하게 피하려면 이 값을 약 900바이트로 설정하는 것이 좋습니다.
195+
196+
149197
## 빠른 시작
150198
HelloWorld 라는 간단한 RPC 서비스를 구현하고, 유니티 클라이언트와 웹뷰 클라이언트 간의 통신을 확인해보겠습니다.
151199

0 commit comments

Comments
 (0)