Comparing version 3.0.0-alpha.12 to 3.0.0-alpha.13
@@ -43,3 +43,3 @@ import EventEmitter from './events.js'; | ||
this.opening = null; | ||
this.lastActivity = new Date().getTime(); | ||
this.lastActivity = Date.now(); | ||
this.callTimeout = options.callTimeout || CALL_TIMEOUT; | ||
@@ -90,3 +90,3 @@ this.pingInterval = options.pingInterval || PING_INTERVAL; | ||
if (data === '{}') return; | ||
this.lastActivity = new Date().getTime(); | ||
this.lastActivity = Date.now(); | ||
let packet; | ||
@@ -225,3 +225,3 @@ try { | ||
if (this.active) { | ||
const interval = new Date().getTime() - this.lastActivity; | ||
const interval = Date.now() - this.lastActivity; | ||
if (interval > this.pingInterval) this.send('{}'); | ||
@@ -253,3 +253,3 @@ } | ||
if (!this.connected) return; | ||
this.lastActivity = new Date().getTime(); | ||
this.lastActivity = Date.now(); | ||
this.socket.send(data); | ||
@@ -272,3 +272,3 @@ } | ||
send(data) { | ||
this.lastActivity = new Date().getTime(); | ||
this.lastActivity = Date.now(); | ||
fetch(this.url, { | ||
@@ -275,0 +275,0 @@ method: 'POST', |
@@ -41,3 +41,3 @@ 'use strict'; | ||
this.opening = null; | ||
this.lastActivity = new Date().getTime(); | ||
this.lastActivity = Date.now(); | ||
this.callTimeout = options.callTimeout || CALL_TIMEOUT; | ||
@@ -86,3 +86,3 @@ this.pingInterval = options.pingInterval || PING_INTERVAL; | ||
if (data === '{}') return; | ||
this.lastActivity = new Date().getTime(); | ||
this.lastActivity = Date.now(); | ||
let packet; | ||
@@ -220,3 +220,3 @@ try { | ||
if (this.active) { | ||
const interval = new Date().getTime() - this.lastActivity; | ||
const interval = Date.now() - this.lastActivity; | ||
if (interval > this.pingInterval) this.send('{}'); | ||
@@ -248,3 +248,3 @@ } | ||
if (!this.connected) return; | ||
this.lastActivity = new Date().getTime(); | ||
this.lastActivity = Date.now(); | ||
this.socket.send(data); | ||
@@ -267,3 +267,3 @@ } | ||
send(data) { | ||
this.lastActivity = new Date().getTime(); | ||
this.lastActivity = Date.now(); | ||
fetch(this.url, { | ||
@@ -270,0 +270,0 @@ method: 'POST', |
@@ -55,3 +55,3 @@ 'use strict'; | ||
if (!event) return; | ||
if (event.has(fn)) event.delete(fn); | ||
event.delete(fn); | ||
} | ||
@@ -58,0 +58,0 @@ |
@@ -62,3 +62,3 @@ 'use strict'; | ||
transport.server.clients.add(this); | ||
transport.on('close', () => { | ||
transport.once('close', () => { | ||
this.destroy(); | ||
@@ -192,3 +192,3 @@ transport.server.clients.delete(this); | ||
if (!req.url.startsWith('/api')) { | ||
application.serveStatic(req.url, transport); | ||
application.static.serve(req.url, transport); | ||
return; | ||
@@ -195,0 +195,0 @@ } |
@@ -126,8 +126,17 @@ 'use strict'; | ||
write(data, httpCode = 200, ext = 'json') { | ||
write(data, httpCode = 200, ext = 'json', options = {}) { | ||
const { res } = this; | ||
if (res.writableEnded) return; | ||
const streaming = data instanceof Readable; | ||
const mimeType = MIME_TYPES[ext] || MIME_TYPES.html; | ||
res.writeHead(httpCode, { ...HEADERS, 'Content-Type': mimeType }); | ||
if (data instanceof Readable) data.pipe(res); | ||
const headers = { ...HEADERS, 'Content-Type': mimeType }; | ||
if (httpCode === 206) { | ||
const { start, end, size = '*' } = options; | ||
headers['Content-Range'] = `bytes ${start}-${end}/${size}`; | ||
headers['Accept-Ranges'] = 'bytes'; | ||
headers['Content-Length'] = end - start + 1; | ||
} | ||
if (!streaming) headers['Content-Length'] = data.length; | ||
res.writeHead(httpCode, headers); | ||
if (streaming) data.pipe(res); | ||
else res.end(data); | ||
@@ -134,0 +143,0 @@ } |
{ | ||
"name": "metacom", | ||
"version": "3.0.0-alpha.12", | ||
"version": "3.0.0-alpha.13", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -56,8 +56,8 @@ "description": "Communication protocol for Metarhia stack with rpc, events, binary streams, memory and db access", | ||
"dependencies": { | ||
"metautil": "^3.8.0", | ||
"metautil": "^3.9.0", | ||
"ws": "^8.13.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.2.5", | ||
"@types/ws": "^8.5.4", | ||
"@types/node": "^20.3.1", | ||
"@types/ws": "^8.5.5", | ||
"eslint": "^8.42.0", | ||
@@ -70,4 +70,4 @@ "eslint-config-metarhia": "^8.1.0", | ||
"prettier": "^2.8.8", | ||
"typescript": "^4.9.5" | ||
"typescript": "^5.1.3" | ||
} | ||
} |
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
54882
1629
Updatedmetautil@^3.9.0