Comparing version 1.5.1 to 1.5.2
@@ -5,2 +5,9 @@ # Changelog | ||
## [1.5.2][] - 2021-02-23 | ||
- Update metautil to 3.5.0, change `await timeout` to `await delay` | ||
- Remove channel from collection on connections close | ||
- Add Client event: 'close' for http and websockets | ||
- Delegate server and browser socket on 'error' handler | ||
## [1.5.1][] - 2021-02-19 | ||
@@ -60,3 +67,4 @@ | ||
[unreleased]: https://github.com/metarhia/metacom/compare/v1.5.1...HEAD | ||
[unreleased]: https://github.com/metarhia/metacom/compare/v1.5.2...HEAD | ||
[1.5.2]: https://github.com/metarhia/metacom/compare/v1.5.1...v1.5.2 | ||
[1.5.1]: https://github.com/metarhia/metacom/compare/v1.5.0...v1.5.1 | ||
@@ -63,0 +71,0 @@ [1.5.0]: https://github.com/metarhia/metacom/compare/v1.4.0...v1.5.0 |
@@ -152,3 +152,4 @@ import { EventEmitter } from './events.js'; | ||
socket.addEventListener('error', () => { | ||
socket.addEventListener('error', (err) => { | ||
this.emit('error', err); | ||
socket.close(); | ||
@@ -155,0 +156,0 @@ }); |
@@ -59,5 +59,11 @@ 'use strict'; | ||
constructor() { | ||
this.events = { close: [] }; | ||
this.callId = 0; | ||
} | ||
on(name, callback) { | ||
if (name !== 'close') return; | ||
this.events.close.push(callback); | ||
} | ||
emit(name, data) { | ||
@@ -264,2 +270,3 @@ const packet = { event: --this.callId, [name]: data }; | ||
destroy() { | ||
for (const callback of this.client.events.close) callback(); | ||
if (!this.session) return; | ||
@@ -266,0 +273,0 @@ const token = this.session.token; |
@@ -5,2 +5,3 @@ 'use strict'; | ||
const https = require('https'); | ||
const { EventEmitter } = require('events'); | ||
const transport = { http, https }; | ||
@@ -33,4 +34,5 @@ const WebSocket = require('ws'); | ||
class Metacom { | ||
class Metacom extends EventEmitter { | ||
constructor(url) { | ||
super(); | ||
this.url = url; | ||
@@ -58,2 +60,5 @@ this.socket = new WebSocket(url); | ||
}); | ||
this.socket.addEventListener('error', (err) => { | ||
this.emit('error', err); | ||
}); | ||
} | ||
@@ -60,0 +65,0 @@ |
@@ -44,2 +44,6 @@ 'use strict'; | ||
}); | ||
connection.on('close', () => { | ||
channels.delete(channel.client); | ||
channel.destroy(); | ||
}); | ||
}); | ||
@@ -114,4 +118,3 @@ this.protocol = protocol; | ||
closeChannels() { | ||
for (const [client, channel] of channels.entries()) { | ||
channels.delete(client); | ||
for (const channel of channels.values()) { | ||
if (channel.connection) { | ||
@@ -123,3 +126,2 @@ channel.connection.terminate(); | ||
} | ||
channel.destroy(); | ||
} | ||
@@ -133,6 +135,6 @@ } | ||
if (channels.size === 0) { | ||
await metautil.timeout(SHORT_TIMEOUT); | ||
await metautil.delay(SHORT_TIMEOUT); | ||
return; | ||
} | ||
await metautil.timeout(SHUTDOWN_TIMEOUT); | ||
await metautil.delay(SHUTDOWN_TIMEOUT); | ||
this.closeChannels(); | ||
@@ -139,0 +141,0 @@ } |
{ | ||
"name": "metacom", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -53,3 +53,3 @@ "description": "Communication protocol for Metarhia stack with rpc, events, binary streams, memory and db access", | ||
"dependencies": { | ||
"metautil": "^3.3.0", | ||
"metautil": "^3.5.0", | ||
"ws": "^7.4.3" | ||
@@ -60,3 +60,3 @@ }, | ||
"eslint-config-metarhia": "^7.0.1", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-config-prettier": "^8.0.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
@@ -63,0 +63,0 @@ "eslint-plugin-prettier": "^3.3.1", |
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
28952
727
Updatedmetautil@^3.5.0