Comparing version 0.0.1-12 to 0.0.1-13
@@ -6,2 +6,3 @@ import { createServer } from 'http'; | ||
import { Tunnel, TunnelClient } from '../tunnel.js'; | ||
const PING_INTERVAL = 5000; | ||
const HOST_DEFAULT = 'localhost'; | ||
@@ -49,3 +50,7 @@ const PORT_DEFAULT = 12368; | ||
this.addClient(client); | ||
ws.on('close', () => this.removeClient(client)); | ||
const pingInterval = setInterval(() => ws.ping(), PING_INTERVAL); | ||
ws.on('close', () => { | ||
clearInterval(pingInterval); | ||
this.removeClient(client); | ||
}).on('error', () => ws.close()); | ||
} | ||
@@ -52,0 +57,0 @@ } |
@@ -5,2 +5,3 @@ import DiffMatchPatch from 'diff-match-patch'; | ||
const WS_URL = location.href.replace(/^http/, 'ws'); | ||
const INITIAL_CONNECT_DELAY = 1000; | ||
const RECONNECT_INTERVAL = 1000; | ||
@@ -12,3 +13,3 @@ const dmp = new DiffMatchPatch(); | ||
document.addEventListener('visibilitychange', () => updateTitle()); | ||
connect(); | ||
setTimeout(() => connect(), INITIAL_CONNECT_DELAY); | ||
function connect() { | ||
@@ -15,0 +16,0 @@ const ws = new WebSocket(WS_URL); |
{ | ||
"name": "backpage", | ||
"version": "0.0.1-12", | ||
"version": "0.0.1-13", | ||
"description": "Naive static HTML streaming based on React for Node.js CLI applications.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/vilicvane/backpage.git", |
@@ -20,2 +20,3 @@ [![NPM version](https://img.shields.io/npm/v/backpage?color=%23cb3837&style=flat-square)](https://www.npmjs.com/package/backpage) | ||
- Send notification to browser. | ||
- Public URL via [backpage.cloud](https://backpage.cloud). | ||
@@ -68,2 +69,17 @@ ## Installation | ||
You can also use [backpage.cloud](https://backpage.cloud) to get a public URL for your page: | ||
```ts | ||
import {randomUUID} from 'crypto'; | ||
const page = new BackPage({ | ||
token: randomUUID(), // Any random UUID would work. | ||
name: 'project-name', | ||
}); | ||
await page.guide(); | ||
``` | ||
> **Note:** [backpage.cloud](https://backpage.cloud) would probably limit the traffic for free users and introduce paid services in the future. | ||
## Notify Fallback | ||
@@ -70,0 +86,0 @@ |
@@ -17,2 +17,4 @@ import type {Server} from 'http'; | ||
const PING_INTERVAL = 5000; | ||
const HOST_DEFAULT = 'localhost'; | ||
@@ -73,3 +75,8 @@ const PORT_DEFAULT = 12368; | ||
ws.on('close', () => this.removeClient(client)); | ||
const pingInterval = setInterval(() => ws.ping(), PING_INTERVAL); | ||
ws.on('close', () => { | ||
clearInterval(pingInterval); | ||
this.removeClient(client); | ||
}).on('error', () => ws.close()); | ||
} | ||
@@ -76,0 +83,0 @@ } |
@@ -14,2 +14,4 @@ import DiffMatchPatch from 'diff-match-patch'; | ||
const INITIAL_CONNECT_DELAY = 1000; | ||
const RECONNECT_INTERVAL = 1000; | ||
@@ -27,3 +29,3 @@ | ||
connect(); | ||
setTimeout(() => connect(), INITIAL_CONNECT_DELAY); | ||
@@ -30,0 +32,0 @@ function connect(): void { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
204127
4661
148