Skip to content
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Imports:
LinkingTo: cpp11, AsioHeaders, later
BugReports: https://github.com/rstudio/websocket/issues
SystemRequirements: C++11, GNU make, OpenSSL >= 1.0.2
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Suggests:
httpuv,
testthat,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# websocket (development version)

* Update examples from websocket.org to websocket.events. (@jonthegeek, #105)

# websocket 1.4.1

* Add UCRT toolchain support (@jeroen, #82)
Expand Down
4 changes: 2 additions & 2 deletions R/websocket.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ null_func <- function(...) { }
#' ## Only run this example in interactive R sessions
#' if (interactive()) {
#'
#' # Create a websocket using the websocket.org test server
#' ws <- WebSocket$new("ws://echo.websocket.org/")
#' # Create a websocket using the websocket.events test server
#' ws <- WebSocket$new("ws://echo.websocket.events/")
#' ws$onMessage(function(event) {
#' cat("Client got msg:", event$data, "\n")
#' })
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is an R WebSocket client library backed by the [websocketpp](https://github
```R
library(websocket)

ws <- WebSocket$new("ws://echo.websocket.org/", autoConnect = FALSE)
ws <- WebSocket$new("ws://echo.websocket.events/", autoConnect = FALSE)
ws$onOpen(function(event) {
cat("Connection opened\n")
})
Expand Down Expand Up @@ -47,7 +47,7 @@ ws$close()
Note that if you want to `send()` a message as soon as it connects, without having to wait at the console, you can put the `ws$send()` inside of the `ws$onOpen` callback, as in:

```R
ws <- WebSocket$new("wss://echo.websocket.org/")
ws <- WebSocket$new("wss://echo.websocket.events/")
ws$onMessage(function(event) {
cat("Client got msg: ", event$data, "\n")
})
Expand All @@ -64,7 +64,7 @@ ws$onOpen(function(event) {
The websocket (client) package can be used with a WebSocket server, implemented as a httpuv web application, to act as a WebSocket proxy. This proxy can be modified do things like log the traffic in each direction, or
modify messages sent in either direction.

The proxy will listen to port 5002 on the local machine, and connect to the remote machine at wss://echo.websocket.org:80. In this example, after starting the proxy, we'll connect to it with a WebSocket client in a separate R process, then send a message from that process. Here's what will happen in the proxy:
The proxy will listen to port 5002 on the local machine, and connect to the remote machine at wss://echo.websocket.events:80. In this example, after starting the proxy, we'll connect to it with a WebSocket client in a separate R process, then send a message from that process. Here's what will happen in the proxy:

* The client will send the message `"hello"`.
* The proxy will receive `"hello"` from the client, convert it to `"HELLO"`, then send it to the remote echo server.
Expand All @@ -80,7 +80,7 @@ library(httpuv)
library(websocket)

# URL of the remote websocket server
target_host <- "echo.websocket.org:80"
target_host <- "echo.websocket.events:80"
# Should be "ws" or "wss"
target_protocol <- "ws"

Expand Down
15 changes: 6 additions & 9 deletions tests/testthat/test-client.R
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,9 @@ test_that("WebSocket persists after reference is gone, and can be GC'd after con
expect_true(finalized)
})



# # Test is failing now that websocket.org is dead
# test_that("Basic ssl websocket communication", {
# # Don't want network connectivity issues on CRAN to cause package to be
# # rejected.
# skip_on_cran()
# check_ws("wss://echo.websocket.org/")
# })
test_that("Basic ssl websocket communication", {
# Don't want network connectivity issues on CRAN to cause package to be
# rejected.
skip_on_cran()
check_ws("wss://echo.websocket.events/")
})
10 changes: 5 additions & 5 deletions vignettes/overview.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ The I/O for a WebSocket happens on a separate thread from the main R thread; the
WebSockets are represented as instances of an [R6](https://github.com/r-lib/R6) object, and are created with `$new()`:

```{r, eval = FALSE}
ws <- WebSocket$new("ws://echo.websocket.org/")
ws <- WebSocket$new("ws://echo.websocket.events/")
```

By default, and similarly to how WebSockets in JavaScript work, constructing a WebSocket with `$new()` will automatically initiate the WebSocket connection. In normal usage, such as in a Shiny app or from within a function, this default behavior is ideal. When run interactively from the R console however, the default behavior is problematic. The reason is that the connection will open before the user is given an opportunity to register any event handlers, meaning messages from the server could be dropped.

So, in the console, WebSockets should be created like this:

```{r, eval = FALSE}
ws <- WebSocket$new("ws://echo.websocket.org/", autoConnect = FALSE)
ws <- WebSocket$new("ws://echo.websocket.events/", autoConnect = FALSE)
# Set up callbacks here...
ws$connect()
```
Expand All @@ -51,7 +51,7 @@ When running a block of code like this in a function, or surrounded with `{` and

```{r, eval = FALSE}
{
ws <- WebSocket$new("ws://echo.websocket.org/")
ws <- WebSocket$new("ws://echo.websocket.events/")
ws$onOpen(function(event) { message("websocket opened") })
}
```
Expand All @@ -75,7 +75,7 @@ For example, the following code instantiates a WebSocket, installs an `onOpen` h

```{r, eval = FALSE}
{
ws <- WebSocket$new("ws://echo.websocket.org/")
ws <- WebSocket$new("ws://echo.websocket.events/")
ws$onOpen(function(event) {
cat("connected\n")
})
Expand Down Expand Up @@ -108,7 +108,7 @@ The following is an example of an `$onMessage()` handler that immediately remove

```{r, eval = FALSE}
{
ws <- WebSocket$new("ws://echo.websocket.org/")
ws <- WebSocket$new("ws://echo.websocket.events/")
removeThis <- ws$onMessage(function(event) {
cat("this is the last time i'll run\n")
removeThis()
Expand Down