forked from igorw/buster-docs
/
client.html
87 lines (84 loc) · 3.36 KB
/
client.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<h1><code>buster.client</code></h1>
<dl>
<dt>Version</dt>
<dd>See <a href="/buster-client/">buster-client</a></dd>
<dt>Module</dt>
<dd><code>require("buster-client").client;</code></dd>
<dt>In browsers</dt>
<dd>N/A</dd>
</dl>
<p>
The client creates a <a href="/buster-client/session/">session</a> given some
<a href="/buster-configuration/">configuration</a>.
</p>
<div class="section">
<h2 id="methods">Methods</h2>
<h3 id="create" data-title="+create(port, host, path);+"><code>var client = buster.client.create(port, host, path);</code></h3>
<p>
Create a new client. Arguments are strings and describes where to find a
running <a href="/buster-capture-server/">buster-capture-server</a>.
</p>
<h3 id="createSession" data-title="+createSession(config);+">
<code>var promise = client.createSession(<a href="#options">options</a>);</code>
</h3>
<p>
Creates and runs a new session on the server. The provided resource set
determines what resources to make available, and which to load by
default. If the client's
<a href="#cacheResources"><code>cacheResources</code></a> property is
<code>true</code> (default), cached resources will be used when possible.
</p>
<p>
The returned promise is resolved with a
<a href="/buster-client/session/">buster-client/session</a> object when
the session is ready.
</p>
<pre><code>var buster = require("buster-client");
var sessionConfig = buster.sessionConfig.create();
sessionConfig.addResource("/src/1.js", {
content: "alert('Hello world');"
});
sessionConfig.load("/src/1.js");
var client = buster.client.create(1111, "localhost");
client.createSession(sessionConfig).then(function (<a href="/buster-client/session/">session</a>) {
// Use session
});</code></pre>
<h3 id="getCachedResources" data-title="+getCachedResources();+">
<code>var promise = client.getCachedResources();</code>
</h3>
<p>
Fetches a list of resources cached on the server. These can optionally be
reused if their content has not changed. The returned promise is resolved
with a <a href="#cachedResources"><code>cachedResources</code></a> object when ready.
</p>
<h3 id="useCachedResources" data-title="+useCachedResources(config);+"><code>var promise = client.useCachedResources(<a href="/buster-client/session-config/#formatted-session-config">config</a>);</code></h3>
<p>
Tweak the session configuration to use cached resources where possible.
</p>
</div>
<div class="section">
<h2 id="properties">Properties</h2>
<h3 id="useCache" data-title="+useCache+">
<code>useCache</code> (<code>true</code>)
</h3>
<p>
If <code>true</code> (default), <code>createSession</code> will exclude
cached resources from the session configuration prior to contacting the
server. Potentially allows for huge performance wins.
</p>
</div>
<div class="section">
<h2 id="supporting-objects">Supporting objects</h2>
<h3 id="cachedResources"><code>cachedResources</code></h3>
<p>
An object describing what resources are available on the server, and in what
versions. The server may cache resources at the same path several times with
different etags. The object has pathnames for keys, and each value is an
array of available etags as strings.
</p>
<h4>Example</h4>
<pre><code>{
"/src/1.js": ["c141b24", "8761944"],
"/src/2.js": ["bac985c"]
}</code></pre>
</div>