4 |
5 | New jrc page
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^CRAN-RELEASE$
2 | ^\.travis\.yml$
3 | Readme.md
4 | LICENSE
5 | test
6 | cran-comments.md
7 | ^.*\.Rproj$
8 | ^\.Rproj\.user$
9 | revdep
10 | ^CRAN-SUBMISSION$
11 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r
2 |
3 | language: R
4 | sudo: false
5 | cache: packages
6 | env:
7 | global:
8 | - _R_CHECK_DONTTEST_EXAMPLES_=FALSE
9 |
10 | matrix:
11 | include:
12 | - r: devel
13 | - r: release
14 | - r: oldrel
--------------------------------------------------------------------------------
/tests/testthat/test_sendHTML.R:
--------------------------------------------------------------------------------
1 | context("Sending HTML to web page")
2 |
3 | test_that("HTML can be added to the web page", {
4 | openPage(allowedVariables = "a")
5 |
6 | sendHTML('')
7 |
8 | sendCommand(paste0('document.getElementById("inp").click()'), wait = 3)
9 | expect_equal(a, "click")
10 |
11 | closePage()
12 | })
--------------------------------------------------------------------------------
/man/closePage.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{closePage}
4 | \alias{closePage}
5 | \title{Stop server}
6 | \usage{
7 | closePage()
8 | }
9 | \description{
10 | Stops the server and closes all currently opened pages (if any). This function is a
11 | wrapper of \code{stopServer} method of class \code{\link{App}}.
12 | }
13 | \seealso{
14 | \code{\link{openPage}}
15 | }
16 |
--------------------------------------------------------------------------------
/man/getSessionIds.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{getSessionIds}
4 | \alias{getSessionIds}
5 | \title{Get IDs of all active sessions}
6 | \usage{
7 | getSessionIds()
8 | }
9 | \value{
10 | Vector of session IDs.
11 | }
12 | \description{
13 | Returns IDs of all currently active sessions. An ID is a randomly generated combination of 6 letters and
14 | numbers that is assigned to each session upon opening. This function is a wrapper around method \code{getSessionIds}
15 | of class \code{\link{App}}.
16 | }
17 |
--------------------------------------------------------------------------------
/man/getSession.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{getSession}
4 | \alias{getSession}
5 | \title{Get a session}
6 | \usage{
7 | getSession(sessionId = NULL)
8 | }
9 | \arguments{
10 | \item{sessionId}{ID of the session. If there is only one active session, this argument becomes optional.}
11 | }
12 | \value{
13 | Object of class \code{\link{Session}}.
14 | }
15 | \description{
16 | Returns \code{\link{Session}} by its ID. This function is a wrapper around method
17 | \code{getSession} of class \code{\link{App}}.
18 | }
19 |
--------------------------------------------------------------------------------
/man/getPort.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{getPort}
4 | \alias{getPort}
5 | \title{Get number of the port on which the local server is running}
6 | \usage{
7 | getPort()
8 | }
9 | \description{
10 | This function returns port number for the running server. By default, a random available port is used. One can also
11 | set a port number as an argument of the \code{\link{openPage}} function. The port number can't be changed after the app
12 | was initialized.This function
13 | is a wrapper around method \code{getPort} of the class \code{\link{App}}.
14 | }
15 | \seealso{
16 | \code{\link{openPage}}
17 | }
18 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: jrc
2 | Type: Package
3 | Title: Exchange Commands Between R and 'JavaScript'
4 | Version: 0.6.0
5 | Date: 2023-08-22
6 | Authors@R: c(
7 | person("Svetlana", "Ovchinnikova", role = c("aut", "cre"), email = "s.ovchinnikova@zmbh.uni-heidelberg.de"),
8 | person("Simon", "Anders", role = c("aut"), email = "sanders@fs.tum.de")
9 | )
10 | Description: An 'httpuv' based bridge between R and 'JavaScript'. Provides an easy way to exchange commands and data between a web page and a currently running R session.
11 | License: GPL-3
12 | Imports: httpuv, jsonlite, utils, stringr, stringi, mime, R6, R.utils
13 | RoxygenNote: 7.2.3
14 | URL: https://github.com/anders-biostat/jrc
15 | BugReports: https://github.com/anders-biostat/jrc/issues
16 | Suggests:
17 | testthat
18 | Language: en-GB
19 |
--------------------------------------------------------------------------------
/man/removeMessage.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{removeMessage}
4 | \alias{removeMessage}
5 | \title{Removes a stored message}
6 | \usage{
7 | removeMessage(sessionId = NULL, messageId = NULL)
8 | }
9 | \arguments{
10 | \item{sessionId}{ID of the session from where to remove a message. If there is only one active session, this argument
11 | becomes optional.}
12 |
13 | \item{messageId}{ID of the message to remove. If there is only one stored message, this argument becomes optional.}
14 | }
15 | \description{
16 | Removes a message from the storage of a session. This function is a wrapper around
17 | method \code{removeMessage} of class \code{\link{Session}}.
18 | }
19 | \seealso{
20 | \code{\link{authorize}}, \code{\link{getMessageIds}}.
21 | }
22 |
--------------------------------------------------------------------------------
/man/getPage.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{getPage}
4 | \alias{getPage}
5 | \title{Get the currently running app}
6 | \usage{
7 | getPage()
8 | }
9 | \value{
10 | Object of class \code{\link{App}} or \code{NULL} if there is no active app.
11 | }
12 | \description{
13 | \code{jrc} offers two ways to control an interactive app. One is by using methods of classes
14 | \code{\link{App}} and \code{\link{Session}}. This allows one to have any number of apps within one
15 | R session, but requires some understanding of object oriented programming. Another way is to use
16 | provided wrapper functions that are exported by the package. These functions internally work with
17 | the \code{\link{App}} object, which is stored in the package namespace upon initialization with
18 | \code{\link{openPage}} function. \code{getPage} returns this object if any.
19 | }
20 |
--------------------------------------------------------------------------------
/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 | export(App)
4 | export(Session)
5 | export(allowDirectories)
6 | export(allowFunctions)
7 | export(allowVariables)
8 | export(authorize)
9 | export(callFunction)
10 | export(closePage)
11 | export(closeSession)
12 | export(getMessageIds)
13 | export(getPage)
14 | export(getPort)
15 | export(getSession)
16 | export(getSessionIds)
17 | export(getSessionVariable)
18 | export(listen)
19 | export(openPage)
20 | export(removeMessage)
21 | export(removeSessionVariables)
22 | export(sendCommand)
23 | export(sendData)
24 | export(sendHTML)
25 | export(setEnvironment)
26 | export(setLimits)
27 | export(setSessionVariables)
28 | import(R6)
29 | import(httpuv)
30 | import(mime)
31 | import(stringr)
32 | importFrom(R.utils,filePath)
33 | importFrom(httpuv,service)
34 | importFrom(jsonlite,fromJSON)
35 | importFrom(jsonlite,toJSON)
36 | importFrom(stringi,stri_rand_strings)
37 | importFrom(utils,browseURL)
38 | importFrom(utils,compareVersion)
39 | importFrom(utils,menu)
40 | importFrom(utils,object.size)
41 | importFrom(utils,packageVersion)
42 |
--------------------------------------------------------------------------------
/man/allowVariables.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{allowVariables}
4 | \alias{allowVariables}
5 | \title{Allow variable assignment without authorization}
6 | \usage{
7 | allowVariables(vars = NULL)
8 | }
9 | \arguments{
10 | \item{vars}{Vector of variable names to be added to the list. If \code{NULL},
11 | returns names of all currently allowed variables.}
12 | }
13 | \value{
14 | Names of all currently allowed variables if \code{vars = NULL}.
15 | }
16 | \description{
17 | This function adds variable names to the list of variables, that
18 | can be modified from a web page without manual confirmation on the R side.
19 | }
20 | \details{
21 | This function is a wrapper around \code{allowVariables} method of class \code{\link{App}}.
22 | }
23 | \examples{
24 | \dontrun{
25 | # to run this example an installed web browser is required
26 | openPage()
27 | allowVariables(c("myVariable", "anotherOne"))
28 | vars <- allowVariables()
29 | closePage()}
30 |
31 | }
32 | \seealso{
33 | \code{\link{allowFunctions}}, \code{\link{authorize}}, \code{\link{openPage}} (check argument
34 | \code{allowedVariables}), \code{\link{sendData}}.
35 | }
36 |
--------------------------------------------------------------------------------
/man/allowFunctions.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{allowFunctions}
4 | \alias{allowFunctions}
5 | \title{Allow function calls without authorization}
6 | \usage{
7 | allowFunctions(funs = NULL)
8 | }
9 | \arguments{
10 | \item{funs}{Vector of function names to be added to the list. If \code{NULL},
11 | returns names of all currently allowed R functions.}
12 | }
13 | \value{
14 | Names of all currently allowed functions if \code{funs = NULL}.
15 | }
16 | \description{
17 | Adds R function names to the list of functions, that
18 | can be called from a web page without manual confirmation on the R side.
19 | }
20 | \details{
21 | This function is a wrapper around \code{allowFunctions} method of class \code{\link{App}}.
22 | }
23 | \examples{
24 | \dontrun{
25 | # to run this example an installed web browser is required
26 | openPage()
27 | allowFunctions(c("myFunction1", "print", "someObject$method"))
28 | funs <- allowFunctions()
29 | closePage()}
30 |
31 | }
32 | \seealso{
33 | \code{\link{allowVariables}}, \code{\link{authorize}}, \code{\link{openPage}} (check argument
34 | \code{allowedFunctions}), \code{\link{callFunction}}.
35 | }
36 |
--------------------------------------------------------------------------------
/man/setEnvironment.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{setEnvironment}
4 | \alias{setEnvironment}
5 | \title{Set Environment}
6 | \usage{
7 | setEnvironment(envir)
8 | }
9 | \arguments{
10 | \item{envir}{Environment to be used as outer environment.}
11 | }
12 | \description{
13 | Defines the outer environment of the app. Outer environment is a parent for all session environments.
14 | It is used to store variables that are common for all the client sessions. The only way to make changes outside of
15 | the outer environment is to use the global assignment operator \code{<<-} if and only if changes are
16 | made to the variable that does not exist in the outer environment.
17 | }
18 | \details{
19 | By default, an environment where app was initialized (via \code{\link{openPage}} function or with \code{App$new()} call)
20 | is used.
21 |
22 | This function is a wrapper around \code{setEnvironment} method of class \code{\link{App}}.
23 | }
24 | \examples{
25 | \dontrun{
26 | # to run this example an installed web browser is required
27 | openPage()
28 | e <- new.env()
29 | setEnvironment(e)
30 |
31 | sendCommand("jrc.sendData('x', 10)", wait = 3)
32 | print(e$x)
33 | closePage()
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/man/getMessageIds.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{getMessageIds}
4 | \alias{getMessageIds}
5 | \title{Get IDs of all stored messages}
6 | \usage{
7 | getMessageIds(sessionId = NULL, simplify = TRUE)
8 | }
9 | \arguments{
10 | \item{sessionId}{ID of the session for which to return message IDs. Can also be a vector of multiple session IDs.
11 | If \code{NULL}, returns message IDs for all currently active sessions.}
12 |
13 | \item{simplify}{If \code{TRUE} and only one session ID is provided (or there is only one active session), returns
14 | a vector of message IDs. Otherwise returns a named list with one vector for each requested session.}
15 | }
16 | \value{
17 | Either a named list or a vector with message IDs.
18 | }
19 | \description{
20 | Returns IDs of all currently stored messages.
21 | }
22 | \details{
23 | For security reasons, most of the messages that are received
24 | from web pages require manual authorization in the R session with \code{\link{authorize}} function. Until that happens,
25 | messages are given randomly generated IDs and are stored in memory.
26 |
27 | This function is a wrapper around method \code{getMessageIds} of class \code{\link{Session}}.
28 | }
29 | \seealso{
30 | \code{\link{authorize}}, \code{\link{getSessionIds}}.
31 | }
32 |
--------------------------------------------------------------------------------
/man/listen.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{listen}
4 | \alias{listen}
5 | \title{Listen to the server}
6 | \usage{
7 | listen(time = Inf, activeSessions = NULL, condition = NULL)
8 | }
9 | \arguments{
10 | \item{time}{Time (in seconds), during which the R session should listen to the server. By default, the function runs until
11 | it is not interrupted (\code{time = Inf}).}
12 |
13 | \item{activeSessions}{The function runs, until there is at least one active session in the provided app. If there is only
14 | one active app, this argument can be set to \code{TRUE} for the same effect.}
15 |
16 | \item{condition}{Custom condition. This argument must be a function that returns \code{TRUE} or \code{FALSE}. R session will
17 | listen to the server, while the condition function returns \code{TRUE}.}
18 | }
19 | \description{
20 | When R session is not interactive, messages from the server are not processed automatically. In this case, one needs to
21 | keep this function running.
22 | This function, is a wrapper around \code{\link[later]{run_now}} or \code{\link[httpuv]{service}}. It runs
23 | the \code{\link[httpuv]{service}} in a loop with a specified condition.
24 | }
25 | \examples{
26 | \dontrun{
27 | # to run this example an installed web browser is required
28 | openPage()
29 | listen(time = 3)}
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/man/sendHTML.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{sendHTML}
4 | \alias{sendHTML}
5 | \title{Send HTML to a web page}
6 | \usage{
7 | sendHTML(html = "", sessionId = NULL, wait = 0)
8 | }
9 | \arguments{
10 | \item{html}{HTML code that will be added to the web page.}
11 |
12 | \item{sessionId}{An ID of the session to which the HTML should be sent. Can also be a vector of multiple session IDs.
13 | If \code{NULL}, the HTML will be sent to all currently active sessions.}
14 |
15 | \item{wait}{If \code{wait > 0}, after sending the message, R will wait for a reply for a given number of seconds.
16 | For this time (or until the reply is received), execution of other commands will be halted. Any incoming message
17 | from the session will be considered as a reply.}
18 | }
19 | \description{
20 | Sends a piece of HTML code to a web page and adds it at the end
21 | or the \code{body} element. This function is a wrapper around \code{sendHTML} method of
22 | class \code{\link{Session}}.
23 | }
24 | \examples{
25 | \dontrun{
26 | # to run this example an installed web browser is required
27 | openPage(FALSE)
28 |
29 | sendHTML("Test...")
30 | sendHTML("This is bold")
31 | sendHTML("
1
2
3
4
")}
32 |
33 | }
34 | \seealso{
35 | \code{\link{sendData}}, \code{\link{sendCommand}}, \code{\link{callFunction}},
36 | \code{\link{openPage}}.
37 | }
38 |
--------------------------------------------------------------------------------
/man/removeSessionVariables.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{removeSessionVariables}
4 | \alias{removeSessionVariables}
5 | \title{Remove variables from a client session environment}
6 | \usage{
7 | removeSessionVariables(varNames, sessionId = NULL)
8 | }
9 | \arguments{
10 | \item{varNames}{Names of variables to remove.}
11 |
12 | \item{sessionId}{ID of the session. If there is only one active session, this argument becomes optional.}
13 | }
14 | \description{
15 | This function removes variables from the environment of a client session. It allows, for instance, to unmask
16 | a variable with the same name from the outer app environment (see \code{\link{setEnvironment}}) for the session
17 | (check the example below). This function
18 | is a wrapper around method \code{sessionVariables} of the class \code{\link{Session}}.
19 | }
20 | \examples{
21 | \dontrun{
22 | # to run this example an installed web browser is required
23 | openPage(allowedVariables = "k", sessionVars = list(k = 10))
24 |
25 | k <- -1
26 | getPage()$openPage(FALSE)
27 | id1 <- getSessionIds()[1]
28 | id2 <- getSessionIds()[2]
29 | removeSessionVariables("k", id1)
30 | #this changes global 'k', since the variable is no longer masked
31 | sendCommand("jrc.sendData('k', 1)", sessionId = id1, wait = 3)
32 | #this doesn't affect global 'k'
33 | sendCommand("jrc.sendData('k', 5)", sessionId = id2, wait = 3)
34 | local_k <- getSessionVariable("k", id2)
35 |
36 | closePage()}
37 |
38 | }
39 | \seealso{
40 | \code{\link{setSessionVariables}}
41 | }
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/anders-biostat/jrc)
2 | [](https://cran.r-project.org/package=jrc)
3 | [](http://www.r-pkg.org/pkg/jrc)
4 |
5 | ## jrc
6 |
7 | An R package to exchange commands between R and JavaScript. It opens a new or an existing web page and establishes a WebSocket connection to the currently running R session.
8 |
9 | ## Installation
10 |
11 | ``` r
12 | install.packages("jrc")
13 | ```
14 |
15 | ## Usage
16 |
17 | Main R functions are `sendData()`, `sendCommand()`, `callFunction()`, and `sendHTML()`. The first one sends a variable
18 | from the R session to the web page, the second one executes a JavaScript code, the third one calls a JavaScript function (optionally, with the specified arguments), and the last one
19 | adds some HTML to the web page.
20 | Their JavaScript counterparts are `jrc.sendData()`, `jrc.callFunction()`, and `jrc.sendCommand()`.
21 |
22 | `openPage()` and `closePage()` respectively opens and closes a web page.
23 |
24 | This example opens a new page and adds there a button, that increases value of `k` by one in the
25 | R session.
26 |
27 | ``` r
28 | library(jrc)
29 |
30 | k <- 0
31 | openPage()
32 | sendCommand(paste0("button = document.createElement('input');",
33 | "button.type = 'button';",
34 | "button.addEventListener('click', function() {jrc.sendCommand('k <<- k + 1')});",
35 | "button.value = '+1';",
36 | "document.body.appendChild(button);", collapse = "\n"))
37 | ```
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/man/getSessionVariable.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{getSessionVariable}
4 | \alias{getSessionVariable}
5 | \title{Get a variable from a client session environment}
6 | \usage{
7 | getSessionVariable(varName, sessionId = NULL)
8 | }
9 | \arguments{
10 | \item{varName}{Name of the variable to search for. Must be a character.}
11 |
12 | \item{sessionId}{ID of the session. If there is only one active session, this argument becomes optional.}
13 | }
14 | \value{
15 | Requested variable
16 | }
17 | \description{
18 | This function returns a variable, how it is seen from a session, e.g. for all the received function calls and
19 | commands. It searches for the variable in the session environment first, and then, if variable is not found, checks enclosing
20 | frames of the environment, starting from the outer environment of the app (see \code{\link{setEnvironment}}). If the variable
21 | doesn't exist, throws an error.
22 | }
23 | \details{
24 | This function
25 | is a wrapper around method \code{sessionVariables} of the class \code{\link{Session}}.
26 | }
27 | \examples{
28 | \dontrun{
29 | # to run this example an installed web browser is required
30 | f <- function(x) {x * 3}
31 | openPage(allowedFunctions = "f", allowedVariables = "k", sessionVars = list(k = 0))
32 | k <- getSessionVariable("k")
33 | getPage()$openPage(FALSE)
34 | id1 <- getSessionIds()[1]
35 | id2 <- getSessionIds()[2]
36 | sendCommand("jrc.callFunction('f', [10], 'k')", sessionId = id1, wait = 3)
37 | sendCommand("jrc.callFunction('f', [20], 'k')", sessionId = id2, wait = 3)
38 | k1 <- getSessionVariable("k", id1)
39 | k2 <- getSessionVariable("k", id2)
40 |
41 | closePage()}
42 |
43 | }
44 | \seealso{
45 | \code{\link{setSessionVariables}}
46 | }
47 |
--------------------------------------------------------------------------------
/man/allowDirectories.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{allowDirectories}
4 | \alias{allowDirectories}
5 | \title{Allow server to access files in a directory}
6 | \usage{
7 | allowDirectories(dirs = NULL)
8 | }
9 | \arguments{
10 | \item{dirs}{Vector of paths to existing directories. Can be absolute paths, or paths relative to
11 | the current working directory. If the specified directory doesn't exist, it will be ignored and a
12 | warning will be produced. If \code{NULL}, returns absolute paths to all currently allowed directories.}
13 | }
14 | \value{
15 | Absolute paths to all currently allowed directories, if \code{dirs = NULL}.
16 | }
17 | \description{
18 | This function adds paths to existing directories to the list of allowed directories,
19 | which can be accessed from the server. To any request for files from outside
20 | of the allowed directories the server will response with \code{403 Forbidden} error.
21 | \code{rootDirectory} (see \code{\link{openPage}}) can always be accessed. By default,
22 | when the app is initialized, current working directory
23 | is added to the list of allowed directories. Further changes
24 | of the working directory will not have any affect on this list or files accessibility.
25 | }
26 | \details{
27 | This function is a wrapper around \code{allowDirectories} method of class \code{\link{App}}.
28 | }
29 | \examples{
30 | \dontrun{
31 | # to run this example an installed web browser is required
32 | openPage()
33 | # The directories must exist
34 | allowDirectories(c("~/directory1", "../anotherDirectory"))
35 | dirs <- allowDirectories()
36 | closePage()}
37 |
38 | }
39 | \seealso{
40 | \code{\link{openPage}} (check arguments \code{rootDirectory} and \code{allowedDirectories}).
41 | }
42 |
--------------------------------------------------------------------------------
/man/closeSession.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{closeSession}
4 | \alias{closeSession}
5 | \title{Close one or several client sessions}
6 | \usage{
7 | closeSession(sessionId = NULL, inactive = NULL, old = NULL)
8 | }
9 | \arguments{
10 | \item{sessionId}{IDs of the sessions to close. Can be a vector of multiple IDs.}
11 |
12 | \item{inactive}{All sessions that were inactive (didn't receive any messages) for the
13 | specified amount of time (in seconds) will be closed.}
14 |
15 | \item{old}{All sessions that were opened for at least specified amount of time (in seconds)
16 | will be closed.}
17 | }
18 | \description{
19 | Closes WebSocket connections for the selected client sessions and removes all the related
20 | information from memory. If no arguments are provided and there is only one active session,
21 | closes it. This function is a wrapper around method \code{closeSession} of
22 | class \code{\link{App}}.
23 | }
24 | \examples{
25 | \dontrun{
26 | # to run this example an installed web browser is required
27 | start <- Sys.time()
28 | openPage()
29 |
30 | app <- getPage()
31 | time <- Sys.time()
32 |
33 | app$openPage(FALSE)
34 | app$openPage(FALSE)
35 |
36 | print(getSessionIds())
37 |
38 | # No sessions will be closed
39 | closeSession(old = Sys.time() - start)
40 | print(getSessionIds())
41 |
42 | # One session (the one that has been opened first) will be closed
43 | closeSession(old = Sys.time() - time)
44 | print(getSessionIds())
45 |
46 | time <- Sys.time()
47 | sendCommand("jrc.sendCommand('print(\"Hi!\")')", sessionId = getSessionIds()[1], wait = 3)
48 |
49 | # this will close all sessions except for the one, that has just send a command to R session
50 | closeSession(inactive = Sys.time() - time)
51 |
52 | # if there is only one active session, sessionId becomes an optional argument
53 | closeSession()
54 |
55 | closePage()}
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/tests/testthat/test_sendCommand.R:
--------------------------------------------------------------------------------
1 | context("Send and receive commands")
2 |
3 | test_that("Commands can be send, received and stored", {
4 | app <- App$new()
5 | app$startServer()
6 |
7 | app$openPage()
8 |
9 | session <- app$getSession()
10 |
11 | session$sendCommand(paste0("jrc.sendCommand('message(\"Hi\")')"), wait = 3)
12 | expect_length(session$getMessageIds(), 1)
13 | session$sendCommand(paste0("jrc.sendCommand('message(\"Hi\")')"), wait = 3)
14 |
15 | messageIds <- session$getMessageIds()
16 | expect_length(messageIds, 2)
17 |
18 | expect_message(session$authorize(messageIds[1]), "Hi")
19 |
20 | expect_length(session$getMessageIds(), 1)
21 | session$removeMessage(messageIds[2])
22 | expect_length(session$getMessageIds(), 0)
23 |
24 | k_send <- sample(1000, 1)
25 | k_received <- -1
26 |
27 | session$sendCommand(paste0("jrc.sendCommand('k_received <<- ", k_send, "')"), wait = 3)
28 | session$authorize()
29 |
30 | expect_equal(k_received, k_send)
31 |
32 | expect_message(app$stopServer(), "Server has been stopped.")
33 | })
34 |
35 | test_that("Commands can be evaluated in the given environment", {
36 | app <- App$new()
37 | app$startServer()
38 |
39 | e <- new.env()
40 | app$setEnvironment(e)
41 |
42 | app$openPage()
43 |
44 | session <- app$getSession()
45 |
46 | e$k_send <- sample(1000, 1)
47 | e$k_received <- -1
48 |
49 | session$sendCommand(paste0("jrc.sendCommand('k_received <<- ", e$k_send, "')"), wait = 3)
50 | messageId <- session$getMessageIds()
51 | session$authorize(messageId)
52 |
53 | expect_equal(e$k_received, e$k_send)
54 |
55 | expect_message(app$stopServer(), "Server has been stopped.")
56 | })
57 |
58 | test_that("Wrapper function is working", {
59 | openPage()
60 |
61 | k_send <- sample(1000, 1)
62 | k_received <- -1
63 |
64 | sendCommand(paste0("jrc.sendCommand('k_received <<- ", k_send, "')"), wait = 3)
65 | session <- getSession()
66 | messageId <- getMessageIds()
67 |
68 | authorize(session$id, messageId)
69 |
70 | expect_equal(k_received, k_send)
71 |
72 | expect_message(closePage(), "Server has been stopped.")
73 | })
74 |
--------------------------------------------------------------------------------
/man/setSessionVariables.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{setSessionVariables}
4 | \alias{setSessionVariables}
5 | \title{Adds variables to a session environment}
6 | \usage{
7 | setSessionVariables(vars, sessionId = NULL, makeDefault = FALSE)
8 | }
9 | \arguments{
10 | \item{vars}{Named list of variables to be added to a session environment. Names are required and
11 | will be used as variable names.}
12 |
13 | \item{sessionId}{ID of the session to which variables should be added. Can also be a vector of
14 | multiple session IDs. If \code{NULL}, then variables will be added to all currently active sessions.}
15 |
16 | \item{makeDefault}{If \code{TRUE} then, in addition, the specified variables will be added to each
17 | new opened session as default ones.}
18 | }
19 | \description{
20 | Each client session in \code{jrc}, gets its own environment that can be accessed only by this
21 | session (or from the outside with the \code{\link{getSessionVariable}} function). General purpose
22 | of these environments is to store some session-specific information such as state of the app for
23 | each user. It can also be used to mask variables from the user: if there are two variables with the
24 | same name in the session environment and outside of it, user will not be able to see the latter one.
25 | This function adds new variables to a session environment or changes values of some existing ones.
26 | }
27 | \details{
28 | This function is a wrapper around method \code{sessionVariables} of class \code{\link{Session}}.
29 | If \code{makeDefault = TRUE}, it is also a wrapper around method \code{sessionVariables} of class
30 | \code{\link{App}}. The first one changes the current state of the session environment, while the
31 | second specifies default variables for each new session.
32 | }
33 | \examples{
34 | \dontrun{
35 | # to run this example an installed web browser is required
36 | openPage(allowedFunctions = "f", allowedVariables = "res")
37 |
38 | m <- 1
39 | f <- function() {v * m}
40 | setSessionVariables(list(v = 1:10, m = 2))
41 |
42 | sendCommand("jrc.callFunction('f', [], 'res')", wait = 1)
43 | print(res)
44 |
45 | closePage()}
46 |
47 | }
48 | \seealso{
49 | \code{\link{getSessionVariable}}.
50 | }
51 |
--------------------------------------------------------------------------------
/man/authorize.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{authorize}
4 | \alias{authorize}
5 | \title{Authorize further message processing}
6 | \usage{
7 | authorize(sessionId = NULL, messageId = NULL, show = FALSE)
8 | }
9 | \arguments{
10 | \item{sessionId}{ID of the session that received the message. If there is only one active session, this
11 | argument becomes optional.}
12 |
13 | \item{messageId}{ID of the message to be processed. If the session has only one stored message, this argument becomes
14 | optional.}
15 |
16 | \item{show}{If \code{TRUE} information about the message will be shown first. After that user gets
17 | a choice to go on with evaluation, to ignore the message (meaning it will be removed from memory) or to
18 | do nothing.}
19 | }
20 | \description{
21 | \code{jrc} library allows one to get full control over the currently running R session from
22 | a web page. Therefore for security reasons one should manually authorize function calls,
23 | variable assignments or expression evaluations. All the received messages that are not
24 | processed automatically are given an ID and stored. This function allows a message with the
25 | given ID to be evaluated. It can also show a short description of the message and give user
26 | a choice between running it or discarding.
27 | }
28 | \details{
29 | Expressions has to be always authorized before evaluation. One can specify a list of
30 | variables that can be changed automatically and functions that can be called without
31 | authorization.
32 |
33 | This function is a wrapper around \code{authorize} method of class \code{\link{Session}}.
34 | }
35 | \examples{
36 | \dontrun{
37 | # to run this example an installed web browser is required
38 | openPage()
39 |
40 | callFunction("jrc.sendCommand", list("k <<- 10"), wait = 1)
41 | allowVariables("x")
42 | callFunction("jrc.sendData", list("x", 15), wait = 1)
43 | callFunction("jrc.sendData", list("y", 20), wait = 1)
44 | msgId <- getMessageIds()
45 | authorize(messageId = msgId[1])
46 | #run that to first see some information about the message
47 | #authorize(messageId = msgId[2], show = TRUE)
48 |
49 | closePage()}
50 | }
51 | \seealso{
52 | \code{\link{allowFunctions}}, \code{\link{allowVariables}}, \code{\link{setLimits}}, \code{\link{getSessionIds}},
53 | \code{\link{getMessageIds}}.
54 | }
55 |
--------------------------------------------------------------------------------
/tests/testthat/test_multisession.R:
--------------------------------------------------------------------------------
1 | context("Handle multiple sessions")
2 |
3 | test_that("Messages from different sessions are properly stored and can be executed via the wrapper function", {
4 | app <- openPage()
5 |
6 | ses1 <- app$getSession()
7 | ses2 <- app$openPage(browser = "google-chrome")
8 | #ses2 <- app$openPage(browser = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")
9 |
10 |
11 | expect_length(app$getSessionIds(), 2)
12 |
13 | ses1$sendCommand("jrc.sendCommand('k <- 1')", wait = 1)
14 | ses1$sendCommand("jrc.sendCommand('k <- 2')", wait = 3)
15 | ids1 <- ses1$getMessageIds()
16 |
17 | ses2$sendCommand("jrc.sendCommand('k <- 3')", wait = 3)
18 | ids2 <- ses2$getMessageIds()
19 |
20 | expect_length(ids1, 2)
21 | expect_length(ids2, 1)
22 |
23 | authorize(ses1$id, ids1[1])
24 | authorize(ses2$id)
25 |
26 | expect_length(ses1$getMessageIds(), 1)
27 | expect_length(ses2$getMessageIds(), 0)
28 |
29 | app$stopServer()
30 | })
31 |
32 | test_that("Each session can store and use its own state", {
33 | app <- App$new()
34 | app$startServer()
35 |
36 | ses1 <- app$openPage()
37 | ses2 <- app$openPage(browser = "google-chrome")
38 | #ses2 <- app$openPage(browser = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")
39 |
40 | ses1$sendCommand("jrc.sendCommand('k <- 1')", wait = 3)
41 | ses1$authorize()
42 | ses2$sendCommand("jrc.sendCommand('k <- 2')", wait = 3)
43 | ses2$authorize()
44 |
45 | k1 <- ses1$sessionVariables(varName = "k")
46 | k2 <- ses2$sessionVariables(varName = "k")
47 |
48 | expect_equal(k1, 1)
49 | expect_equal(k2, 2)
50 |
51 | f <- function() {k * 3}
52 | app$allowFunctions("f")
53 | app$allowVariables("k")
54 |
55 | ses1$sendCommand("jrc.callFunction('f', [], 'k')", wait = 3)
56 | ses2$sendCommand("jrc.callFunction('f', [], 'k')", wait = 3)
57 |
58 | expect_false(exists("k", inherits = FALSE))
59 |
60 | k1 <- ses1$sessionVariables(varName = "k")
61 | k2 <- ses2$sessionVariables(varName = "k")
62 |
63 | expect_equal(k1, 3)
64 | expect_equal(k2, 6)
65 |
66 | app$stopServer()
67 | })
68 |
69 | test_that("One can specify default actions for each new page", {
70 | app <- openPage(onStart = function(session) {
71 | session$sendCommand(paste0("f = function() {jrc.sendData('k', '", session$id, "', false)}"))
72 | }, allowedVariables = "k")
73 | ses1 <- app$getSession()
74 |
75 | ses2 <- app$openPage(useViewer = F)
76 | ses3 <- app$openPage(F)
77 |
78 | k <- -1
79 |
80 | ses1$callFunction("f", wait = 3)
81 | expect_equal(k, ses1$id)
82 |
83 | ses2$callFunction("f", wait = 3)
84 | expect_equal(k, ses2$id)
85 |
86 | closePage()
87 | })
--------------------------------------------------------------------------------
/man/sendCommand.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{sendCommand}
4 | \alias{sendCommand}
5 | \title{Send a command to a web page}
6 | \usage{
7 | sendCommand(command, sessionId = NULL, wait = 0)
8 | }
9 | \arguments{
10 | \item{command}{A line (or several lines separated by \code{\\n}) of JavaScript code. This code
11 | will be directly evaluated on the web page. No R-side syntax check is performed.}
12 |
13 | \item{sessionId}{An ID of the session to which the command should be sent. Can also be a vector of multiple session IDs.
14 | If \code{NULL}, the command will be sent to all currently active sessions.}
15 |
16 | \item{wait}{If \code{wait > 0}, after sending the message, R will wait for a reply for a given number of seconds.
17 | For this time (or until the reply is received), execution of other commands will be halted. Any incoming message
18 | from the session will be considered as a reply.}
19 | }
20 | \description{
21 | \code{sendCommand} sends JavaScript code through the selected WebSocket connection and evaluates it on the specified
22 | web page. Use JavaScript function \code{jrc.sendCommand} to send R code from the web page
23 | and evaluate it in the current R session. All commands send to R from the server will be evaluated
24 | only after authorization in the currently running R session (see \code{\link{authorize}}).
25 | }
26 | \details{
27 | Each opened page gets its own environment, where all the commands are evaluated. Any changes
28 | made with the usual assignment operator \code{<-} will be limited to this page-specific environment. The changes
29 | are still saved, but can be accessed only with \code{\link{getSessionVariable}} function. To make changes outside
30 | of the page-specific environment use \code{<<-} instead.
31 |
32 | In JavaScript one should use \code{windows.varibleName = "SomeValue"}
33 | instead of \code{varibleName = "SomeValue"}, in order to make the variable accessible outside of the
34 | current \code{sendCommand} call.
35 |
36 | This function is a wrapper around \code{sendCommand} method of class \code{\link{Session}}.
37 | }
38 | \examples{
39 |
40 | \dontrun{
41 | # to run this example an installed web browser is required
42 | k <- 0
43 | openPage()
44 | sendCommand(paste0("button = document.createElement('input');",
45 | "button.type = 'button';",
46 | "button.addEventListener('click', function() {jrc.sendCommand('k <<- k + 1')});",
47 | "button.value = '+1';",
48 | "document.body.appendChild(button);", collapse = "\n"))
49 | closePage()}
50 |
51 | }
52 | \seealso{
53 | \code{\link{authorize}}, \code{\link{sendData}}, \code{\link{sendHTML}}, \code{\link{callFunction}},
54 | \code{\link{openPage}}, \code{\link{getSessionIds}}.
55 | }
56 |
--------------------------------------------------------------------------------
/tests/testthat/test_openAndClosePage.R:
--------------------------------------------------------------------------------
1 | context("Start server and open page")
2 |
3 | test_that("Pages can be opened in different browsers", {
4 | app <- App$new()
5 | app$startServer()
6 |
7 | app$openPage()
8 | expect_length(app$getSessionIds(), 1)
9 |
10 | app$openPage(browser = "google-chrome")
11 | #app$openPage(browser = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe")
12 | expect_length(app$getSessionIds(), 2)
13 |
14 | app$openPage(browser = "firefox")
15 | #app$openPage(browser = "C:\\Program Files\\Mozilla Firefox\\firefox.exe")
16 | expect_length(app$getSessionIds(), 3)
17 |
18 | app$openPage(useViewer = F)
19 | expect_length(app$getSessionIds(), 4)
20 |
21 | ids <- app$getSessionIds()
22 | expect_type(ids, "character")
23 |
24 | app$closeSession(ids[1:2])
25 | expect_length(app$getSessionIds(), 2)
26 |
27 | expect_warning(app$closeSession(ids[1]), "There is no session with ID")
28 |
29 | session <- app$getSession(ids[3])
30 | expect_true("Session" %in% class(session))
31 |
32 | app$closeSession(session$id)
33 | expect_length(app$getSessionIds(), 1)
34 |
35 | app$closeSession()
36 | expect_length(app$getSessionIds(), 0)
37 |
38 | expect_message(app$stopServer(), "Server has been stopped.")
39 | })
40 |
41 | test_that("Wrapper functions to open and close pages are working", {
42 | openPage()
43 | expect_length(getSessionIds(), 1)
44 | expect_message(closePage(), "Server has been stopped.")
45 | expect_message(closePage(), "There is no opened page.")
46 | })
47 |
48 | test_that("Port is freed after page is closed", {
49 | port <- httpuv::randomPort()
50 | app <- App$new()
51 | app$startServer(port = port)
52 | expect_error(app$startServer(port = port))
53 | expect_message(app$stopServer(), "Server has been stopped.")
54 | expect_silent(app$startServer(port = port))
55 | expect_message(app$stopServer(), "Server has been stopped.")
56 |
57 | openPage(port = port)
58 | expect_message(openPage(port = port), "Server has been stopped.")
59 | expect_message(closePage(), "Server has been stopped.")
60 | })
61 |
62 | test_that("Sessions can be closed according to there time stamps", {
63 | start <- Sys.time()
64 | openPage()
65 |
66 | app <- getPage()
67 | time <- Sys.time()
68 |
69 | app$openPage(F)
70 | app$openPage(F)
71 |
72 | expect_error(app$closeSession(), "There is more than one active session.")
73 |
74 | app$closeSession(old = Sys.time() - start)
75 | expect_length(app$getSessionIds(), 3)
76 |
77 | app$closeSession(old = Sys.time() - time)
78 | expect_length(app$getSessionIds(), 2)
79 |
80 | time <- Sys.time()
81 | session <- app$getSession(app$getSessionIds()[1])
82 | session$sendCommand("jrc.sendCommand('print(\"Hi!\")')", wait = 3)
83 |
84 | app$closeSession(inactive = Sys.time() - time)
85 | expect_length(app$getSessionIds(), 1)
86 |
87 | app$stopServer()
88 | })
--------------------------------------------------------------------------------
/tests/testthat/test_callFunction.R:
--------------------------------------------------------------------------------
1 | context("Call functions and assign their results to variables")
2 |
3 | test_that("Fucntions can be called on both sides", {
4 | openPage()
5 |
6 | k <- -1
7 | f <- function() k <<- 10
8 | sendCommand("jrc.callFunction('f')", wait = 3)
9 | authorize()
10 | expect_equal(k, 10)
11 |
12 | callFunction("Math.random", assignTo = "x")
13 | allowVariables("x")
14 | sendCommand("jrc.sendData('x', x)", wait = 3)
15 | expect_gte(x, 0)
16 | expect_lte(x, 1)
17 |
18 | expect_message(closePage(), "Server has been stopped.")
19 | })
20 |
21 | test_that("External variables are taken from the correct environment", {
22 | openPage()
23 |
24 | x <- 1
25 | y <- 0
26 | e <- new.env()
27 | e$x <- 10
28 |
29 | f <- function() x * 2
30 |
31 | allowFunctions("f")
32 | allowVariables("y")
33 | sendCommand("jrc.callFunction('f', undefined, 'y')", wait = 3)
34 | expect_equal(y, 2)
35 |
36 | setEnvironment(e)
37 | sendCommand("jrc.callFunction('f', undefined, 'y')", wait = 3)
38 | expect_equal(e$y, 20)
39 |
40 | setSessionVariables(list(x = 100))
41 | sendCommand("jrc.callFunction('f', undefined, 'y')", wait = 3)
42 | expect_equal(e$y, 200)
43 |
44 | expect_message(closePage(), "Server has been stopped.")
45 | })
46 |
47 | test_that("Function from a specified package can be called", {
48 | openPage()
49 | a <- ""
50 |
51 | allowFunctions("str_c")
52 | allowVariables("a")
53 | sendCommand("jrc.callFunction('str_c', ['abc', 'def'], 'a', 'stringr')", wait = 3)
54 | expect_equal(getSessionVariable("a"), "abcdef")
55 |
56 | expect_message(closePage(), "Server has been stopped.")
57 | })
58 |
59 | test_that("Methods of an object can be called", {
60 | Accum <- R6::R6Class("Accum", public = list(
61 | addone = function(){
62 | private$count <- private$count + 1
63 | },
64 | show = function() {
65 | private$count
66 | }
67 | ),
68 | private = list(
69 | count = 0
70 | ))
71 | obj <- Accum$new()
72 |
73 | openPage(allowedFunctions = c("obj$addone"))
74 | sendCommand("jrc.callFunction('obj$addone')", wait = 3)
75 |
76 | expect_equal(obj$show(), 1)
77 |
78 | closePage()
79 | })
80 |
81 | test_that("The correct 'this' object is used", {
82 | openPage(allowedVariables = "thisName")
83 | thisName <- "none"
84 |
85 | sendCommand("a = {name: 'a', b: {f: function() {jrc.sendData('thisName', this.name)}, c: {name: 'c'}, name: 'b'}}")
86 | callFunction("a.b.f", wait = 3)
87 | expect_equal(thisName, "b")
88 |
89 | callFunction("a.b.f", thisArg = "a.b.c", wait = 3)
90 | expect_equal(thisName, "c")
91 |
92 | sendData("name", "w")
93 | callFunction("a.b.f", thisArg = "window", wait = 3)
94 | expect_equal(thisName, "w")
95 |
96 | thisName <- "none"
97 |
98 | sendCommand("f2 = function() {jrc.sendData('thisName', this.name)}")
99 | callFunction("f2", wait = 3)
100 | expect_equal(thisName, "w")
101 |
102 | closePage()
103 | })
--------------------------------------------------------------------------------
/tests/testthat/test_limits.R:
--------------------------------------------------------------------------------
1 | context("Security limits")
2 |
3 | test_that("Number of active connection can be limited", {
4 | app <- openPage(connectionNumber = 2)
5 |
6 | app$openPage(FALSE)
7 | app$openPage(FALSE)
8 |
9 | expect_equal(length(app$getSessionIds()), 2)
10 |
11 | setLimits(maxCon = 3)
12 | app$openPage(FALSE)
13 | expect_equal(length(app$getSessionIds()), 3)
14 |
15 | closePage()
16 | })
17 |
18 | test_that("Storage size can be limited", {
19 | app <- openPage()
20 | ses <- app$getSession()
21 | ses$setLimits(list(storageSize = 200))
22 |
23 | sendCommand("jrc.sendCommand('print(\"xxx\")');", wait = 3)
24 |
25 | id <- ses$getMessageIds()
26 | expect_length(id, 1)
27 |
28 | sendCommand("jrc.sendCommand('print(\"xxx\")');", wait = 3)
29 |
30 | expect_length(ses$getMessageIds(), 1)
31 | expect_false(ses$getMessageIds() == id)
32 |
33 | ses$setLimits(list(storageSize = 400))
34 | sendCommand("jrc.sendCommand('print(\"xxx\")');", wait = 3)
35 |
36 | expect_length(ses$getMessageIds(), 2)
37 |
38 | closePage()
39 | })
40 |
41 | test_that("Number of stored messages can be limited", {
42 | app <- openPage()
43 | ses <- app$getSession()
44 |
45 | for(i in 1:3)
46 | sendCommand("jrc.sendCommand('print(\"xxx\")');", wait = 3)
47 |
48 | ses$setLimits(list(storedMsg = 2))
49 |
50 | sendCommand("jrc.sendCommand('print(\"xxx\")');", wait = 3)
51 | expect_length(ses$getMessageIds(), 3)
52 |
53 | ses$setLimits(list(storedMsg = 10))
54 | sendCommand("jrc.sendCommand('print(\"xxx\")');", wait = 3)
55 |
56 | expect_length(ses$getMessageIds(), 4)
57 |
58 | closePage()
59 | })
60 |
61 | test_that("Variable size can be limited", {
62 | x <- -1
63 | app <- openPage(allowedVariables = "x")
64 |
65 | setLimits(varSize = 70)
66 | ses <- app$openPage(FALSE)
67 |
68 | ses$sendCommand("jrc.sendData('x', [1, 1, 1]);", wait = 3)
69 | expect_length(x, 3)
70 |
71 | ses$sendCommand("jrc.sendData('x', [1, 1, 1, 1, 1]);", wait = 3)
72 | expect_length(x, 3)
73 |
74 | ses$setLimits(list(varSize = 100))
75 | ses$sendCommand("jrc.sendData('x', [1, 1, 1, 1, 1]);", wait = 3)
76 | expect_length(x, 5)
77 |
78 | closePage()
79 | })
80 |
81 | test_that("Number of received messages per second can be limited", {
82 | app <- openPage(allowedVariables = "x", useViewer = FALSE)
83 | ses <- app$getSession()
84 |
85 | x <- -1
86 |
87 | ses$setLimits(list(msgPerSec = 2))
88 | ses$sendCommand("i = 0; while(i < 4) {jrc.sendData('x', i); i++;}")
89 |
90 | t <- 0
91 | while(t < 2) {
92 | httpuv::service(0.1)
93 | t <- t + 0.1
94 | }
95 | expect_equal(x, 1)
96 |
97 | Sys.sleep(1)
98 | ses$setLimits(list(msgPerSec = 3))
99 | ses$sendCommand("j = 0; while(j < 10) {jrc.sendCommand('print(1)'); j++;}")
100 |
101 | t <- 0
102 | while(t < 2) {
103 | httpuv::service(0.1)
104 | t <- t + 0.1
105 | }
106 | expect_length(ses$getMessageIds(), 3)
107 |
108 | closePage()
109 | })
110 |
--------------------------------------------------------------------------------
/man/sendData.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{sendData}
4 | \alias{sendData}
5 | \title{Send data to a web page}
6 | \usage{
7 | sendData(
8 | variableName,
9 | variable,
10 | keepAsVector = FALSE,
11 | rowwise = TRUE,
12 | sessionId = NULL,
13 | wait = 0
14 | )
15 | }
16 | \arguments{
17 | \item{variableName}{Name that the variable will have on the web page.}
18 |
19 | \item{variable}{Variable to send.}
20 |
21 | \item{keepAsVector}{If \code{TRUE}, variables with length 1 will be saved as arrays on the web page, otherwise they
22 | will be converted to atomic types.}
23 |
24 | \item{rowwise}{If \code{TRUE}, matrices and data.frames will be transformed into JavaScript objects or arrays
25 | row wise (e.g. a matrix will become an Array of its rows).}
26 |
27 | \item{sessionId}{An ID of the session to which the data should be sent. Can also be a vector of multiple session IDs.
28 | If \code{NULL}, the data will be sent to all currently active sessions.}
29 |
30 | \item{wait}{If \code{wait > 0}, after sending the message, R will wait for a reply for a given number of seconds.
31 | For this time (or until the reply is received), execution of other commands will be halted. Any incoming message
32 | from the session will be considered as a reply.}
33 | }
34 | \description{
35 | Sends a variable to a web page, where it is saved under a specified name. This function
36 | is a wrapper around \code{sendData} method of class \code{\link{Session}}.
37 | }
38 | \details{
39 | To send data back from the web page to the current R session one should use\code{jrc.sendData(variableName, variable, internal)}.
40 | Its arguments are:
41 |
42 | \describe{
43 | \item{\code{variableName}}{
44 | Name that the variable will have in the R session. If variable name hasn't been previously added to the list
45 | of allowed variables (see \code{\link{allowVariables}} or \code{allowedVariables} argument of the \code{\link{openPage}}
46 | function), attempt to assign it from a web page will require manual authorization on the R side.
47 | }
48 | \item{\code{variable}}{
49 | Variable to send.
50 | }
51 | \item{\code{internal} (optional)}{
52 | Whether this variable should be used only by the session that sent it. If \code{true}, variable will be stored
53 | in the session-specific environment and can be accessed from the outside with \code{\link{getSessionVariable}}
54 | function. If \code{false}, variable will be saved to the outer environment of the app (see \code{\link{setEnvironment}}).
55 | By default, uses \code{true} for variables that already exist in the session specific environment
56 | (see \code{\link{setSessionVariables}} or \code{sessionVariables} argument of the \code{\link{openPage}} function.)
57 | and \code{false} otherwise.
58 | }
59 | }
60 | }
61 | \examples{
62 | \dontrun{
63 | # to run this example an installed web browser is required
64 | openPage()
65 | x <- 1:100
66 | sendData("x", x)
67 | sendCommand("console.log(x);")
68 | sendCommand("jrc.sendData('x', x.filter(function(e) {return e \% 2 == 0}))")
69 | closePage()}
70 |
71 | }
72 | \seealso{
73 | \code{\link{authorize}}, \code{\link{allowVariables}}, \code{\link{sendCommand}},
74 | \code{\link{callFunction}}, \code{\link{sendHTML}}, \code{\link{openPage}}, \code{\link{getSessionIds}}.
75 | }
76 |
--------------------------------------------------------------------------------
/tests/testthat/test_directoryAccess.R:
--------------------------------------------------------------------------------
1 | context("Access only allowed directories")
2 |
3 | test_that("Files inside default working directories can be accessed", {
4 | app <- openPage(allowedVariables = "loaded", useViewer = F)
5 |
6 | loaded <- -1
7 | #root directory
8 | sendCommand(str_c("var myScript = document.createElement('script');",
9 | "myScript.src = 'test.js';",
10 | "myScript.onload = function(){",
11 | "jrc.sendData('loaded', 1);",
12 | "};",
13 | "document.head.appendChild(myScript);"), wait = 3)
14 | expect_equal(loaded, 1)
15 |
16 | sendCommand(str_c("var client = new XMLHttpRequest();",
17 | "client.open('GET', 'test_directoryAccess.R');",
18 | "client.onreadystatechange = function() {",
19 | "if(client.responseText.substr(0, 7) == 'context')",
20 | "jrc.sendData('loaded', 2);",
21 | "};",
22 | "client.send();"), wait = 3)
23 | expect_equal(loaded, 2)
24 | closePage()
25 | })
26 |
27 | test_that("Files outside working directories can't be accessed", {
28 | openPage(allowedVariables = "status")
29 |
30 | status <- -1
31 | sendCommand(str_c("var client = new XMLHttpRequest();",
32 | "client.open('GET', '../test.R');",
33 | "client.onreadystatechange = function() {",
34 | "if(client.response)",
35 | "jrc.sendData('status', client.status);",
36 | "};",
37 | "client.send();"), wait = 3)
38 | expect_equal(status, 404)
39 |
40 | closePage()
41 |
42 | openPage(allowedDirectories = NULL, allowedVariables = "status")
43 | sendCommand(str_c("var client = new XMLHttpRequest();",
44 | "client.open('GET', 'test_directoryAccess.R');",
45 | "client.onreadystatechange = function() {",
46 | "if(client.response)",
47 | "jrc.sendData('status', client.status)",
48 | "};",
49 | "client.send();"), wait = 3)
50 | expect_equal(status, 403)
51 | closePage()
52 | })
53 |
54 | test_that("Directories can be added to the list of allowed directories", {
55 | openPage(allowedVariables = "loaded", allowedDirectories = NULL)
56 |
57 | allowDirectories(getwd())
58 |
59 | loaded <- -1
60 | sendCommand(str_c("var client = new XMLHttpRequest();",
61 | "client.open('GET', 'test_directoryAccess.R');",
62 | "client.onreadystatechange = function() {",
63 | "if(client.responseText.substr(0, 7) == 'context')",
64 | "jrc.sendData('loaded', 1);",
65 | "};",
66 | "client.send();"), wait = 3)
67 | expect_equal(loaded, 1)
68 |
69 | closePage()
70 |
71 |
72 | openPage(allowedVariables = "loaded")
73 |
74 | png(str_c(tempdir(), .Platform$file.sep, "testImage.png"))
75 | plot(1:10, 1:10)
76 | dev.off()
77 |
78 | allowDirectories(tempdir())
79 |
80 | sendCommand(str_c("var myImage = document.createElement('img');",
81 | "myImage.src = 'testImage.png';",
82 | "myImage.onload = function() {",
83 | "jrc.sendData('loaded', 2);",
84 | "};",
85 | "document.body.appendChild(myImage);"), wait = 3)
86 | expect_equal(loaded, 2)
87 |
88 | closePage()
89 |
90 | })
--------------------------------------------------------------------------------
/man/setLimits.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{setLimits}
4 | \alias{setLimits}
5 | \title{Set security limits}
6 | \usage{
7 | setLimits(
8 | maxCon = NULL,
9 | storageSize = NULL,
10 | storedMsg = NULL,
11 | varSize = NULL,
12 | msgPerSec = NULL,
13 | msgSize = NULL,
14 | bytesPerSec = NULL
15 | )
16 | }
17 | \arguments{
18 | \item{maxCon}{Maximal allowed number of web socket connections simultaneously. A new
19 | connection is established whenever someone requests an HTML page from the server
20 | or when the \code{openPage} method of class \code{\link{App}} is used. If number of
21 | the allowed connections is reached the newly opened web socked will be immediately
22 | closed and the user will see a warning.}
23 |
24 | \item{storageSize}{Maximal total size of all stored messages in bytes.}
25 |
26 | \item{storedMsg}{Maximal number of messages that can be stored simultaneously.}
27 |
28 | \item{varSize}{Maximal size of a variable that can be received from a web page.
29 | Attempt to assign data of larger size to a variable will be ignored.}
30 |
31 | \item{msgPerSec}{Maximal number of messages that can be received per second.
32 | All extra messages will be disposed of immediately without any attempt to
33 | process their content.}
34 |
35 | \item{msgSize}{Maximal allowed size of a message in bytes. Note, that here a
36 | size of character string that contains all the received information is estimated.
37 | All larger messages will be ignored.}
38 |
39 | \item{bytesPerSec}{Number of bytes that can be received per second. After the
40 | limit is reached, all the incoming messages will be ignored.}
41 | }
42 | \description{
43 | This function allows to control memory usage and limit number of messages processed per
44 | second or simultaneously active connections to the app.
45 |
46 | If an app is deployed on a server and is publicly available, it may be useful to limit
47 | resources that are available to each user. There are various things that can be
48 | controlled by this function: storage size and number of stored messages,
49 | maximal variable size, number of messages processed per second and bytes received
50 | per second.
51 |
52 | Messages are all the communication received via web socket from an opened web page.
53 | Each message contains a command that is to be evaluated in the R session, name
54 | of a function to call or variable to store. If number or size of messages exceeds
55 | the preset limit, they are completely ignored by the app.
56 | }
57 | \details{
58 | For security reasons, some messages has to be first authorized by the
59 | \code{\link{authorize}} function, before they can be processed. Such messages
60 | are saved until they are manually removed or authorized. If number or total
61 | size of the stored messages exceeds the limits, new messages are still saved,
62 | but the older ones are removed from the memory. If storage size is set to zero
63 | no messages can be stored and every message that requires authorization will
64 | be automatically discarded.
65 |
66 | Size of variables or messages is estimated in \code{\link[utils]{object.size}}
67 | and is always measured in byte.
68 |
69 | The limits are set for the entire app and are applied for each new connection.
70 | One can also change security limits for any connection separately by using
71 | method \code{setLimits} of a corresponding object of class \code{\link{Session}}.
72 |
73 | This function is a wrapper for method \code{setLimits} of class \code{\link{App}}.
74 | }
75 | \examples{
76 | \dontrun{
77 | # to run this example an installed web browser is required
78 | openPage()
79 | setLimits(maxCon = 10)
80 | setLimits(varSize = 10 * 1024^2)
81 | closePage()}
82 |
83 | }
84 | \seealso{
85 | \code{\link{authorize}}, \code{\link{allowFunctions}}, \code{\link{allowVariables}}.
86 | }
87 |
--------------------------------------------------------------------------------
/NEWS.md:
--------------------------------------------------------------------------------
1 | # jrc 0.6.0
2 |
3 | * `listen` function (a wrapper around `httpuv::service` or `later::run_now`) added to for more convenient use of JRC apps in Jupyter Notebooks.
4 |
5 | # jrc 0.5.1
6 |
7 | * `onlyServer` argument is added to the `openPage` function to prevent opening a browser tab.
8 |
9 | * Bug in the `thisArg` argument of the `callFunction` function is fixed.
10 |
11 |
12 | # jrc 0.5.0
13 |
14 | * `setLimits` now used to set any kind of restriction to memory usage. It replaces `numberOfConnections` and `limitStorage`. Now, also number of processed messages per second or the amount of processed information can be limited, so that the app will not get stuck after receiving too many messages.
15 |
16 | * `onClose` callback added to the `openPage` function. It allows to specify actions to be taken when a WebSocket connection is closed (user closes the page).
17 |
18 | * `getPort` added as a function and as a method of class `App` to query for a port number of the running app.
19 |
20 | * `sendData` now handles the NAs properly.
21 |
22 | * Issue with failing to establish a WebSocket connection to a complex address fixed.
23 |
24 | # jrc 0.4.0
25 |
26 | * `allowedDirectories` argument is added to the `openPage` function (and also the corresponding function and method `allowDirectories`).
27 | Now user can specify the list of directories that can be accessed by server. By default, it's the `rootDirectory`, the current working
28 | directory and a temporary directory for the current R session.
29 |
30 | * Issue with incorrect serving of the file types that are supposed to be send as bytes fixed.
31 |
32 | * `jrc` now imports `R.utils` for more robust paths handling.
33 |
34 | # jrc 0.3.1
35 |
36 | * Issue with file separator in Windows fixed.
37 |
38 | * Now app is stored in packages namespace immediately after initialization. This fixes a problem with wrapper functions inside `onStart`.
39 |
40 | # jrc 0.3.0
41 |
42 | * `jrc` now supports multiple connections to a single server and thus can be used to create server apps that are intended
43 | to be used by multiple clients simultaneously. This change requires some additional arguments in some of the functions as well
44 | as several new ones. However, backwards compatibility is maintained.
45 |
46 | * `jrc` now depends on `R6` and each app is represented with a single object. One can manage the app with methods of this object,
47 | which allows to run several apps inside one R session. For more information, check man pages of classes `App` and `Session`.
48 |
49 | # jrc 0.2.1
50 |
51 | * `jrc` now works properly on RStudio Server
52 |
53 | * `sendData` no longer crashes when `keepAsVector = FALSE` and some NAs are present.
54 |
55 | * `jrc` now works with `httpuv < 1.5.2` (it no longer depends on `httpuv::randomPort()`).
56 |
57 | * `jrc` now imports `mime` for defining content type when serving a page.
58 |
59 |
60 | # jrc 0.2.0
61 |
62 | * Now most of the request from the server must be manually authorized in the R session to prevent misuse of publicly available
63 | apps based on jrc. Functions `authorize`, `allowVariables`, `allowFunctions`, `limitStorage` have been added. Check their man
64 | pages for more information.
65 |
66 | * `openPage` now have `browser` argument, which allows to specify a browser to open a page (previously the default browser was
67 | used with no alternatives).
68 |
69 | * Function `getPage` is added. This function returns the main page-handling object with all the information about current session.
70 |
71 | * Function `callFunction` added on both R and JavaScript sides. It allows to call a function by name, list of arguments and name
72 | of variable to which assign the result.
73 |
74 | * Now port for the local server is selected by `httpuv::randomPort()` function. User can also provide a port number as an
75 | argument to the `openPage` function.
76 |
77 | * `sendData` now has argument `rowwise` which allows to send matrices and data.frames to JavaScript not only rowwise (default),
78 | but also columnwise.
79 |
80 | * If in `sendData` `keepAsVector = FALSE` `jrc` now checks recursively for any arrays of length 1 to replace them with scalars
81 | (important for lists).
82 |
83 | * Some bugs with changing variable types in `jrc.sendData` fixed.
--------------------------------------------------------------------------------
/man/Session.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{Session}
4 | \alias{Session}
5 | \title{Session class}
6 | \description{
7 | Objects of this class handle all the incoming and outgoing messages for one active connection.
8 | Please, avoid creating instances of this class manually. Each \code{Session} object is created when
9 | a WebSocket is opened and serves as a wrapper around it. A manually created object will not have
10 | a WebSocket connection and thus are not functional.
11 |
12 | All sessions are stored within an object of class \code{\link{App}} and cannot exist and function without it.
13 | One can manipulate a session directly, using its methods described below, via methods of the corresponding
14 | \code{\link{App}} object or the provided wrapper function (links to them can be found in the Methods section).
15 | }
16 | \section{Fields}{
17 |
18 | \describe{
19 | \item{\code{id}}{
20 | Automatically generated ID for this session. ID is a random combination of 6 letters or numbers.
21 | Please, do not change the value of this field.
22 | }
23 | \item{\code{lastActive}}{
24 | Time of the last received message from the session's WebSocket. The timestamp is generated by the
25 | \code{\link[base]{Sys.time}} function.
26 | }
27 | \item{\code{startTime}}{
28 | Time when this session has been started (generated by the \code{\link[base]{Sys.time}} function).
29 | }
30 | }
31 | }
32 |
33 | \section{Methods}{
34 |
35 | \describe{
36 | \item{\code{getMessageIds()}}{
37 | Returns IDs of all currently stored messages. ID is a combination of 6 random letters and numbers
38 | generated when the message is stored. See also \code{\link{getMessageIds}}.
39 | }
40 | \item{\code{authorize(messageId = NULL, show = FALSE)}}{
41 | Authorizes evaluation of a message. Check \code{\link{authorize}} for more information.
42 | }
43 | \item{\code{removeMessage(messageId = NULL)}}{
44 | Removes a stored message. This can also be done with the \code{\link{authorize}} function (set
45 | \code{show = TRUE} and then select the ``Ignore message'' option). See also \code{\link{removeMessage}}.
46 | }
47 | \item{\code{sendCommand(command, wait = 0)}}{
48 | Sends a JavaScript command to be evaluated on the web page. Check
49 | \code{\link{sendCommand}} for more information.
50 | }
51 | \item{\code{callFunction(name, arguments = NULL, assignTo = NULL, wait = 0, thisArg = NULL, ...)}}{
52 | Calls an existing JavaScript
53 | function on the web page. Check \code{\link{callFunction}} for more information.
54 | }
55 | \item{\code{sendData(variableName, variable, wait = 0, keepAsVector = FALSE, rowwise = TRUE)}}{
56 | Sends data and assigns it to
57 | a variable on the web page. Check \code{\link{sendData}} for more information.
58 | }
59 | \item{\code{sendHTML(html, wait = 0)}}{
60 | Sends HTML code that will be appended to the web page. Check \code{\link{sendHTML}} for
61 | more information.
62 | }
63 | \item{\code{sessionVariables(vars = NULL, varName = NULL, remove = NULL)}}{
64 | Sets or returns variables that are used (read or modified) only by this session. If both arguments are
65 | \code{NULL}, returns environment for this session. If \code{vars} is a named list, adds this variables to the
66 | session environment. If \code{varName} is a character, returns a variable with this name how it is seen from
67 | the session. If the variable doesn't exist, throws an error. If \code{remove} is a vector of characters, removes
68 | variables with these names from the session environment. One can add variables to the session environment,
69 | get one back and remove variables with a single function call. Check \code{\link{setSessionVariables}},
70 | \code{\link{getSessionVariable}}, \code{\link{removeSessionVariables}} for more information.
71 | }
72 | \item{\code{setLimits(limits)}}{
73 | Sets limits for memory usage, number of simultaneously active connections and amount of messages processed per second.
74 | For information about possible arguments, please, check \code{\link{setLimits}}. This method accepts all the same arguments,
75 | but they should be supplied in a form of list.
76 | }
77 | }
78 | Note, that \code{Session} class has some other public methods that are not mentioned in this list. These methods are
79 | intended to be used only by other functions of \code{jrc} package and therefore are not documented.
80 | }
81 |
82 |
--------------------------------------------------------------------------------
/man/callFunction.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{callFunction}
4 | \alias{callFunction}
5 | \title{Trigger a function call}
6 | \usage{
7 | callFunction(
8 | name,
9 | arguments = NULL,
10 | assignTo = NULL,
11 | wait = 0,
12 | sessionId = NULL,
13 | thisArg = NULL,
14 | ...
15 | )
16 | }
17 | \arguments{
18 | \item{name}{Name of the function. If the function is a method of some object
19 | its name must contain the full chain of calls (e.g. \code{myArray.sort} or
20 | \code{Math.rand}).}
21 |
22 | \item{arguments}{List of arguments for the function. Note that in JavaScript
23 | arguments must be given in a fixed order, naming is not necessary and will
24 | be ignored.}
25 |
26 | \item{assignTo}{Name of a variable to which will be assigned the returned value
27 | of the called function.}
28 |
29 | \item{wait}{If \code{wait > 0}, after sending the message, R will wait for a reply for a given number of seconds.
30 | For this time (or until the reply is received), execution of other commands will be halted. Any incoming message
31 | from the session will be considered as a reply.}
32 |
33 | \item{sessionId}{An ID of the session to which the function call should be sent. Can also be a vector of multiple
34 | session IDs. If \code{NULL}, the function call will be sent to all currently active sessions.}
35 |
36 | \item{thisArg}{JavaScript functions (methods) can belong to some object, which
37 | is referred to as \code{this} inside the function (e.g. in
38 | \code{someObject.myFunction()} function \code{myFunction} is a method of \code{someObject}).
39 | \code{thisArg} specifies object that will be known as \code{this} inside the function. If \code{NULL},
40 | the function will use its parent as \code{this} object (as it happens in JavaScript by default).}
41 |
42 | \item{...}{further arguments passed to \code{\link{sendData}}. It is used to send
43 | \code{arguments} to the web page.}
44 | }
45 | \description{
46 | Calls a function in a web page by its name. It can also pass a list of arguments for the function and
47 | save the returned result to a variable.
48 | }
49 | \details{
50 | JavaScript counterpart is \code{jrc.callFunction(name, arguments, assignTo, package, internal)}.
51 | Its arguments are:
52 | \describe{
53 | \item{\code{name}}{
54 | Name of an R function. If function name hasn't been previously added to the list
55 | of allowed functions (see \code{\link{allowFunctions}} or \code{allowedFunctions} argument of \code{\link{openPage}}),
56 | attempt to call it from a web page will require manual authorization on the R side.
57 | }
58 | \item{\code{arguments} (optional)}{
59 | arguments for the function. This should be an Array (for unnamed arguments) or an Object with argument names as keys
60 | (for named arguments).
61 | }
62 | \item{\code{assignTo} (optional)}{
63 | Name of the variable to which the returned value of the function will be assigned in the R session.
64 | If the variable name hasn't been previously added to the list
65 | of allowed variables (see \code{\link{allowVariables}} or \code{allowedVariables} argument of \code{\link{openPage}}),
66 | attempt to assign it from a web page will require manual authorization on the R side.
67 | }
68 | \item{\code{package} (optional)}{
69 | If the function needs to be imported from an installed package, name of this package.
70 | }
71 | \item{\code{internal} (optional)}{
72 | Whether assignment of the function returned value should happen internally or not. If \code{true}, result will be stored
73 | in the session environment and can be accessed from the outside with \code{\link{getSessionVariable}}
74 | function. If \code{false}, result will be saved to the outer environment of the app (see \code{\link{setEnvironment}}).
75 | By default, uses \code{true} for variables that already exist in the session environment
76 | (see \code{\link{setSessionVariables}} or \code{sessionVariables} argument of the \code{\link{openPage}} function)
77 | and \code{false} otherwise.
78 | }
79 | }
80 |
81 | This function is a wrapper
82 | around \code{callFunction} method of class \code{\link{Session}}.
83 | }
84 | \examples{
85 | \dontrun{
86 | # to run this example an installed web browser is required
87 | openPage()
88 | callFunction("alert", list("Some alertText"))
89 | callFunction("Math.random", assignTo = "randomNumber")
90 | sendCommand("alert(randomNumber)")
91 | closePage()
92 | }
93 |
94 | }
95 | \seealso{
96 | \code{\link{authorize}}, \code{\link{allowFunctions}}, \code{\link{allowVariables}},
97 | \code{\link{setEnvironment}}, \code{\link{getSessionIds}}.
98 | }
99 |
--------------------------------------------------------------------------------
/man/App.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{App}
4 | \alias{App}
5 | \title{App class}
6 | \description{
7 | Object of this class represents the entire jrc-based app. It stores all the active connections,
8 | client-specific variables and all the global app settings.
9 |
10 | You can create interactive apps by initializing
11 | new instances of this class and manage the apps with the methods that are described below. There are no limitations
12 | on the number of apps that can run simultaneously in one R session.
13 |
14 | A wrapper function is also exported for almost each method (see links in the Methods section). This functions allow
15 | you to gain full control over the app without ever dealing with this class. However, in this case only a single app
16 | can run per R session. Attempt to create a new app (with \code{\link{openPage}} function) will force the existing one (if any)
17 | to stop. You can always get the \code{App} object for the currently running app with \code{\link{getPage}} function.
18 | }
19 | \section{Methods}{
20 |
21 | \describe{
22 | \item{\code{new(rootDirectory = NULL, startPage = NULL, onStart = NULL, onClose = NULL,
23 | connectionNumber = Inf, allowedFunctions = c(), allowedVariables = c(), sessionVars = NULL)}}{
24 | Creates a new instance of class \code{App}. Check \code{\link{openPage}} man page for information about
25 | arguments.
26 | }
27 | \item{\code{startServer(port = NULL)}}{
28 | Starts a local server that listens to a given port. If \code{port = NULL}, picks a random available port.
29 | See also \code{\link{openPage}}.
30 | }
31 | \item{\code{stopServer()}}{
32 | Closes all active sessions and stops a running server. See also \code{\link{closePage}}.
33 | }
34 | \item{\code{openPage(useViewer = TRUE, browser = NULL)}}{
35 | Opens a new web page either in a browser, or in the R Studio viewer. If \code{useViewer = FALSE} and browser is not selected,
36 | a default installed browser is used. If browser is specified, \code{useViewer} is ignored. This method returns
37 | a new \code{\link{Session}} object, which should correspond to the page that has been just opened. However, if someone would start
38 | a new connection at the moment when \code{openPage} method is called, it may return a wrong session. See also \code{\link{openPage}}.
39 | }
40 | \item{\code{getSession(sessionId = NULL)}}{
41 | Returns a session with the given ID or \code{NULL} if session with this ID doesn't exist. If \code{sessionId = NULL}
42 | and there is only one active session, returns it. See also \code{\link{getSession}}.
43 | }
44 | \item{\code{closeSession(sessionId = NULL, inactive = NULL, old = NULL)}}{
45 | Closes WebSocket connection of one or multiple sessions and removes all the related data from the app. For more information on
46 | the arguments, please, check \code{\link{closeSession}} man page.
47 | }
48 | \item{\code{getSessionIds()}}{
49 | Returns IDs of all currently active sessions. See also \code{\link{getSessionIds}}.
50 | }
51 | \item{\code{setEnvironment(envir)}}{
52 | Specifies the outer environment of the app, in which all the messages from the web pages will be evaluated. For more information,
53 | please, check \code{\link{setEnvironment}}.
54 | }
55 | \item{\code{allowFunctions(funs = NULL)}}{
56 | Adds function names to a list of allowed R functions. These functions can be called from a web page without authorization
57 | on the R side. If \code{funs = NULL}, returns a list of all currently allowed functions. For more information,
58 | please, check \code{\link{allowFunctions}}.
59 | }
60 | \item{\code{allowVariables(vars = NULL)}}{
61 | Adds variable names to the list of allowed variables. These variables can be changed from a web page without
62 | authorization on the R side. If \code{vars = NULL}, then returns a vector of names of all currently allowed variables.
63 | For more information, please, check \code{\link{allowVariables}}.
64 | }
65 | \item{\code{allowDirectories(dir = NULL)}}{
66 | Allows app to serve files from an existing directory. Files from the \code{rootDirectory} can always be accessed
67 | by the app. By default, the current working directory is
68 | added to the list of the allowed directories, when the app is initialized. All the subdirectories of the allowed
69 | directories can also be accessed. Attempt to request file from outside allowed directory will produce
70 | \code{403 Forbidden} error. If \code{dirs = NULL}, then returns a vector of names of all currently allowed directories.
71 | Also see \code{\link{allowDirectories}}.
72 | }
73 | \item{\code{startPage(path = NULL)}}{
74 | Sets path to a starting web page of the app. Path can be full, relative to the app's root directory or relative
75 | to the current R working directory. If
76 | \code{path = NULL}, returns current path to the starting page.
77 | }
78 | \item{\code{rootDirectory(path = NULL)}}{
79 | Sets path to the root directory for the server. Any file, requested by the server, will be looked for in this directory.
80 | Can be a full path or a path relative to the current R working directory. If \code{path = NULL}, returns path to the
81 | current root directory.
82 | }
83 | \item{\code{setLimits(...)}}{
84 | Sets limits for memory usage, number of simultaneously active connections and amount of messages processed per second.
85 | These settings will apply for each new connection. To change memory usage for an existing session use method \code{setLimits}
86 | of class \code{\link{Session}}. For information about possible arguments, please, check \code{\link{setLimits}}.
87 | }
88 | \item{\code{getPort()}}{
89 | Returns number of the port which the running server listens to. After the app has been initialized, the port number cannot be changed.
90 | }
91 | }
92 | }
93 |
94 |
--------------------------------------------------------------------------------
/man/openPage.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/jrc.R
3 | \name{openPage}
4 | \alias{openPage}
5 | \title{Create a server}
6 | \usage{
7 | openPage(
8 | useViewer = TRUE,
9 | rootDirectory = NULL,
10 | startPage = NULL,
11 | port = NULL,
12 | browser = NULL,
13 | allowedFunctions = NULL,
14 | allowedVariables = NULL,
15 | allowedDirectories = getwd(),
16 | connectionNumber = Inf,
17 | sessionVars = NULL,
18 | onStart = NULL,
19 | onClose = NULL,
20 | onlyServer = FALSE
21 | )
22 | }
23 | \arguments{
24 | \item{useViewer}{If \code{TRUE}, the new web page will be opened in the RStudio Viewer. If \code{FALSE},
25 | a default web browser will be used (if other is not specified with the \code{browser} argument).}
26 |
27 | \item{rootDirectory}{A path to the root directory for the server. Any file, requested by the server
28 | will be searched for in this directory. If \code{rootDirectory} is not
29 | defined, the \code{http_root} in the package directory will be used as a root directory.}
30 |
31 | \item{startPage}{A path to an HTML file that should be used as a starting page of the app.
32 | It can be an absolute path to a local file, or it can be relative to the \code{rootDirectory}
33 | or to the current R working directory. If \code{startPage} is not defined, an empty page will be used.
34 | The file must have \emph{.html} extension.}
35 |
36 | \item{port}{Defines which TCP port the server will listen to. If not defined, random available port
37 | will be used (see \code{\link[httpuv]{randomPort}}).}
38 |
39 | \item{browser}{A browser in which to open a new web page.
40 | If not defined, default browser will be used. For more information check \code{\link[utils]{browseURL}}.
41 | If this argument is specified, \code{useViewer} will be ignored.}
42 |
43 | \item{allowedFunctions}{List of functions that can be called from a web page without any additional actions
44 | on the R side. All other functions will require authorization in the current R session before they are called.
45 | This argument should be a vector of R function names. Check \code{\link{authorize}} and \code{\link{allowFunctions}}
46 | for more information.}
47 |
48 | \item{allowedVariables}{List of variables that can be modified from a web page without any additional actions
49 | on the R side. All other variable reassignments must be confirmed in the current R session.
50 | This argument should be a vector of variable names. Check \code{\link{authorize}} and \code{\link{allowVariables}}
51 | for more information.}
52 |
53 | \item{allowedDirectories}{List of directories that can be accessed by the server. This argument should be a vector of
54 | paths (absolute or relative to the current working directory) to existing directories. Check \code{\link{allowDirectories}}
55 | for more information.}
56 |
57 | \item{connectionNumber}{Maximum number of connections that is allowed to be active simultaneously.}
58 |
59 | \item{sessionVars}{Named list of variables, that will be declared for each session, when a new connection is opened.
60 | Any changes to these variables will affect only a certain session. Thus they can be used, for instance, to
61 | store a state of each session. For more information, please, check \code{\link{setSessionVariables}}.}
62 |
63 | \item{onStart}{A callback function that will be executed, when a new connection is opened. This function gets a single
64 | argument, which is an object of class \code{\link{Session}}. General purpose of the function is to populate each
65 | new web page with some default content.}
66 |
67 | \item{onClose}{A callback function that will be executed, when a connection is closed. This function gets a single
68 | argument, which is an object of class \code{\link{Session}}. General purpose of the function is to store session
69 | variables if needed or in any other form to finalize user's interaction with the app.}
70 |
71 | \item{onlyServer}{If \code{TRUE}, then an app will initialise without trying to open a new page in a browser.}
72 | }
73 | \value{
74 | Object of class \code{\link{App}}.
75 | }
76 | \description{
77 | \code{openPage} starts a server and opens a new page with a WebSocket connection between it and the current
78 | R session. After that, messages can be exchanged between R session and the web page to generate content on the
79 | web page and to trigger calculations in R as a response to user activity on the page.
80 | }
81 | \details{
82 | \code{jrc} supports four types of messages:
83 | \itemize{
84 | \item{Commands are pieces of R or JavaScript code that will be evaluated on the receiving side. Note,
85 | that any command from a web page must be authorized in the R session for security reasons. A message
86 | with information about how to do that is printed in the console each time a command is received. For more
87 | information, please, check \code{\link{sendCommand}}.}
88 | \item{Data is any variable that is sent to or from the R session. It must always come with a
89 | name of the variable to which it should be assigned on the receiving side. For more information, please,
90 | check \code{\link{sendData}}.}
91 | \item{Function calls can be triggered on each side of the WebSocket connection. Alongside the function name,
92 | one can also send a list of arguments and name of a variable to which the returned value of the function will
93 | be assigned. For more information, please, check \code{\link{callFunction}}.}
94 | \item{Unlike other types of messages, HTML code can be sent only from the R session to a web page. This code will
95 | be added to the body of the page.}
96 | }
97 |
98 | \code{openPage} function is a wrapper around several methods of class \code{\link{App}}. First, it creates an
99 | instance of this class. Then it starts a server that listens to the given port. And finally, it attempts
100 | to open a new web page. It also stores a new app object in the package namespace, which allows other
101 | wrapper functions to access it.
102 | }
103 | \seealso{
104 | \code{\link{closePage}}, \code{\link{setEnvironment}}, \code{\link{setLimits}}, \code{\link{allowVariables}},
105 | \code{\link{allowFunctions}}, \code{\link{setSessionVariables}}.
106 | }
107 |
--------------------------------------------------------------------------------
/tests/testthat/test_sendData.R:
--------------------------------------------------------------------------------
1 | context("Send and receive data")
2 |
3 | test_that("Data types are converted appropriately on the server side", {
4 | openPage()
5 | allowVariables(c("type", "size", "names"))
6 |
7 | sendData("x", 10)
8 | sendCommand("jrc.sendData('type', typeof x)", wait = 3)
9 | expect_equal(type, "number")
10 |
11 | sendData("y", "abc")
12 | sendCommand("jrc.sendData('type', typeof y)", wait = 3)
13 | expect_equal(type, "string")
14 |
15 | sendData("z", 1:10)
16 | sendCommand("jrc.sendData('type', Array.isArray(z) ? 'Array' : 'something else')", wait = 3)
17 | sendCommand("jrc.sendData('size', z.length)", wait = 3)
18 | expect_equal(type, "Array")
19 | expect_equal(size, 10)
20 |
21 | sendData("k", c("a", "b", "c"))
22 | sendCommand("jrc.sendData('type', Array.isArray(k) ? 'Array' : 'something else')", wait = 3)
23 | sendCommand("jrc.sendData('size', k.length)", wait = 3)
24 | expect_equal(type, "Array")
25 | expect_equal(size, 3)
26 |
27 | sendData("f", as.factor(1:10)) # factor -> Array of strings
28 | sendCommand("jrc.sendData('type', typeof f[0])", wait = 3)
29 | expect_equal(type, "string")
30 |
31 | sendData("m", matrix(1:12, nrow = 4)) # matrix -> Array of Arrays
32 | sendCommand("jrc.sendData('size', [m.length, m[0].length])", wait = 3)
33 | expect_equal(size, c(4, 3))
34 |
35 | sendData("df", data.frame(a = 1:10, b = 11:20)) # data.frame -> Array of Objects (rowwise)
36 | sendCommand("jrc.sendData('size', df.length)", wait = 3)
37 | expect_equal(size, 10)
38 | sendCommand("jrc.sendData('names', Object.keys(df[0]))", wait = 3)
39 | expect_equal(names, c("a", "b"))
40 |
41 | sendData("df2", data.frame(a = 1:10, # data.frame -> Array of Objects (rowwise) (factor -> character)
42 | b = paste0("a", 1:10),
43 | c = as.factor(rep(c("a", "b"), times = 5)),
44 | stringsAsFactors = F))
45 | sendCommand("jrc.sendData('type', [typeof df2[0].a, typeof df2[0].b, typeof df2[0].c])", wait = 3)
46 | expect_equal(type, c("number", "string", "string"))
47 |
48 | ####columnwise#####
49 | sendData("m", matrix(1:12, nrow = 4), rowwise = F) # matrix -> Array of Arrays
50 | sendCommand("jrc.sendData('size', [m.length, m[0].length])", wait = 3)
51 | expect_equal(size, c(3, 4))
52 |
53 | sendData("df", data.frame(a = 1:10, b = 11:20), rowwise = FALSE) # data.frame -> Object with each column as Array
54 | sendCommand("jrc.sendData('size', df.a.length)", wait = 3)
55 | sendCommand("jrc.sendData('type', typeof df.b[0])", wait = 3)
56 | expect_equal(size, 10)
57 | expect_equal(type, "number")
58 |
59 | sendData("df2", data.frame(a = 1:10, # data.frame -> Object with each column as Array
60 | b = paste0("a", 1:10),
61 | c = as.factor(rep(c("a", "b"), times = 5)),
62 | stringsAsFactors = F), rowwise = F)
63 | sendCommand("jrc.sendData('names', Object.keys(df2))", wait = 3)
64 | sendCommand("jrc.sendData('type', [typeof df2.a[0], typeof df2.b[0], typeof df2.c[0]])", wait = 3)
65 | expect_equal(type, c("number", "string", "string"))
66 | expect_equal(names, c("a", "b", "c"))
67 |
68 | sendData("l", list(a = 1, b = 1:10, c = c("a", "b", "c"), d = as.factor(1:10))) # list of vectors -> Object of Arrays
69 | sendCommand("jrc.sendData('names', Object.keys(l))", wait = 3)
70 | sendCommand("jrc.sendData('type', typeof l.a)", wait = 3)
71 | sendCommand("jrc.sendData('size', l.c.length)", wait = 3)
72 | expect_equal(type, "number")
73 | expect_equal(names, c("a", "b", "c", "d"))
74 | expect_equal(size, 3)
75 |
76 | #keepAsVector = TRUE
77 | sendData("l", list(a = 1, b = 1:10), keepAsVector = TRUE) # list of vectors -> Object of Arrays
78 | sendCommand("jrc.sendData('size', l.a.length)", wait = 3)
79 | expect_equal(size, 1)
80 |
81 | sendData("l2", list(data.frame(a = 1:10, # unnamed list -> Array of Arrays and Objects
82 | b = paste0("a", 1:10),
83 | c = as.factor(rep(c("a", "b"), times = 5)),
84 | stringsAsFactors = F),
85 | matrix(1:12, nrow = 4),
86 | list(a = 1, b = 1:10, c = c("a", "b", "c"), d = as.factor(1:10))))
87 | sendCommand("jrc.sendData('type', Array.isArray(l2) ? 'Array' : 'something else')", wait = 3)
88 | expect_equal(type, "Array")
89 | sendCommand("jrc.sendData('type', typeof l2[2].a)", wait = 3)
90 | expect_equal(type, "number")
91 |
92 | expect_message(closePage(), "Server has been stopped.")
93 | })
94 |
95 | test_that("Data types are converted appropriately on the R side", {
96 | openPage(allowedVariables = c("x", "y", "z", "k", "m", "l"))
97 |
98 | sendCommand('jrc.sendData("x", 10)', wait = 3) # number -> number
99 | expect_true(is.numeric(x))
100 |
101 | sendCommand('jrc.sendData("y", "abc")', wait = 3) # string -> character
102 | expect_type(y, "character")
103 |
104 | sendCommand('jrc.sendData("z", [1, 2, 3, 4, 5, 6])', wait = 3) # Array -> vector of numerics
105 | expect_true(is.vector(z))
106 | expect_true(is.numeric(z))
107 |
108 | sendCommand('jrc.sendData("k", ["a", "b", "c"])', wait = 3)
109 | expect_true(is.character(k))
110 | expect_length(k, 3)
111 |
112 | sendCommand('jrc.sendData("m", [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]])', wait = 3) # Array of numeric Arrays -> matrix (rowwise)
113 | expect_equal(dim(m), c(4, 3))
114 |
115 | sendCommand('jrc.sendData("l", {a: [1, 2, 3, 4, 5, 6], b: [7, 8, 9, 10, 11, 12]})', wait = 3)
116 | expect_type(l, "list")
117 | expect_length(l$a, 6)
118 | expect_true(is.numeric(l$b))
119 |
120 | expect_message(closePage(), "Server has been stopped.")
121 | })
122 |
123 | test_that("Data messages can be stored for later execution", {
124 | openPage()
125 |
126 | sendCommand('jrc.sendData("x", 15, false)', wait = 3)
127 |
128 | expect_length(getMessageIds(), 1)
129 |
130 | messageId <- getMessageIds()
131 | authorize(messageId = messageId)
132 |
133 | expect_equal(x, 15)
134 |
135 | expect_length(getMessageIds(), 0)
136 | expect_message(closePage(), "Server has been stopped.")
137 | })
138 |
139 | test_that("Variables are assigned in a correct environment", {
140 |
141 | openPage(allowedVariables = c(".x_ut", ".y_ut", ".z_ut"))
142 | e <- new.env()
143 | setEnvironment(e)
144 |
145 | sendCommand('jrc.sendData(".x_ut", 18, false)', wait = 3)
146 | expect_false(exists(".x_ut"))
147 | expect_equal(e$.x_ut, 18)
148 |
149 | sendCommand('jrc.sendData(".y_ut", 22, true)', wait = 3)
150 | expect_false(exists(".y_ut"))
151 | expect_false(exists(".y_ut", envir = e))
152 |
153 | y <- getSessionVariable(".y_ut")
154 | expect_equal(y, 22)
155 |
156 | setEnvironment(environment())
157 | setSessionVariables(list(.z_ut = 10))
158 | sendCommand('jrc.sendData(".z_ut", 19)', wait = 3)
159 | expect_false(exists(".z_ut"))
160 | z <- getSessionVariable(".z_ut")
161 | expect_equal(z, 19)
162 |
163 | expect_message(closePage(), "Server has been stopped.")
164 | })
--------------------------------------------------------------------------------
/cran-comments.md:
--------------------------------------------------------------------------------
1 | ## Resubmission
2 |
3 | This is a new version of the package. It adds a function to block the R session and listen to the server. It is needed to use jrc apps, for instance, in Jupyter Notebooks or in other cases, where the R
4 | session is not interactive.
5 |
6 | Regarding the auto-check issues at https://www.stats.ox.ac.uk/pub/bdr/donttest/jrc.out
7 |
8 | I've replaced all donttest examples with dontrun and added a comment for the users that one needs a browser to run the code.
9 |
10 | >> Dear CRAN Team,
11 |
12 | >> The error occurs because all the provided examples require a browser to be installed, which is not always the case for automated checks. The examples are checked locally (manually in RStudio and with R CMD check --run-donttest). Also, they work when testing for Windows platform with rhub, or check_win_devel. In other cases (rhub Ubuntu and Fedora) I set _R_CHECK_DONTTEST_EXAMPLES_=FALSE. Should I do something like that for the CRAN auto-check? Or maybe replace donttest with dontrun?
13 |
14 | >Yes, please \dontrun{} plus an exlplanation as comment.
15 | >Or perhaps protect by if(interactive()) in case it should only run for users working interactivbely with the package.
16 |
17 | >Best,
18 | >Uwe Ligges
19 |
20 | ## Test environments
21 | * local Ubuntu 23.04, R 4.2.2
22 | * win-builder: R-devel
23 | * Ubuntu Linux 20.04.1 LTS, R-release; Windows Server 2022, R-devel, 64 bit; Fedora Linux, R-devel (R-hub)
24 |
25 | There were 2 NOTES when testing the package for Windows with R-hub:
26 |
27 | ```
28 | * checking for non-standard things in the check directory ... NOTE
29 | Found the following files/directories:
30 | ''NULL''
31 |
32 | * checking for detritus in the temp directory ... NOTE
33 | Found the following files/directories:
34 | 'lastMiKTeXException'
35 | ```
36 | Both are mentioned in the open issues of the rhub package.
37 |
38 | There was 1 NOTE when testing on R-hub (for both Ubuntu and Fedora), which, as far as I undertood, is caused by some promlem on the side of the testing platform.
39 |
40 | ```
41 | * checking HTML version of manual ... NOTE
42 | Skipping checking HTML validation: no command 'tidy' found
43 | ```
44 |
45 | # Previous cran-comments
46 |
47 | ## Resubmission
48 |
49 | This is a new version of the package. It introduces minor changes in functionality and also fixes a
50 | couple of existing issues. See NEWS.md for more details.
51 |
52 | ## Test environments
53 | * local Ubuntu 21.10, R 4.0.4
54 | * win-builder: R-devel
55 | * Ubuntu Linux 20.04.1 LTS, R-release; Windows Server 2022, R-devel, 64 bit; Fedora Linux, R-devel (R-hub)
56 |
57 | There is a NOTE when testing for Windows Server:
58 | ```
59 | * checking for detritus in the temp directory ... NOTE
60 | Found the following files/directories:
61 | 'lastMiKTeXException'
62 | ```
63 | However, I can't neither understand the cause of this note, nor reproduce it locally on my Windows machine (Windows 10, 64 bit, R 4.0.2, MiKTeX installed). There are also no notes or errors in the win-builder. So I decided to submit the package anyway.
64 |
65 | ## Resubmission
66 | This is a new version of the package. It introduces minor changes in functionality and also fixes a
67 | couple of existing issues. See NEWS.md for more details.
68 |
69 | ## Test environments
70 | * local ubuntu 20.04 LST, R 4.0.3
71 | * win-builder: R-devel
72 | * ubuntu 16.04.6 LTS, R-devel, R 4.0.2, R 3.6.3 (travis ci)
73 |
74 | ## R CMD check results
75 |
76 | There were no ERRORS, WARNINGS or NOTES
77 |
78 | ## Resubmission
79 | This is a new version of the package. It fixes a major security issue by restricting server access to only to specified directories.
80 |
81 | All the examples were checked locally by both R CMD check --run-donttest and running them manually in RStudio.
82 | However, all other checks were performed with _R_CHECK_DONTTEST_EXAMPLES_=FALSE.
83 | Examples, wrapped in donttest{}, are functional and don't produce errors, but require some browser to be installed.
84 | I would rather not change `donttest` to `dontrun`, since it can confuse users.
85 |
86 | ## Test environments
87 | * local ubuntu 20.04 LST, R 4.0.2
88 | * win-builder: R-devel
89 | * ubuntu 16.04.6 LTS, R-devel, R 4.0.2, R 3.6.3 (travis ci)
90 |
91 | ## R CMD check results
92 |
93 | There were no ERRORS, WARNINGS or NOTES
94 |
95 | ## Resubmission
96 |
97 | This is a new version that fixes some existing bugs. Other than that, it doesn't change any functinality. For more details, please, check NEWS.md.
98 |
99 | ## Test environments
100 | * local ubuntu 18.04 LST, R 3.6.2
101 | * win-builder: R-devel
102 | * ubuntu 16.04.6 LTS, R-devel, R 3.6.2, R 3.5.3 (travis ci)
103 |
104 | ## R CMD check results
105 |
106 | There were no ERRORS, WARNINGS or NOTES
107 |
108 | ## Resubmission
109 |
110 | This is a new version that introduces major restructarization of the package. It now supports multiple connections to the interactive apps and
111 | introduces functions to manage client sessions. The app itself is now contained within a single R6 object, which allows to start multiple apps
112 | inside one R session.
113 |
114 | ## Reverse dependencies
115 |
116 | Backwards compatibility is fully maintained.
117 |
118 | ## Test environments
119 | * local ubuntu 18.04 LST, R 3.6.2
120 | * win-builder: R-devel
121 | * ubuntu 16.04.6 LTS, R-devel, R 3.6.2, R 3.5.3 (travis ci)
122 |
123 | ## R CMD check results
124 |
125 | There were no ERRORS, WARNINGS or NOTES
126 |
127 | ## Resubmission
128 |
129 | This is a new version that fixes some existing bugs, such as crashing when one attempts to send data with NAs present,
130 | and inability to use the package on RStudio Server. For more details, please, check NEWS.md.
131 |
132 | ## Reverse dependencies
133 |
134 | None is affected.
135 |
136 | ## Test environments
137 | * local ubuntu 18.04 LST, R 3.6.1
138 | * win-builder: R-devel
139 | * ubuntu 14.04.5 LTS, R-devel, R 3.5.2, R 3.4.4 (travis ci)
140 |
141 | ## R CMD check results
142 |
143 | There were no ERRORS, WARNINGS or NOTES
144 |
145 | ## Resubmission
146 |
147 | This is a new version of the package. Here, we introduce functionality to limit the amount of control
148 | user can get over the currently running R session from the web page. As a part of this, `callFunction`
149 | function added to be used instead of `sendCommand` whenever possible and some bugs in variable types, when
150 | they are exchanged between R and JavaScript fixed. For more details, please, check NEWS.md.
151 |
152 | This resubmition will be followed by the resubmition of this package's reverse dependency `sleepwalk`.
153 |
154 | ## Test environments
155 | * local ubuntu 18.04 LST, R 3.6.1
156 | * win-builder: R-devel
157 | * ubuntu 14.04.5 LTS, R-devel, R 3.5.2, R 3.4.4 (travis ci)
158 |
159 | ## R CMD check results
160 |
161 | There were no ERRORS, WARNINGS or NOTES
162 |
163 | ## Test environments
164 | * local ubuntu 16.04 LST, R 3.5.1
165 | * win-builder: R-devel
166 | * ubuntu 14.04.5 LTS, R 3.5.2 (travis ci)
167 |
168 | ## R CMD check results
169 |
170 | There were no ERRORS, WARNINGS or NOTES
171 |
172 | ## Resubmission
173 |
174 | * unused import ('run_now' from 'later') removed.
175 | * DESCRIPTION eddited.
176 | * A typo that resulted in "Unexecutable code in man/sendCommand.Rd" error fixed.
177 |
178 | >> Most of your examples are wrapped in \donttest{} and hence not tested. Please unwrap the examples if that is feasible and if they can be executed in < 5 sec for each Rd file or create additionally small toy examples.
179 | Unfortunately, running even the most minimalistic examples requires to open a web page and establish a websocket connection. While this works locally, devtools::check_rhub() always produces errors about not being able to open a web browser.
180 |
--------------------------------------------------------------------------------
/tests/test.R:
--------------------------------------------------------------------------------
1 | library( jrc )
2 | library( stringr )
3 |
4 | app <- App$new()
5 | app$startServer()
6 | app$openPage()
7 | app$getSessionIds()
8 | app$openPage(useViewer = F, browser = "google-chrome")
9 | app$getSessionIds()
10 | session <- app$getSession("A4Iqa2")
11 | app$closeSession("Ld0mWS")
12 | app$closeSession(session)
13 | app$stopServer()
14 |
15 | port <- httpuv::randomPort()
16 | openPage(port = port)
17 |
18 | appTest <- App$new()
19 | env <- new.env()
20 | env$someVariable <- 1
21 | appTest$setEnvironment(env)
22 | appTest$startServer()
23 | appTest$openPage()
24 | id <- appTest$getSessionIds()$id
25 | sessionTest <- appTest$getSession(id)
26 | #sessionTest$sendCommand("jrc.sendCommand('k_test <<- 15')", wait = 3)
27 | #mesId <- sessionTest$getMessageIds()
28 | #msg <- sessionTest$getMessage(mesId)
29 | #sessionTest$authorize(mesId, show = T)
30 | sessionTest$sendCommand("jrc.sendCommand('env1 <<- environment()')", wait = 1)
31 | mesIds <- sessionTest$getMessageIds()
32 | sessionTest$authorize(mesIds[1])
33 | appTest$stopServer()
34 |
35 | appTest <- App$new()
36 | appTest$startServer()
37 | appTest$openPage()
38 | id <- appTest$getSessionIds()$id
39 | sessionTest <- appTest$getSession(id)
40 | sessionTest$sendCommand("jrc.sendCommand('env1 <<- environment()')", wait = 1)
41 | mesIds <- sessionTest$getMessageIds()
42 | sessionTest$authorize(mesIds[1])
43 | appTest$stopServer()
44 |
45 |
46 |
47 | openPage(useViewer = F, port = 12345, browser = "firefox")
48 | closePage()
49 |
50 | #test basic functions
51 | openPage(useViewer = F)
52 | allowVariables("type")
53 |
54 | appTest <- getPage()
55 | sessionTest <- appTest$getSession(appTest$getSessionIds()$id)
56 | sessionTest$getMessage("1ivSCK")
57 |
58 | sendCommand("alert('Bla-bla-bla')")
59 |
60 | sendData("x", 10) # number -> number
61 | sendData("y", "abc") # character -> string
62 | sendData("z", 1:10) # vector (with multiple elements) -> Array
63 | sendData("k", c("a", "b", "c")) # vector (with several characters) -> Array
64 | sendData("f", as.factor(1:10)) # factor -> Array of strings
65 |
66 | sendData("m", matrix(1:12, nrow = 4)) # matrix -> Array of Arrays
67 | sendData("df", data.frame(a = 1:10, b = 11:20)) # data.frame -> Array of Objects (rowwise)
68 | sendData("df2", data.frame(a = 1:10, # data.frame -> Array of Objects (rowwise) (factor -> character)
69 | b = paste0("a", 1:10),
70 | c = as.factor(rep(c("a", "b"), times = 5)),
71 | stringsAsFactors = F))
72 | ####columnwise#####
73 | sendData("m_r", matrix(1:12, nrow = 4), rowwise = F) # matrix -> Array of Arrays
74 | sendData("df_r", data.frame(a = 1:10, b = 11:20), rowwise = F) # data.frame -> Array of Objects
75 | sendData("df2_r", data.frame(a = 1:10, # data.frame -> Array of Objects (factor -> character)
76 | b = paste0("a", 1:10),
77 | c = as.factor(rep(c("a", "b"), times = 5)),
78 | stringsAsFactors = F), rowwise = F)
79 |
80 | #rownames and colnames
81 | #row and column names of matrices are ignored
82 | #data.frames are turned into objects if rowwise = T or get additional _row column.
83 | #let's leave it like that for now
84 | a <- matrix(1:12, nrow = 4)
85 | rownames(a) <- paste0("row", 1:4)
86 | colnames(a) <- paste0("col", 1:3)
87 | sendData("m_names", a)
88 | sendData("df_names", as.data.frame(a))
89 | sendData("df_names_r", as.data.frame(a), rowwise = F)
90 |
91 | #TO DO: make sure that keepAsVector also works on elements of a list (recursively?)
92 | sendData("l", list(a = 1, b = 1:10, c = c("a", "b", "c"), d = as.factor(1:10))) # list of vectors -> Object of Arrays
93 | sendData("l2", list(data.frame(a = 1:10, # unnamed list -> Array of Arrays and Objects
94 | b = paste0("a", 1:10),
95 | c = as.factor(rep(c("a", "b"), times = 5)),
96 | stringsAsFactors = F),
97 | matrix(1:12, nrow = 4),
98 | list(a = 1, b = 1:10, c = c("a", "b", "c"), d = as.factor(1:10))))
99 |
100 | # to run from the browser
101 | # jrc.sendCommand("a <<- 10")
102 | #
103 | # jrc.sendData("x", 10) number -> number
104 | allowVariables(c("y", "z", "k", "m"))
105 | # jrc.sendData("y", "abc") string -> character
106 | # jrc.sendData("z", [1, 2, 3, 4, 5, 6]) Array -> vector of numerics
107 | # jrc.sendData("k", ["a", "b", "c"])
108 |
109 | # jrc.sendData("m", [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) Array of numeric Arrays -> matrix (rowwise)
110 | # jrc.sendData("df", {a: [1, 2, 3, 4, 5, 6], b: [7, 8, 9, 10, 11, 12]}) TO DO: Make this turn df into data.frame
111 |
112 | callFunction("alert", list("AAAAAAAA!"))
113 | callFunction("Math.random", assignTo = "x")
114 |
115 | # jrc.callFunction("print", 10)
116 | # jrc.callFunction("rnorm", 10, "x")
117 | allowFunctions("rnorm")
118 | allowVariables("x")
119 |
120 | #basic button example
121 | k <- 0
122 | openPage()
123 | sendCommand(str_c("button = document.createElement('input');",
124 | "button.type = 'button';",
125 | "button.addEventListener('click', function() {jrc.sendCommand('k <<- k + 1')});",
126 | "button.value = '+1';",
127 | "document.body.appendChild(button);", collapse = "\n"))
128 | closePage()
129 |
130 |
131 |
132 | #load linked charts from a local file
133 | openPage(rootDirectory = "~/Work/Git/linked-charts/", useViewer = F)
134 | x <- seq(0, 5, length.out = 100)
135 | y <- sin(x) + rnorm(n = 100, sd = 0.2)
136 |
137 | sendData("x", x)
138 | sendData("y", y)
139 |
140 | selPoint <- -1
141 |
142 | sendCommand(str_c("script = document.createElement('script');",
143 | "script.src = 'build/linked-charts.js';",
144 | "document.head.appendChild(script);", collapse = "\n"))
145 |
146 | sendCommand(str_c("script = document.createElement('script');",
147 | "script.src = 'build/adds.js';",
148 | "document.head.appendChild(script);", collapse = "\n"))
149 |
150 | sendCommand(str_c("link = document.createElement('link');",
151 | "link.rel = 'stylesheet';",
152 | "link.href = 'lib/linked-charts.css';",
153 | "document.head.appendChild(link);", collapse = "\n"))
154 |
155 | sendCommand("selPoint = -1")
156 | sendCommand(str_c("sc = lc.scatter()",
157 | ".x(function(k) {return x[k]})",
158 | ".y(function(k) {return y[k]})",
159 | ".colour(function(k) {return k == selPoint ? 'red' : 'black';})",
160 | ".on_click(function(k) {selPoint = k; jrc.sendCommand('selPoint <<- ' + k); jrc.callFunction('print', selPoint); sc.update()})",
161 | ".place()", collapse = "\n"))
162 |
163 | closePage()
164 |
165 | k <- 0
166 | a <- 0
167 | #try multiple sessions
168 | openPage(useViewer = F, onStart = function(id) {
169 | sendHTML(str_c("
Session ID: ", id, "
"), id = id)
170 | sendHTML("
a = ; k =
", id = id)
171 |
172 | sendCommand(str_c("buttonK = document.createElement('input');",
173 | "buttonK.type = 'button';",
174 | "buttonK.addEventListener('click', function() {jrc.sendCommand('k <- k + 1'); jrc.callFunction('updateText')});",
175 | "buttonK.value = 'k + 1';",
176 | "document.body.appendChild(buttonK);", collapse = "\n"), id = id)
177 |
178 | sendCommand(str_c("buttonA = document.createElement('input');",
179 | "buttonA.type = 'button';",
180 | "buttonA.addEventListener('click', function() {jrc.sendCommand('a <<- a + 1'); jrc.callFunction('updateText')});",
181 | "buttonA.value = 'a + 1';",
182 | "document.body.appendChild(buttonA);", collapse = "\n"), id = id)
183 |
184 | }, allowedFunctions = "updateText")
185 |
186 |
187 | updateText <- function() {
188 | sendCommand(str_c("document.getElementById('a').innerHTML = ", a, ";",
189 | "document.getElementById('k').innerHTML = ", k, ";"), id = .id)
190 | }
191 |
192 | Accum <- R6::R6Class("Accum", public = list(
193 | addone = function(){
194 | private$count <- private$count + 1
195 | },
196 | show = function() {
197 | private$count
198 | }
199 | ),
200 | private = list(
201 | count = 0
202 | ))
203 | obj <- Accum$new()
204 |
205 | openPage(allowedFunctions = c("obj$addone"))
206 | sendCommand("jrc.callFunction('obj$addone')", wait = 3)
207 |
--------------------------------------------------------------------------------
/inst/http_root/jrc.js:
--------------------------------------------------------------------------------
1 | //get current url
2 | var urlSpl = window.location.href.split("/"),
3 | urlWs = "";
4 | if(urlSpl[0] == "https:")
5 | urlWs += "wss://"
6 | else
7 | urlWs += "ws://";
8 | urlWs += urlSpl[2] + "/" + urlSpl.slice(3).join("/");
9 | urlWs = urlWs.split("?")[0];
10 | if(urlWs.slice(-1) != "/")
11 | urlWs += "/";
12 | // if(urlSpl[3] == "p")
13 | // urlWs += "p/" + urlSpl[4] + "/";
14 |
15 | jrc = {};
16 |
17 | // establish WebSocket link and handlers
18 | jrc.ws = new WebSocket( urlWs )
19 |
20 | jrc.ws.addEventListener( "open", function(event) {
21 | // ...
22 | } );
23 |
24 | jrc.ws.addEventListener( "message", function(event) {
25 | msg = JSON.parse( event.data );
26 | for(el in msg) msg[el] = msg[el][0];
27 |
28 | if(msg.type == "COM") {
29 | eval(msg.com);
30 | return;
31 | }
32 | if(msg.type == "DATA") {
33 | //msg.variableName - variable name
34 | //msg.variable - variable content
35 | //msg.keepAsVector - 'TRUE' or 'FALSE'
36 | if(msg.variableName == undefined || !jrc.isValidName(msg.variableName)) {
37 | console.log("DATA message with invalid variable name has been recieved: " + msg.variableName)
38 | ws.send("warning('Invalid variable name: " + msg.variableName + "')");
39 | return;
40 | }
41 | window[msg.variableName] = JSON.parse(msg.variable);
42 | // check if we also got `keepAsVector` parameter and it's false
43 | turnToScalar = function(v) {
44 | if(!v || (v.length === undefined && typeof v !== "object") || typeof v === "string") return v;
45 | if(Array.isArray(v)) {
46 | if(v.length == 1) return v[0];
47 | for(var i = 0; i < v.length; i++)
48 | v[i] = turnToScalar(v[i]);
49 | } else {
50 | var keys = Object.keys(v);
51 | for(var i = 0; i < keys.length; i++)
52 | v[keys[i]] = turnToScalar(v[keys[i]]);
53 | }
54 | return v;
55 | }
56 | if(!msg.keepAsVector) {
57 | window[msg.variableName] = turnToScalar(window[msg.variableName]);
58 | }
59 |
60 | if(window[msg.variableName] && window[msg.variableName].length && window[msg.variableName][0]._row) {
61 | var converted = {}, rowname;
62 | for(var i = 0; i < window[msg.variableName].length; i++) {
63 | rowname = window[msg.variableName][i]._row;
64 | delete window[msg.variableName][i]._row;
65 | converted[rowname] = window[msg.variableName][i];
66 | }
67 | window[msg.variableName] = converted;
68 | }
69 | return;
70 | }
71 | if(msg.type == "HTML") {
72 | document.body.innerHTML += msg.html;
73 | return;
74 | }
75 | if(msg.type == "FUN") {
76 | //msg.name - function name
77 | //msg.assignTo - variable name
78 | //msg.thisArg - apply to this
79 | //___args___ - arguments
80 |
81 | var fCall = msg.name.split("."),
82 | obj = window;
83 |
84 | for(var i = 0; i < fCall.length; i++){
85 | if(i == fCall.length - 1)
86 | self = obj;
87 | obj = obj[fCall[i]];
88 | }
89 |
90 | if(msg.thisArg) {
91 | var thisName = msg.thisArg.split(".");
92 | self = window;
93 | for(let i = 0; i < thisName.length; i++)
94 | self = self[thisName[i]];
95 | }
96 |
97 | var ___tmp___ = obj.apply(self, window["___args___"]);
98 |
99 | if(msg.assignTo)
100 | window[msg.assignTo] = ___tmp___;
101 |
102 | window["___args___"] = null;
103 |
104 | return;
105 | }
106 | if(msg.type == "ID") {
107 | jrc.id = msg.id
108 | return;
109 | }
110 | console.log("Unknown message type: " + msg.type)
111 | jrc.ws.send("warning('Unknown message type: " + msg.type + "')");
112 | } );
113 | jrc.ws.addEventListener( "close", function(event) {
114 | window.close()
115 | } );
116 |
117 | jrc.sendCommand = function(command) {
118 | jrc.ws.send(JSON.stringify(["COM", command]));
119 | }
120 |
121 | jrc.sendData = function(variableName, variable, internal) {
122 | jrc.ws.send(JSON.stringify(["DATA", variableName, JSON.stringify(variable), internal]));
123 | }
124 |
125 | //args must be object (to be converted to names list in R)
126 | jrc.callFunction = function(functionName, args, assingTo, package, internal) {
127 | jrc.ws.send(JSON.stringify(["FUN", functionName, JSON.stringify(args), assingTo, package, internal]));
128 | }
129 |
130 | jrc.notifyStorage = function(id) {
131 | alert("Your command has been stored. To execute it, please, run the 'authorize' function as it is shown in your R sesion. " +
132 | "Use functions 'allowVariables' and 'allowFunctions' to permit automatic execution of " +
133 | "your commands.")
134 | }
135 |
136 | //from https://mothereff.in/js-variables
137 | jrc.isValidName = function(name) {
138 | return name.search(/^(?!(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$)[$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc][$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc0-9\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19b0-\u19c0\u19c8\u19c9\u19d0-\u19d9\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1dc0-\u1de6\u1dfc-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f]*$/) + 1;
139 | }
140 |
141 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------