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
Promise
with 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 cmd
string Name of received command
message
object 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 event
OpenEvent 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 event
ErrorEvent 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 event
CloseEvent 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 cmd
string Name of command to send
params
object <optional>
Parameters of command to send
cb
ZeroFrame#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 cmd
string Name of command to send
params
object <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 cmd
number Message ID to response
result
object 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 result
object | 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 multiuser
object <optional>
Multiuser options
Properties
Name Type Argument Default Description masterAddress
string <optional>
null Master address for multiuser ZeroNet instance
masterSeed
string <optional>
null Master seed for multiuser ZeroNet instance
instance
object <optional>
Instance options
Properties
Name Type Argument Default Description host
string <optional>
127.0.0.1 Host of ZeroNet instance
port
number <optional>
43110 Port of ZeroNet instance
secure
boolean <optional>
false Secure connection of ZeroNet instance
show
object <optional>
Showing options
Properties
Name Type Argument Default Description log
boolean <optional>
false Show log messages in console
error
boolean <optional>
false Show error messages in console
reconnect
object <optional>
Reconnecting options
Properties
Name Type Argument Default Description attempts
number <optional>
-1 Number of attempts (no limit with
-1
& no reconnect with0
)delay
number <optional>
5000 Number of delay in milliseconds