# gulp-ws-server

> A simple gulp websocket server

Latest version **1.0.9** (published 2019-01-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install gulp-ws-server
pnpm add gulp-ws-server
yarn add gulp-ws-server
bun add gulp-ws-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.0.9 |
| Published | 2019-01-02 |
| First published | 2019-01-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 2.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | M. Donkers |
| Maintainers | donkie9999 |
| Keywords | ws, websocket, wsclient, wsserver, gulp |

## Links

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

## Dependencies (2)

- [ws](https://npm.io/package/ws.md) ^6.1.2
- [fancy-log](https://npm.io/package/fancy-log.md) ^1.3.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.0.9 (latest) — 2019-01-02

## README

# gulp-ws-server
A simple gulp (> 4.x) websocket server.

#### Installation
```$xslt
npm install --save-dev gulp-ws-server
```

#### Usage (with gulp.task)
```js
const gulp = require('gulp');
const ws = require('gulp-ws-server');

// start an instance of websocket server
let wss = ws({
    port: 3000,
    path: '/myWS'
});

// send a message
gulp.task('send', () => {
  wss.send('refresh')
})
```

#### Usage (with gulp.watch)
gulp expects a valid stream back, we use `through2` to return the gulp stream without writing out or process any function.
```js
const gulp = require('gulp');
const ws = require('gulp-ws-server');
const through2 = require('through2');

// start an instance of websocket server
let wss = ws({
    port: 3000,
    path: '/myWS'
});

gulp.task('reload-browser', () => {
  wss.send('refresh');
  return gulp
    .src(__filename)
    .pipe(through2({objectMode: true}))
});

gulp.watch("less/**/*.less", gulp.series('less', 'reload-browser'));

```
#### Client implementation (example: refresh page on gulp task)
```js
if ("WebSocket" in window) {
  let ws = new WebSocket("ws://localhost:3000/myWS");
  ws.onmessage = function(e) {
    if (e.data === "refresh") {
      window.top.location.reload();
    }
  };
}
```

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