Skip to content

Commit

Permalink
cherry-pick(#33211): docs: use WebSocketFrame abstraction for Java & …
Browse files Browse the repository at this point in the history
….NET
  • Loading branch information
mxschmitt committed Oct 21, 2024
1 parent 5b54067 commit 8e96d94
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 44 deletions.
8 changes: 4 additions & 4 deletions docs/src/api/class-page.md
Original file line number Diff line number Diff line change
Expand Up @@ -3699,8 +3699,8 @@ await page.routeWebSocket('/ws', ws => {

```java
page.routeWebSocket("/ws", ws -> {
ws.onMessage(message -> {
if ("request".equals(message))
ws.onMessage(frame -> {
if ("request".equals(frame.text()))
ws.send("response");
});
});
Expand Down Expand Up @@ -3730,8 +3730,8 @@ page.route_web_socket("/ws", handler)

```csharp
await page.RouteWebSocketAsync("/ws", ws => {
ws.OnMessage(message => {
if (message == "request")
ws.OnMessage(frame => {
if (frame.Text == "request")
ws.Send("response");
});
});
Expand Down
52 changes: 26 additions & 26 deletions docs/src/api/class-websocketroute.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ await page.routeWebSocket('wss://example.com/ws', ws => {

```java
page.routeWebSocket("wss://example.com/ws", ws -> {
ws.onMessage(message -> {
if ("request".equals(message))
ws.onMessage(frame -> {
if ("request".equals(frame.text()))
ws.send("response");
});
});
Expand Down Expand Up @@ -47,8 +47,8 @@ page.route_web_socket("wss://example.com/ws", lambda ws: ws.on_message(

```csharp
await page.RouteWebSocketAsync("wss://example.com/ws", ws => {
ws.OnMessage(message => {
if (message == "request")
ws.OnMessage(frame => {
if (frame.Text == "request")
ws.Send("response");
});
});
Expand All @@ -70,8 +70,8 @@ await page.routeWebSocket('wss://example.com/ws', ws => {

```java
page.routeWebSocket("wss://example.com/ws", ws -> {
ws.onMessage(message -> {
JsonObject json = new JsonParser().parse(message).getAsJsonObject();
ws.onMessage(frame -> {
JsonObject json = new JsonParser().parse(frame.text()).getAsJsonObject();
if ("question".equals(json.get("request").getAsString())) {
Map<String, String> result = new HashMap();
result.put("response", "answer");
Expand Down Expand Up @@ -105,8 +105,8 @@ page.route_web_socket("wss://example.com/ws", lambda ws: ws.on_message(

```csharp
await page.RouteWebSocketAsync("wss://example.com/ws", ws => {
ws.OnMessage(message => {
using var jsonDoc = JsonDocument.Parse(message);
ws.OnMessage(frame => {
using var jsonDoc = JsonDocument.Parse(frame.Text);
JsonElement root = jsonDoc.RootElement;
if (root.TryGetProperty("request", out JsonElement requestElement) && requestElement.GetString() == "question")
{
Expand Down Expand Up @@ -140,11 +140,11 @@ await page.routeWebSocket('/ws', ws => {
```java
page.routeWebSocket("/ws", ws -> {
WebSocketRoute server = ws.connectToServer();
ws.onMessage(message -> {
if ("request".equals(message))
ws.onMessage(frame -> {
if ("request".equals(frame.text()))
server.send("request2");
else
server.send(message);
server.send(frame.text());
});
});
```
Expand Down Expand Up @@ -180,11 +180,11 @@ page.route_web_socket("/ws", handler)
```csharp
await page.RouteWebSocketAsync("/ws", ws => {
var server = ws.ConnectToServer();
ws.OnMessage(message => {
if (message == "request")
ws.OnMessage(frame => {
if (frame.Text == "request")
server.Send("request2");
else
server.Send(message);
server.Send(frame.Text);
});
});
```
Expand Down Expand Up @@ -215,13 +215,13 @@ await page.routeWebSocket('/ws', ws => {
```java
page.routeWebSocket("/ws", ws -> {
WebSocketRoute server = ws.connectToServer();
ws.onMessage(message -> {
if (!"blocked-from-the-page".equals(message))
server.send(message);
ws.onMessage(frame -> {
if (!"blocked-from-the-page".equals(frame.text()))
server.send(frame.text());
});
server.onMessage(message -> {
if (!"blocked-from-the-server".equals(message))
ws.send(message);
server.onMessage(frame -> {
if (!"blocked-from-the-server".equals(frame.text()))
ws.send(frame.text());
});
});
```
Expand Down Expand Up @@ -263,13 +263,13 @@ page.route_web_socket("/ws", handler)
```csharp
await page.RouteWebSocketAsync("/ws", ws => {
var server = ws.ConnectToServer();
ws.OnMessage(message => {
if (message != "blocked-from-the-page")
server.Send(message);
ws.OnMessage(frame => {
if (frame.Text != "blocked-from-the-page")
server.Send(frame.Text);
});
server.OnMessage(message => {
if (message != "blocked-from-the-server")
ws.Send(message);
server.OnMessage(frame => {
if (frame.Text != "blocked-from-the-server")
ws.Send(frame.Text);
});
});
```
Expand Down
20 changes: 10 additions & 10 deletions docs/src/mock.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ await page.routeWebSocket('wss://example.com/ws', ws => {

```java
page.routeWebSocket("wss://example.com/ws", ws -> {
ws.onMessage(message -> {
if ("request".equals(message))
ws.onMessage(frame -> {
if ("request".equals(frame.text()))
ws.send("response");
});
});
Expand Down Expand Up @@ -479,8 +479,8 @@ page.route_web_socket("wss://example.com/ws", lambda ws: ws.on_message(

```csharp
await page.RouteWebSocketAsync("wss://example.com/ws", ws => {
ws.OnMessage(message => {
if (message == "request")
ws.OnMessage(frame => {
if (frame.Text == "request")
ws.Send("response");
});
});
Expand All @@ -503,11 +503,11 @@ await page.routeWebSocket('wss://example.com/ws', ws => {
```java
page.routeWebSocket("wss://example.com/ws", ws -> {
WebSocketRoute server = ws.connectToServer();
ws.onMessage(message -> {
if ("request".equals(message))
ws.onMessage(frame -> {
if ("request".equals(frame.text()))
server.send("request2");
else
server.send(message);
server.send(frame.text());
});
});
```
Expand Down Expand Up @@ -543,11 +543,11 @@ page.route_web_socket("wss://example.com/ws", handler)
```csharp
await page.RouteWebSocketAsync("wss://example.com/ws", ws => {
var server = ws.ConnectToServer();
ws.OnMessage(message => {
if (message == "request")
ws.OnMessage(frame => {
if (frame.Text == "request")
server.Send("request2");
else
server.Send(message);
server.Send(frame.Text);
});
});
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/release-notes-csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ New methods [`method: Page.routeWebSocket`] and [`method: BrowserContext.routeWe

```csharp
await page.RouteWebSocketAsync("/ws", ws => {
ws.OnMessage(message => {
if (message == "request")
ws.OnMessage(frame => {
if (frame.Text == "request")
ws.Send("response");
});
});
Expand Down
4 changes: 2 additions & 2 deletions docs/src/release-notes-java.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ New methods [`method: Page.routeWebSocket`] and [`method: BrowserContext.routeWe

```java
page.routeWebSocket("/ws", ws -> {
ws.onMessage(message -> {
if ("request".equals(message))
ws.onMessage(frame -> {
if ("request".equals(frame.text()))
ws.send("response");
});
});
Expand Down

0 comments on commit 8e96d94

Please sign in to comment.