Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pladaria/html5-websocket
HTML5 WebSocket for node.js
https://github.com/pladaria/html5-websocket
Last synced: about 2 months ago
JSON representation
HTML5 WebSocket for node.js
- Host: GitHub
- URL: https://github.com/pladaria/html5-websocket
- Owner: pladaria
- License: mit
- Created: 2016-03-13T22:33:52.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-09-30T17:47:42.000Z (over 6 years ago)
- Last Synced: 2024-02-27T19:04:03.300Z (10 months ago)
- Language: JavaScript
- Size: 53.7 KB
- Stars: 8
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# DEPRECATED
:warning: **Consider this library as deprecated. It was created to expose `ws` with a `WebSocket` interface. This is no longer needed because latest versions of `ws` already implement this interface.**
---
# html5-websocket
This module implements the standard [HTML5 WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) as a thin layer over the great [ws](https://www.npmjs.com/package/ws) library.
The motivation behind this module is to be able to write WebSocket based libraries that will run without changes in Node.js, Browsers or React Native apps.
## Install
```bash
npm install --save html5-websocket
```## Usage
The API is the same as the standard HTML5 Socket API so nothing new here...
```javascript
const WebSocket = require('html5-websocket');const ws = new WebSocket('ws://html5rocks.websocket.org/echo');
ws.onopen = function () {
ws.send('Hello!');
};ws.onmessage = function (e) {
console.log(e.data);
};ws.onerror = function (error) {
console.log('Fail:', error);
};
```You can also use the DOM Level 2 Event Model
```javascript
const handleMessage = function (e) {
console.log(e.data);
};// add listener
ws.addEventListener('message', handleMessage);// remove listener
ws.removeEventListener('message', handleMessage);
```## License
MIT