Skip to content

Commit 10929f4

Browse files
authored
Update experimental websocket onping/onpong examples (#1475)
1 parent 363d7fb commit 10929f4

File tree

8 files changed

+72
-43
lines changed

8 files changed

+72
-43
lines changed

docs/sources/next/javascript-api/k6-experimental/websockets/websocket/websocket-onping.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,24 @@ _A k6 script that initiates a WebSocket connection and sets up a handler for the
1919
import { WebSocket } from 'k6/experimental/websockets';
2020

2121
export default function () {
22-
const ws = new WebSocket('ws://localhost:10000');
22+
const ws = new WebSocket('wss://test-api.k6.io/ws/crocochat/publicRoom/');
2323

2424
ws.onping = () => {
2525
console.log('A ping happened!');
26+
ws.close();
2627
};
27-
}
28-
```
29-
30-
{{< /code >}}
3128

32-
The preceding example uses a WebSocket echo server, which you can run with the following command:
29+
ws.onclose = () => {
30+
console.log('WebSocket connection closed!');
31+
}
3332

34-
{{< code >}}
35-
36-
```bash
37-
$ docker run --detach --rm --name ws-echo-server -p 10000:8080 jmalloc/echo-server
33+
ws.onopen = () => {
34+
ws.send(JSON.stringify({ 'event': 'SET_NAME', 'new_name': `Croc ${__VU}` }));
35+
}
36+
ws.onerror = (err) => {
37+
console.log(err)
38+
}
39+
}
3840
```
3941

40-
{{< /code >}}
42+
{{< /code >}}

docs/sources/next/javascript-api/k6-experimental/websockets/websocket/websocket-onpong.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ export default function () {
2323

2424
ws.onpong = () => {
2525
console.log('A pong happened!');
26+
ws.close();
2627
};
28+
29+
ws.onopen = () => {
30+
ws.ping();
31+
}
2732
}
2833
```
2934

docs/sources/v0.47.x/javascript-api/k6-experimental/websockets/websocket/websocket-onping.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,24 @@ _A k6 script that initiates a WebSocket connection and sets up a handler for the
1919
import { WebSocket } from 'k6/experimental/websockets';
2020

2121
export default function () {
22-
const ws = new WebSocket('ws://localhost:10000');
22+
const ws = new WebSocket('wss://test-api.k6.io/ws/crocochat/publicRoom/');
2323

2424
ws.onping = () => {
2525
console.log('A ping happened!');
26+
ws.close();
2627
};
27-
}
28-
```
29-
30-
{{< /code >}}
3128

32-
The preceding example uses a WebSocket echo server, which you can run with the following command:
29+
ws.onclose = () => {
30+
console.log('WebSocket connection closed!');
31+
}
3332

34-
{{< code >}}
35-
36-
```bash
37-
$ docker run --detach --rm --name ws-echo-server -p 10000:8080 jmalloc/echo-server
33+
ws.onopen = () => {
34+
ws.send(JSON.stringify({ 'event': 'SET_NAME', 'new_name': `Croc ${__VU}` }));
35+
}
36+
ws.onerror = (err) => {
37+
console.log(err)
38+
}
39+
}
3840
```
3941

40-
{{< /code >}}
42+
{{< /code >}}

docs/sources/v0.47.x/javascript-api/k6-experimental/websockets/websocket/websocket-onpong.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ export default function () {
2323

2424
ws.onpong = () => {
2525
console.log('A pong happened!');
26+
ws.close();
2627
};
28+
29+
ws.onopen = () => {
30+
ws.ping();
31+
}
2732
}
2833
```
2934

docs/sources/v0.48.x/javascript-api/k6-experimental/websockets/websocket/websocket-onping.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,24 @@ _A k6 script that initiates a WebSocket connection and sets up a handler for the
1919
import { WebSocket } from 'k6/experimental/websockets';
2020

2121
export default function () {
22-
const ws = new WebSocket('ws://localhost:10000');
22+
const ws = new WebSocket('wss://test-api.k6.io/ws/crocochat/publicRoom/');
2323

2424
ws.onping = () => {
2525
console.log('A ping happened!');
26+
ws.close();
2627
};
27-
}
28-
```
29-
30-
{{< /code >}}
3128

32-
The preceding example uses a WebSocket echo server, which you can run with the following command:
29+
ws.onclose = () => {
30+
console.log('WebSocket connection closed!');
31+
}
3332

34-
{{< code >}}
35-
36-
```bash
37-
$ docker run --detach --rm --name ws-echo-server -p 10000:8080 jmalloc/echo-server
33+
ws.onopen = () => {
34+
ws.send(JSON.stringify({ 'event': 'SET_NAME', 'new_name': `Croc ${__VU}` }));
35+
}
36+
ws.onerror = (err) => {
37+
console.log(err)
38+
}
39+
}
3840
```
3941

40-
{{< /code >}}
42+
{{< /code >}}

docs/sources/v0.48.x/javascript-api/k6-experimental/websockets/websocket/websocket-onpong.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ export default function () {
2323

2424
ws.onpong = () => {
2525
console.log('A pong happened!');
26+
ws.close();
2627
};
28+
29+
ws.onopen = () => {
30+
ws.ping();
31+
}
2732
}
2833
```
2934

src/data/markdown/docs/02 javascript api/07 k6-experimental/05 websockets/10 WebSocket/30-WebSocket-onping.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,24 @@ _A k6 script that initiates a WebSocket connection and sets up a handler for the
1717
import { WebSocket } from 'k6/experimental/websockets';
1818

1919
export default function () {
20-
const ws = new WebSocket('ws://localhost:10000');
20+
const ws = new WebSocket('wss://test-api.k6.io/ws/crocochat/publicRoom/');
2121

2222
ws.onping = () => {
2323
console.log('A ping happened!');
24+
ws.close();
2425
};
25-
}
26-
```
27-
28-
</CodeGroup>
2926

30-
The preceding example uses a WebSocket echo server, which you can run with the following command:
27+
ws.onclose = () => {
28+
console.log('WebSocket connection closed!');
29+
}
3130

32-
<CodeGroup>
33-
34-
```bash
35-
$ docker run --detach --rm --name ws-echo-server -p 10000:8080 jmalloc/echo-server
31+
ws.onopen = () => {
32+
ws.send(JSON.stringify({ 'event': 'SET_NAME', 'new_name': `Croc ${__VU}` }));
33+
}
34+
ws.onerror = (err) => {
35+
console.log(err)
36+
}
37+
}
3638
```
39+
3740
</CodeGroup>

src/data/markdown/docs/02 javascript api/07 k6-experimental/05 websockets/10 WebSocket/30-WebSocket-onpong.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ export default function () {
2121

2222
ws.onpong = () => {
2323
console.log('A pong happened!');
24+
ws.close();
2425
};
26+
27+
ws.onopen = () => {
28+
ws.ping();
29+
}
2530
}
2631
```
2732

0 commit comments

Comments
 (0)