# socket-livereload

> > livereload for socket.io + koa

Latest version **2.0.0** (published 2022-05-24) · 0 weekly downloads

## Install

```sh
npm install socket-livereload
pnpm add socket-livereload
yarn add socket-livereload
bun add socket-livereload
```

## 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 | 2.0.0 |
| Published | 2022-05-24 |
| First published | 2020-09-18 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | cenfun |

## Links

- npm: https://www.npmjs.com/package/socket-livereload
- Repository: https://github.com/cenfun/socket-livereload
- Homepage: https://github.com/cenfun/socket-livereload#readme
- Issues: https://github.com/cenfun/socket-livereload/issues
- npm.io page: https://npm.io/package/socket-livereload

## Recent versions

- 2.0.0 (latest) — 2022-05-24
- 1.0.1 — 2020-11-17
- 1.0.0 — 2020-09-18

## README

# socket-livereload
> livereload for socket.io + koa


## Install
```sh
npm install socket-livereload
```

## Usage

```js
const http = require("http");
const Koa = require("koa");
const KSR = require("koa-static-resolver");
const socketIO = require("socket.io");

const open = require("open");

const app = new Koa();
app.use(KSR({
    dirs: [
        "./test/client/",
        //for livereload
        "./node_modules/socket.io-client/dist/",
        //"./node_modules/socket-livereload/dist/",
        "./dist/"
    ],
    //max-age=<seconds>
    maxAge: 1,
    livereload: '\n<script src="/livereload.js" class="livereload" client="socket.io.min.js"></script>\n'
}));

const server = http.createServer(app.callback());
const io = socketIO(server);
io.on("connection", function(client) {
    client.on("data", function(data) {
    });
    client.on("disconnect", function() {
        console.log(`${new Date().toString()} a preview page disconnected`);
    });
    console.log(`${new Date().toString()} a preview page connected`);
});

const sockets = io.sockets;

const port = 8080;
server.listen(port, function() {
    const url = `http://localhost:${port}`;
    console.log(`${new Date().toString()} server started: ${url}`);
    open(url);
});


//test
const refreshHandler = function() {
    
    setTimeout(function() {

        sockets.emit("data", {
            message: "Show something ..."
        });

        setTimeout(function() {

            sockets.emit("data", {
                message: "Reloading for something ...",
                action: "reload"
            });
            refreshHandler();

        }, 3000);
        
    }, 3000);

};

refreshHandler();

```

## Test

```sh
npm run test
```

## Changelog

- 2.0.0
    - IE no longer supported

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