qz-tray
Version:
Connects a web client to the QZ Tray software. Enables printing and device communication from javascript.
1,648 lines (432 loc) • 20.5 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Namespace: websocket</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Namespace: websocket</h1>
<section>
<header>
<h2>
<span class="ancestors"><a href="qz.html">qz</a>.</span>websocket</h2>
</header>
<article>
<div class="container-overview">
<div class="description">Calls related specifically to the web socket connection.</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1206">line 1206</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id=".getNetworkInfo"><span class="type-signature">(static) </span>getNetworkInfo<span class="type-signature"></span></h4>
<dl class="details">
<dt class="important tag-deprecated">Deprecated:</dt><dd><ul class="dummy"><li>Since 2.1.0. Please use qz.networking.device() instead</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1404">line 1404</a>
</li></ul></dd>
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id=".connect"><span class="type-signature">(static) </span>connect<span class="signature">(options<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise.<(null|Error)>}</span></h4>
<div class="description">
Call to setup connection with QZ Tray on user's system.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last">Configuration options for the web socket connection.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>host</code></td>
<td class="type">
<span class="param-type">string</span>
|
<span class="param-type">Array.<string></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
['localhost', 'localhost.qz.io']
</td>
<td class="description last">Host running the QZ Tray software.</td>
</tr>
<tr>
<td class="name"><code>port</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
</td>
<td class="description last">Config options for ports to cycle.
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>secure</code></td>
<td class="type">
<span class="param-type">Array.<number></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
[8181, 8282, 8383, 8484]
</td>
<td class="description last">Array of secure (WSS) ports to try</td>
</tr>
<tr>
<td class="name"><code>insecure</code></td>
<td class="type">
<span class="param-type">Array.<number></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
[8182, 8283, 8384, 8485]
</td>
<td class="description last">Array of insecure (WS) ports to try</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="name"><code>usingSecure</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
true
</td>
<td class="description last">If the web socket should try to use secure ports for connecting.</td>
</tr>
<tr>
<td class="name"><code>keepAlive</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
60
</td>
<td class="description last">Seconds between keep-alive pings to keep connection open. Set to 0 to disable.</td>
</tr>
<tr>
<td class="name"><code>retries</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
0
</td>
<td class="description last">Number of times to reconnect before failing.</td>
</tr>
<tr>
<td class="name"><code>delay</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
0
</td>
<td class="description last">Seconds before firing a connection. Ignored if <code>options.retries</code> is 0.</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1241">line 1241</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(null|Error)></span>
</dd>
</dl>
<h4 class="name" id=".disconnect"><span class="type-signature">(static) </span>disconnect<span class="signature">()</span><span class="type-signature"> → {Promise.<(null|Error)>}</span></h4>
<div class="description">
Stop any active connection with QZ Tray.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1327">line 1327</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<(null|Error)></span>
</dd>
</dl>
<h4 class="name" id=".getConnectionInfo"><span class="type-signature">(static) </span>getConnectionInfo<span class="signature">()</span><span class="type-signature"> → {Object.<{socket: String, host: String, port: Number}>}</span></h4>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1411">line 1411</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Details of active websocket connection
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Object.<{socket: String, host: String, port: Number}></span>
</dd>
</dl>
<h4 class="name" id=".isActive"><span class="type-signature">(static) </span>isActive<span class="signature">()</span><span class="type-signature"> → {boolean}</span></h4>
<div class="description">
Check connection status. Active connection is necessary for other calls to run.
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1220">line 1220</a>
</li></ul></dd>
<dt class="tag-see">See:</dt>
<dd class="tag-see">
<ul>
<li>connect</li>
</ul>
</dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
If there is an active connection with QZ Tray.
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
<h4 class="name" id=".setClosedCallbacks"><span class="type-signature">(static) </span>setClosedCallbacks<span class="signature">(calls)</span><span class="type-signature"></span></h4>
<div class="description">
List of functions called for any connection closing event outside of an API call.<p/>
Also called when websocket#disconnect is called.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>calls</code></td>
<td class="type">
<span class="param-type">function</span>
|
<span class="param-type">Array.<function()></span>
</td>
<td class="description last">Single or array of <code>Function({Event} event)</code> calls.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1364">line 1364</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".setErrorCallbacks"><span class="type-signature">(static) </span>setErrorCallbacks<span class="signature">(calls)</span><span class="type-signature"></span></h4>
<div class="description">
List of functions called for any connections errors outside of an API call.<p/>
Also called if websocket#connect fails to connect.
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>calls</code></td>
<td class="type">
<span class="param-type">function</span>
|
<span class="param-type">Array.<function()></span>
</td>
<td class="description last">Single or array of <code>Function({Event} event)</code> calls.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1352">line 1352</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".setSurfDomain"><span class="type-signature">(static) </span>setSurfDomain<span class="signature">(surfDomain)</span><span class="type-signature"></span></h4>
<div class="description">
The domain to automagically append to non-qualified hosts, such as "qz.surf", or "example.com"
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>surfDomain</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="default">
"qz.surf"
</td>
<td class="description last">The domain to append to non-qualified hosts without a leading dot.</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-since">Since:</dt>
<dd class="tag-since"><ul class="dummy"><li>2.2.6</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1388">line 1388</a>
</li></ul></dd>
</dl>
<h4 class="name" id=".setUsingSurf"><span class="type-signature">(static) </span>setUsingSurf<span class="signature">(usingSurf)</span><span class="type-signature"></span></h4>
<div class="description">
Whether to append the "surf" domain (e.g. "qz.surf") to the end of non-qualified hosts (except "localhost")
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>usingSurf</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="default">
true
</td>
<td class="description last">Toggles automatic "surf" domain appending</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-since">Since:</dt>
<dd class="tag-since"><ul class="dummy"><li>2.2.6</li></ul></dd>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="qz-tray.js.html">qz-tray.js</a>, <a href="qz-tray.js.html#line1376">line 1376</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="qz.html">qz</a></li><li><a href="qz.api.html">api</a></li><li><a href="qz.configs.html">configs</a></li><li><a href="qz.file.html">file</a></li><li><a href="qz.hid.html">hid</a></li><li><a href="qz.networking.html">networking</a></li><li><a href="qz.printers.html">printers</a></li><li><a href="qz.security.html">security</a></li><li><a href="qz.serial.html">serial</a></li><li><a href="qz.socket.html">socket</a></li><li><a href="qz.usb.html">usb</a></li><li><a href="qz.websocket.html">websocket</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Apr 02 2026 13:01:02 GMT-0400 (Eastern Daylight Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>