new ZeroFrame(site [, options])
Construct the class and set up a connection to the WebSocket server.
Parameters:
| Name | Type | Argument | Default | Description |
|---|---|---|---|---|
site |
string | Target ZeroNet site address |
||
options |
ZeroFrame#constructorOptions |
<optional> |
ZeroFrame#constructorOptions | Client options |
Members
-
proxy :Proxy
-
Proxy for accessing ZeroFrame commands.
Command name is accepted as an object's property and parameters are accepted as a method's arguments. Command returns
Promisewith the result.- Command with no arguments can be accessed with
zeroframe.proxy.cmdName(). - Command with keyword arguments can be accessed with
zeroframe.proxy.cmdName({key1: value1, key2: value2}). - Command with normal arguments can be accessed with
zeroframe.proxy.cmdName(value1, value2).
Type:
- Proxy
- Command with no arguments can be accessed with
Methods
-
init()
-
User-based initialization code.
Returns:
- Type
- ZeroFrame
-
onRequest(cmd, message)
-
User-based on request handler.
It is triggered on every message from the WebSocket server. It can be used to add additional functionalities to the client or handle received messages.
Parameters:
Name Type Description cmdstring Name of received command
messageobject Message of received command
Returns:
- Type
- void
-
onOpenWebsocket(event)
-
User-based on open websocket handler.
It is triggered when the WebSocket connection is opened. It can be used to notify user or check for server details.
Parameters:
Name Type Description eventOpenEvent Open event from the WebSocket library
Returns:
- Type
- void
-
onErrorWebsocket(event)
-
User-based on error websocket handler.
It is triggered on the WebSocket error. It can be used to notify user or display errors.
Parameters:
Name Type Description eventErrorEvent Error event from the WebSocket library
-
onCloseWebsocket(event)
-
User-based on close websocket handler.
It is triggered when the WebSocket connection is closed. It can be used to notify user or display connection error.
Parameters:
Name Type Description eventCloseEvent Close event from the WebSocket library
-
log(args)
-
Add log to console if enabled.
Parameters:
Name Type Argument Description args* <repeatable>
Logs to add to console
Returns:
- Type
- void
-
error(args)
-
Add error to console if enabled.
Parameters:
Name Type Argument Description args* <repeatable>
Errors to add to console
Returns:
- Type
- void
-
cmd(cmd [, params] [, cb])
-
Send command to ZeroFrame server and call callback.
Parameters:
Name Type Argument Default Description cmdstring Name of command to send
paramsobject <optional>
Parameters of command to send
cbZeroFrame#cmdCallback <optional>
null Command callback
Returns:
- Type
- void
-
cmdp(cmd [, params])
-
Send command to ZeroFrame server and return the result as promise.
In most cases, the result will be object which contains data. Some commands don't have any result. In this case, the result will probably be string
ok.Parameters:
Name Type Argument Description cmdstring Name of command to send
paramsobject <optional>
Parameters of command to send
- Source:
- See:
Returns:
Command response
- Type
- Promise.<(object|string)>
-
response(cmd, result)
-
Response to ZeroFrame message.
Parameters:
Name Type Description cmdnumber Message ID to response
resultobject Result to send
Returns:
- Type
- void
-
close()
-
Close websocket connection.
Returns:
- Type
- void
Type Definitions
-
cmdCallback( [result])
-
Callback with command result.
Result will depend on called command.
In most cases, the result will be object which contains data. Some commands don't have any result. In this case, the result will probably be string
ok.Parameters:
Name Type Argument Description resultobject | string <optional>
Result from command
- Source:
- See:
Returns:
- Type
- void
-
constructorOptions
-
Constructor's options structure with default values.
Type:
- object
- Source:
Properties:
Name Type Argument Description multiuserobject <optional>
Multiuser options
Properties
Name Type Argument Default Description masterAddressstring <optional>
null Master address for multiuser ZeroNet instance
masterSeedstring <optional>
null Master seed for multiuser ZeroNet instance
instanceobject <optional>
Instance options
Properties
Name Type Argument Default Description hoststring <optional>
127.0.0.1 Host of ZeroNet instance
portnumber <optional>
43110 Port of ZeroNet instance
secureboolean <optional>
false Secure connection of ZeroNet instance
showobject <optional>
Showing options
Properties
Name Type Argument Default Description logboolean <optional>
false Show log messages in console
errorboolean <optional>
false Show error messages in console
reconnectobject <optional>
Reconnecting options
Properties
Name Type Argument Default Description attemptsnumber <optional>
-1 Number of attempts (no limit with
-1& no reconnect with0)delaynumber <optional>
5000 Number of delay in milliseconds