Skip to content

Commit

Permalink
Merge 695e333 into f58fcd3
Browse files Browse the repository at this point in the history
  • Loading branch information
lahsivjar committed Sep 20, 2018
2 parents f58fcd3 + 695e333 commit 2cf7c48
Show file tree
Hide file tree
Showing 3 changed files with 272 additions and 27 deletions.
261 changes: 261 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

- [SockJsClient][1]
- [Parameters][2]
- [connect][3]
- [disconnect][4]
- [sendMessage][5]
- [Parameters][6]
- [url][7]
- [options][8]
- [topics][9]
- [onConnect][10]
- [onDisconnect][11]
- [getRetryInterval][12]
- [Parameters][13]
- [onMessage][14]
- [Parameters][15]
- [headers][16]
- [subscribeHeaders][17]
- [autoReconnect][18]
- [debug][19]
- [heartbeat][20]
- [heartbeatIncoming][21]
- [heartbeatOutgoing][22]

## SockJsClient

[src/client.jsx:15-271][23]

**Extends React.Component**

- **See: [STOMP][24]**
- **See: [StompJS:][25]**

React component for SockJS-client with STOMP messaging protocol.

### Parameters

- `props`

**Meta**

- **version**: 4.0.0
- **author**: \[lahsivjar] (https&#x3A;//github.com/lahsivjar)

### connect

[src/client.jsx:224-229][26]

Connect to the server if not connected. Under normal circumstances component
will automatically try to connect to server. This method is mostly useful
after component is explicitly disconnected via [SockJsClient#disconnect][27].

### disconnect

[src/client.jsx:236-254][28]

Disconnect STOMP client and disable all reconnect.

### sendMessage

[src/client.jsx:264-270][29]

Send message to the specified topic.

#### Parameters

- `topic` **[string][30]** target topic to send message
- `msg` **[string][30]** message to send
- `opt_headers` **[Object][31]** additional headers for underlying STOMP client (optional, default `{}`)

## url

[src/client.jsx:32-32][32]

HTTP URL of the endpoint to connect.

## options

[src/client.jsx:38-38][33]

- **See: [SockJS-options][34]**

Additional options to pass to the underlying SockJS constructor.

## topics

[src/client.jsx:42-42][35]

Array of topics to subscribe to.

## onConnect

[src/client.jsx:46-46][36]

Callback after connection is established.

## onDisconnect

[src/client.jsx:50-50][37]

Callback after connection is lost.

## getRetryInterval

[src/client.jsx:56-56][38]

Gets called to find the time interval for next retry. Defaults to a function returing retryCount seconds.

### Parameters

- `retryCount` **[number][39]** number of retries for the current disconnect

## onMessage

[src/client.jsx:63-63][40]

Callback when a message is recieved.

### Parameters

- `msg` **([string][30] \| [Object][31])** message received from server, if JSON format then object
- `topic` **[string][30]** the topic on which the message was received

## headers

[src/client.jsx:67-67][41]

Headers that will be passed to the server or broker with STOMP's connection frame.

## subscribeHeaders

[src/client.jsx:71-71][42]

Headers that will be passed when subscribing to a destination.

## autoReconnect

[src/client.jsx:75-75][43]

Should the client try to automatically connect in an event of disconnection.

## debug

[src/client.jsx:79-79][44]

Enable debugging mode.

## heartbeat

[src/client.jsx:83-83][45]

Number of milliseconds to send and expect heartbeat messages.

## heartbeatIncoming

[src/client.jsx:87-87][46]

Number of milliseconds to expect heartbeat messages

## heartbeatOutgoing

[src/client.jsx:91-91][47]

Number of milliseconds to send heartbeat messages

[1]: #sockjsclient

[2]: #parameters

[3]: #connect

[4]: #disconnect

[5]: #sendmessage

[6]: #parameters-1

[7]: #url

[8]: #options

[9]: #topics

[10]: #onconnect

[11]: #ondisconnect

[12]: #getretryinterval

[13]: #parameters-2

[14]: #onmessage

[15]: #parameters-3

[16]: #headers

[17]: #subscribeheaders

[18]: #autoreconnect

[19]: #debug

[20]: #heartbeat

[21]: #heartbeatincoming

[22]: #heartbeatoutgoing

[23]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L15-L271 "Source code on GitHub"

[24]: https://stomp.github.io/

[25]: https://github.com/sockjs/sockjs-client

[26]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L224-L229 "Source code on GitHub"

[27]: #sockjsclientdisconnect

[28]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L236-L254 "Source code on GitHub"

[29]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L264-L270 "Source code on GitHub"

[30]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[31]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[32]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L32-L32 "Source code on GitHub"

[33]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L38-L38 "Source code on GitHub"

[34]: https://github.com/sockjs/sockjs-client#sockjs-client-api

[35]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L42-L42 "Source code on GitHub"

[36]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L46-L46 "Source code on GitHub"

[37]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L50-L50 "Source code on GitHub"

[38]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L56-L56 "Source code on GitHub"

[39]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number

[40]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L63-L63 "Source code on GitHub"

[41]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L67-L67 "Source code on GitHub"

[42]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L71-L71 "Source code on GitHub"

[43]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L75-L75 "Source code on GitHub"

[44]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L79-L79 "Source code on GitHub"

[45]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L83-L83 "Source code on GitHub"

[46]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L87-L87 "Source code on GitHub"

[47]: https://github.com/lahsivjar/react-stomp/blob/e38bebc6904a7e8bffc8f346022350c317ee666b/src/client.jsx#L91-L91 "Source code on GitHub"
34 changes: 8 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# react-stomp

[![Build Status](https://travis-ci.org/lahsivjar/react-stomp.svg?branch=master)](https://travis-ci.org/lahsivjar/react-stomp) [![Coverage Status](https://coveralls.io/repos/github/lahsivjar/react-stomp/badge.svg?branch=master)](https://coveralls.io/github/lahsivjar/react-stomp?branch=master) [![License](https://img.shields.io/npm/l/react-stomp.svg)](https://github.com/lahsivjar/react-stomp/blob/master/LICENSE) [![Greenkeeper badge](https://badges.greenkeeper.io/lahsivjar/react-stomp.svg)](https://greenkeeper.io/)

React component for [SockJS-client](https://github.com/sockjs/sockjs-client) with [STOMP](https://stomp.github.io/) messaging protocol.
Expand Down Expand Up @@ -37,43 +38,24 @@ class SampleComponent extends React.Component {
```

## Demonstration
https://react-websocket.herokuapp.com/index

A working implementation using [Spring Boot](https://projects.spring.io/spring-boot/) and [react-talk](https://github.com/lahsivjar/react-talk) can be found at https://github.com/lahsivjar/spring-websocket-template/tree/master/with-sockjs

## Parameters

* `url`: HTTP URL of the websocket endpoint to connect
* `topics`: An array of topics to subscribe
* `onMessage`: Callback when a message is recieved
* `onConnect`: Callback after connection is established
* `heartbeat`: Number of milliseconds to send and expect heartbeat messages
* `heartbeatIncoming`: Number of milliseconds to expect heartbeat messages
* `heartbeatOutgoing`: Number of milliseconds to send heartbeat messages
* `onDisconnect`: Callback after connection is lost
* `getRetryInterval`: Function property which takes a number parameter indicating the retry count for a particular disconnection and returns another number specifying the interval for next retry (will be ignored if auto reconnect is false, defaults to `retryCount` seconds)
* `headers`: Headers that will be passed to the server or broker with connection request
* `subscribeHeaders`: Headers that will be passed when subscribing to a destination
* `autoReconnect`: boolean indicating if retry should be attempted in an event of loosing connection (defaults to `true`)
* `debug`: Enable debugging mode (defaults to `false`)
<https://react-websocket.herokuapp.com/index>

## API
A working implementation using [Spring Boot](https://projects.spring.io/spring-boot/) and [react-talk](https://github.com/lahsivjar/react-talk) can be found at <https://github.com/lahsivjar/spring-websocket-template/tree/master/with-sockjs>

* `sendMessage(topic, msg, opt_headers)`: Send message to the specified topic
* `disconnect`: Disconnect STOMP client without any reconnection attempt
* `connect`: Try connecting to server (useful if `disconnect` is called explicitly before)
## [API Docs](API.md)

## Issues

Report any issues or bugs to https://github.com/lahsivjar/react-stomp/issues
Report any issues or bugs to <https://github.com/lahsivjar/react-stomp/issues>

## Changelog

### 4.0.0

- Improve test coverage
- [BugFix #61] Add support for receiving plain text messages
- [BugFix #70] Fix reconnect loop under certain circumstances even after disconnect is called
- Improve test coverage
- [BugFix #61] Add support for receiving plain text messages
- [BugFix #70] Fix reconnect loop under certain circumstances even after disconnect is called

## License

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"e2e-test": "npm run lint && mocha --require babel-core/register --require test/bootstrap.js --recursive test/e2e --exit",
"all-test": "npm run lint && nyc mocha --require babel-core/register --require test/bootstrap.js --recursive test --exit",
"build": "babel src --out-dir dist",
"coverage": "nyc report --reporter=text-lcov | coveralls"
"coverage": "nyc report --reporter=text-lcov | coveralls",
"docs": "documentation build src/* -f md --github > API.md"
},
"repository": {
"type": "git",
Expand All @@ -42,6 +43,7 @@
"babel-preset-react": "^6.24.1",
"chai": "^4.1.2",
"coveralls": "^3.0.2",
"documentation": "^8.1.2",
"enzyme": "^3.6.0",
"enzyme-adapter-react-16": "^1.5.0",
"eslint": "^5.5.0",
Expand Down

0 comments on commit 2cf7c48

Please sign in to comment.