Skip to content

Commit

Permalink
Merge pull request #23 from dillon-sellars/feature/closeEvent
Browse files Browse the repository at this point in the history
Add closeEventCallback to expose the websocket CloseEvent so that the
  • Loading branch information
kum-deepak authored Feb 11, 2018
2 parents c70e56a + dd529f6 commit 30c35a3
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 62 deletions.
1 change: 1 addition & 0 deletions docs-src/Contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ names. So, running both together may cause unexpected failures._
## Submit pull requests
* Run `cake build` to update generated files
* Please follow GitHub guidelines. Raise an issue if you are unclear.
## STOMP API
Expand Down
10 changes: 7 additions & 3 deletions docs-src/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,26 @@ API to use in most cases:
```javascript
client.connect(login, passcode, connectCallback);
client.connect(login, passcode, connectCallback, errorCallback);
client.connect(login, passcode, connectCallback, errorCallback, host);
client.connect(login, passcode, connectCallback, errorCallback, closeEventCallback);
client.connect(login, passcode, connectCallback, errorCallback, closeEventCallback, host);
```

where `login`, `passcode` and `host` are strings. `connectCallback` and
`errorCallback` are functions which will receive a `Frame` as argument.
`errorCallback` is a function which will receive a `Frame` as argument and
`closeEventCallback` is a function which will receive a [CloseEvent](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent)

The `connect()` method also accepts two other variants if you need
to pass additional headers:

```javascript
client.connect(headers, connectCallback);
client.connect(headers, connectCallback, errorCallback);
client.connect(headers, connectCallback, errorCallback, closeEventCallback);
```

where `header` is a `map`. `connectCallback` and
`errorCallback` are functions which will receive a `Frame` as argument.
`errorCallback` is a function which will receive a `Frame` as argument and
`closeEventCallback` is a function which will receive a [CloseEvent](https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent)


Please note that if you use these forms, you will typically add `login`,
Expand Down
10 changes: 5 additions & 5 deletions docs/codo/alphabetical_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ <h2>Extra File Listing</h2>
docs-src&#47;Contribute.md
</a>
</li>
<li>
<a href='extra/docs-src/sockjs.md.html' title='docs-src/sockjs.md'>
docs-src&#47;sockjs.md
</a>
</li>
<li>
<a href='extra/docs-src/STOMP-brokers.md.html' title='docs-src/STOMP-brokers.md'>
docs-src&#47;STOMP-brokers.md
Expand All @@ -49,11 +54,6 @@ <h2>Extra File Listing</h2>
docs-src&#47;Usage.md
</a>
</li>
<li>
<a href='extra/docs-src/sockjs.md.html' title='docs-src/sockjs.md'>
docs-src&#47;sockjs.md
</a>
</li>
<li>
<a href='extra/LICENSE.txt.html' title='LICENSE.txt'>
LICENSE.txt
Expand Down
27 changes: 25 additions & 2 deletions docs/codo/class/Client.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,11 @@ <h3>Parameters:</h3>
<br>
~
(void)
<b>connect</b><span>(login, passcode, connectCallback, errorCallback, host)</span>
<b>connect</b><span>(login, passcode, connectCallback, errorCallback, closeEventCallback)</span>
<br>
~
(void)
<b>connect</b><span>(login, passcode, connectCallback, errorCallback, closeEventCallback, host)</span>
<br>
</p>
<div class='docstring'>
Expand Down Expand Up @@ -322,6 +326,16 @@ <h3>Parameters:</h3>
&mdash;
<span class='desc'>Optional, called upon an error. The passed paramer may be a <a href='../class/Frame.html'>Frame</a> or a message </span>
</li>
<li>
<span class='name'>closeEventCallback</span>
<span class='type'>
(
<tt>function(CloseEvent)</tt>
)
</span>
&mdash;
<span class='desc'>Optional, called when the websocket is closed. </span>
</li>
<li>
<span class='name'>login</span>
<span class='type'>
Expand Down Expand Up @@ -429,7 +443,16 @@ <h3>Overloads:</h3>
<p class='signature'>
~
(void)
<b>connect</b><span>(login, passcode, connectCallback, errorCallback, host)</span>
<b>connect</b><span>(login, passcode, connectCallback, errorCallback, closeEventCallback)</span>
</p>
<div class='tags'>
</div>
</div>
<div class='overload'>
<p class='signature'>
~
(void)
<b>connect</b><span>(login, passcode, connectCallback, errorCallback, closeEventCallback, host)</span>
</p>
<div class='tags'>
</div>
Expand Down
9 changes: 9 additions & 0 deletions docs/codo/extra/docs-src/Contribute.md.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ <h2 id="setup-a-stomp-broker">Setup a Stomp broker</h2>
<li>Edit <code>tests/config/browser-config.js</code> and <code>tests/config/node-config.js</code> as per
your setup. Defaults should work for a RabbitMQ default setup on localhost.</li>
<li>Please note that in RabbitMQ you will need to enable Stomp and WebStomp plugins.</li>
<li>A RabbitMQ Dockerfile is provided with the necessary plugins. To use it, run:<ul>
<li><code>docker build -t myrabbitmq .</code></li>
<li><code>docker run -d -p 15674:15674 myrabbitmq</code></li>
</ul>
</li>
</ul>
<h2 id="building-and-testing">Building and testing</h2><p>To build JavaScript from the CoffeeScript source code:</p><pre><code class="lang-bash">$ cake build
</code></pre><p>To run tests using nodejs:</p><pre><code class="lang-bash">$ cake test
Expand All @@ -108,9 +113,13 @@ <h2 id="browser-tests">Browser Tests</h2>
<ul>
<li>Browser and node environments use the same set of test cases.</li>
<li>Open <code>test/index.html</code> in your browser.</li>
<li>If Chrome fails with &quot;Uncaught DOMException: Failed to read the &#39;sessionStorage&#39; property from &#39;Window&#39;
you need to <a href="https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document">Unblock third-party cookies</a>
or use Firefox. </li>
</ul><p><em><strong>Caution:</strong> As both browser and nodejs use same set of test cases and hence same queue
names. So, running both together may cause unexpected failures.</em></p><h2 id="submit-pull-requests">Submit pull requests</h2>
<ul>
<li>Run <code>cake build</code> to update generated files</li>
<li>Please follow GitHub guidelines. Raise an issue if you are unclear.</li>
</ul>
<h2 id="stomp-api">STOMP API</h2><p>STOMP over WebSocket provides a straightforward mapping from a STOMP frame
Expand Down
13 changes: 8 additions & 5 deletions docs/codo/extra/docs-src/Usage.md.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ <h3 id="in-nodejs">In NodeJS</h3>
<h2 id="create-a-stomp-client">Create a STOMP client</h2><p>STOMP JavaScript clients will communicate to a STOMP server using a <code>ws://</code> URL.</p><p>To create a STOMP client JavaScript object, you need to call <code>Stomp.client(url)</code>
with the URL corresponding to the server&#39;s WebSocket endpoint:</p><pre><code class="lang-javascript"> var url = &quot;ws://localhost:15674/ws&quot;;
var client = Stomp.client(url);
</code></pre><p>The Stomp.client(url, protocols) can also be used to override the
default subprotocols provided by the library:
</code></pre><p>The Stomp.client(url, protocols) can also be used to override the </p><p>default subprotocols provided by the library:
[&#39;v10.stomp&#39;, &#39;v11.stomp&#39;, &#39;v12.stomp&#39;] (for STOMP 1.0, 1.1, &amp; 1.2
specifications). This second argument can either be a single string
or an array of strings to specify multiple subprotocols.</p><p><strong>Notes:</strong> </p><ul>
Expand Down Expand Up @@ -101,13 +100,17 @@ <h2 id="connection-to-the-server">Connection to the server</h2><p>Once a STOMP c
</code></pre><p>The <code>connect()</code> method accepts different number of arguments to provide a simple
API to use in most cases:</p><pre><code class="lang-javascript"> client.connect(login, passcode, connectCallback);
client.connect(login, passcode, connectCallback, errorCallback);
client.connect(login, passcode, connectCallback, errorCallback, host);
client.connect(login, passcode, connectCallback, errorCallback, closeEventCallback);
client.connect(login, passcode, connectCallback, errorCallback, closeEventCallback, host);
</code></pre><p>where <code>login</code>, <code>passcode</code> and <code>host</code> are strings. <code>connectCallback</code> and
<code>errorCallback</code> are functions which will receive a <code>Frame</code> as argument.</p><p>The <code>connect()</code> method also accepts two other variants if you need
<code>errorCallback</code> is a function which will receive a <code>Frame</code> as argument and
<code>closeEventCallback</code> is a function which will receive a <a href="https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent">CloseEvent</a></p><p>The <code>connect()</code> method also accepts two other variants if you need
to pass additional headers:</p><pre><code class="lang-javascript"> client.connect(headers, connectCallback);
client.connect(headers, connectCallback, errorCallback);
client.connect(headers, connectCallback, errorCallback, closeEventCallback);
</code></pre><p>where <code>header</code> is a <code>map</code>. <code>connectCallback</code> and
<code>errorCallback</code> are functions which will receive a <code>Frame</code> as argument.</p><p>Please note that if you use these forms, you will typically add <code>login</code>,
<code>errorCallback</code> is a function which will receive a <code>Frame</code> as argument and
<code>closeEventCallback</code> is a function which will receive a <a href="https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent">CloseEvent</a></p><p>Please note that if you use these forms, you will typically add <code>login</code>,
<code>passcode</code> (and <code>host</code>) headers yourself:</p><pre><code class="lang-javascript"> var headers = {
login: &#39;mylogin&#39;,
passcode: &#39;mypasscode&#39;,
Expand Down
10 changes: 5 additions & 5 deletions docs/codo/extra_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ <h1 class='full_list_header'>File List</h1>
Contribute.md
</a>
</li>
<li>
<a href='extra/docs-src/sockjs.md.html' target='main'>
sockjs.md
</a>
</li>
<li>
<a href='extra/docs-src/STOMP-brokers.md.html' target='main'>
STOMP-brokers.md
Expand All @@ -68,11 +73,6 @@ <h1 class='full_list_header'>File List</h1>
Usage.md
</a>
</li>
<li>
<a href='extra/docs-src/sockjs.md.html' target='main'>
sockjs.md
</a>
</li>
</ul>

<li>
Expand Down
2 changes: 1 addition & 1 deletion docs/codo/javascript/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 23 additions & 22 deletions lib/stomp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 30c35a3

Please sign in to comment.