From 8e96d946aaa08d7afa1d9f4d5c8c502955a86d74 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 21 Oct 2024 21:21:30 +0200 Subject: [PATCH] cherry-pick(#33211): docs: use WebSocketFrame abstraction for Java & .NET --- docs/src/api/class-page.md | 8 ++--- docs/src/api/class-websocketroute.md | 52 ++++++++++++++-------------- docs/src/mock.md | 20 +++++------ docs/src/release-notes-csharp.md | 4 +-- docs/src/release-notes-java.md | 4 +-- 5 files changed, 44 insertions(+), 44 deletions(-) diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md index 60512f51ca70d..f0c8b34b09fc7 100644 --- a/docs/src/api/class-page.md +++ b/docs/src/api/class-page.md @@ -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"); }); }); @@ -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"); }); }); diff --git a/docs/src/api/class-websocketroute.md b/docs/src/api/class-websocketroute.md index b827db25dd6e7..e23316ebcbd07 100644 --- a/docs/src/api/class-websocketroute.md +++ b/docs/src/api/class-websocketroute.md @@ -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"); }); }); @@ -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"); }); }); @@ -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 result = new HashMap(); result.put("response", "answer"); @@ -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") { @@ -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()); }); }); ``` @@ -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); }); }); ``` @@ -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()); }); }); ``` @@ -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); }); }); ``` diff --git a/docs/src/mock.md b/docs/src/mock.md index a061efaff143e..6ecf6d4b5b2f8 100644 --- a/docs/src/mock.md +++ b/docs/src/mock.md @@ -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"); }); }); @@ -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"); }); }); @@ -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()); }); }); ``` @@ -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); }); }); ``` diff --git a/docs/src/release-notes-csharp.md b/docs/src/release-notes-csharp.md index fee7d732fec4b..130b9d4a7168c 100644 --- a/docs/src/release-notes-csharp.md +++ b/docs/src/release-notes-csharp.md @@ -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"); }); }); diff --git a/docs/src/release-notes-java.md b/docs/src/release-notes-java.md index ae9735861129c..c817a5a178423 100644 --- a/docs/src/release-notes-java.md +++ b/docs/src/release-notes-java.md @@ -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"); }); });