# gulp-websocket-server

> gulp-websocket-server

Latest version **1.1.2** (published 2017-04-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install gulp-websocket-server
pnpm add gulp-websocket-server
yarn add gulp-websocket-server
bun add gulp-websocket-server
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2017-04-04 |
| First published | 2017-04-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | zengxuebing |
| Maintainers | zengxuebing |
| Keywords | gulp, websocket, gulp-websocket-server |

## Links

- npm: https://www.npmjs.com/package/gulp-websocket-server
- Repository: https://github.com/SimonTart/gulp-websocket-server
- Homepage: https://github.com/SimonTart/gulp-websocket-server#readme
- Issues: https://github.com/SimonTart/gulp-websocket-server/issues
- npm.io page: https://npm.io/package/gulp-websocket-server

## Dependencies (2)

- [ws](https://npm.io/package/ws.md) ^2.2.2
- [through2](https://npm.io/package/through2.md) ^2.0.3

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2017-04-04
- 1.1.1 — 2017-04-04
- 1.1.0 — 2017-04-04
- 1.0.0 — 2017-04-04
- 0.0.1 — 2017-04-02

## README

### gulp-websocket-server
[English](./README.md) | [中文](./zh.md)

The main purpose of this plugn is to open a websocket service in gulp, and then send the message to the client who has already created the link when the file changes.

#### Install
```
npm install --save-dev gulp-websocket-server
```
#### Usage
##### How use in gulp
```js
const gulp = require('gulp');
const gulpWss = require('gulp-websocket-server');
const serverConfig = {
    port: 4000,
    path: '/ws'
};
//build a websocket server in gulp
let wss = gulpWss(serverConfig);

//
gulp.task('js',() => {
    return gulp.src('./*.js')
                .pipe(wss.liverealod('relaod'));//use method livereload send message: 'reload'
});
gulp.task('send',() => {
    wss.send('reload');//use method send to send message:'reload'
});
```
websocket server's creation configuration refer to [ws](https://github.com/websockets/ws/blob/master/doc/ws.md).

Webscoket server's instance has `livereload` and `send` methods,they all can send message to client.`livereload`only can be used in gulp's pipe.`send`can be use directly.They both has only one parameter that is message needed to be sent.The default value for this parameter `file change`

##### How to use in client
You can build link like above and wait for message and then do what you want do.
```js
const ws = new WebScoket('ws://localhost:yourport/yourpath');
ws.addEventListener('error', err => {
    console.log('encounter some error');
});
ws.addEventListener('message',event =>{
    if(event.data === 'message'){
        //do what you want
    }
});
```

---
_Source: https://npm.io/package/gulp-websocket-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
