@dwmt/comlink
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -214,2 +214,12 @@ import Cookies from 'js-cookie'; | ||
listeners: {}, | ||
onConnectionOpen: options.onConnectionOpen || function () {}, | ||
onConnectionTermination: options.onConnectionTermination || function () {}, | ||
onConnectionClose: options.onConnectionClose || function () {}, | ||
onConnectionError: options.onConnectionError || function () {}, | ||
callbacks: { | ||
onConnectionOpen: function onConnectionOpen() {}, | ||
onConnectionClose: function onConnectionClose() {}, | ||
onConnectionError: function onConnectionError() {}, | ||
onConnectionTermination: function onConnectionTermination() {} | ||
}, | ||
terminate: function terminate() { | ||
@@ -221,3 +231,6 @@ self._channels[options.name].connection.close(); | ||
self._channels[options.name].listeners = {}; | ||
console.log(self._channels[options.name]); | ||
self._channels[options.name].onConnectionTermination(); | ||
self._channels[options.name].callbacks.onConnectionTermination(); | ||
}, | ||
@@ -241,3 +254,7 @@ connect: function connect() { | ||
self._channels[options.name].alive = true; | ||
console.log('Connection established'); | ||
self._channels[options.name].onConnectionOpen(); | ||
self._channels[options.name].callbacks.onConnectionOpen(); | ||
resolve(); | ||
@@ -247,5 +264,14 @@ }); | ||
self._channels[options.name].alive = false; | ||
self._channels[options.name].onConnectionClose(); | ||
self._channels[options.name].callbacks.onConnectionClose(); | ||
}); | ||
ws.addEventListener('error', function () { | ||
ws.addEventListener('error', function (err) { | ||
self._channels[options.name].alive = false; | ||
self._channels[options.name].onConnectionError(err); | ||
self._channels[options.name].callbacks.onConnectionError(err); | ||
reject(); | ||
@@ -334,2 +360,3 @@ }); | ||
var self = this; | ||
var channel = {}; | ||
@@ -345,2 +372,6 @@ channel.name = this._channels[channelName].name; | ||
channel.registerCallback = function (callbackName, cb) { | ||
self._channels[channelName].callbacks[callbackName] = cb; | ||
}; | ||
return channel; | ||
@@ -347,0 +378,0 @@ } |
@@ -218,2 +218,12 @@ 'use strict'; | ||
listeners: {}, | ||
onConnectionOpen: options.onConnectionOpen || function () {}, | ||
onConnectionTermination: options.onConnectionTermination || function () {}, | ||
onConnectionClose: options.onConnectionClose || function () {}, | ||
onConnectionError: options.onConnectionError || function () {}, | ||
callbacks: { | ||
onConnectionOpen: function onConnectionOpen() {}, | ||
onConnectionClose: function onConnectionClose() {}, | ||
onConnectionError: function onConnectionError() {}, | ||
onConnectionTermination: function onConnectionTermination() {} | ||
}, | ||
terminate: function terminate() { | ||
@@ -225,3 +235,6 @@ self._channels[options.name].connection.close(); | ||
self._channels[options.name].listeners = {}; | ||
console.log(self._channels[options.name]); | ||
self._channels[options.name].onConnectionTermination(); | ||
self._channels[options.name].callbacks.onConnectionTermination(); | ||
}, | ||
@@ -245,3 +258,7 @@ connect: function connect() { | ||
self._channels[options.name].alive = true; | ||
console.log('Connection established'); | ||
self._channels[options.name].onConnectionOpen(); | ||
self._channels[options.name].callbacks.onConnectionOpen(); | ||
resolve(); | ||
@@ -251,5 +268,14 @@ }); | ||
self._channels[options.name].alive = false; | ||
self._channels[options.name].onConnectionClose(); | ||
self._channels[options.name].callbacks.onConnectionClose(); | ||
}); | ||
ws.addEventListener('error', function () { | ||
ws.addEventListener('error', function (err) { | ||
self._channels[options.name].alive = false; | ||
self._channels[options.name].onConnectionError(err); | ||
self._channels[options.name].callbacks.onConnectionError(err); | ||
reject(); | ||
@@ -338,2 +364,3 @@ }); | ||
var self = this; | ||
var channel = {}; | ||
@@ -349,2 +376,6 @@ channel.name = this._channels[channelName].name; | ||
channel.registerCallback = function (callbackName, cb) { | ||
self._channels[channelName].callbacks[callbackName] = cb; | ||
}; | ||
return channel; | ||
@@ -351,0 +382,0 @@ } |
{ | ||
"name": "@dwmt/comlink", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Communication library for lazy enthusiasts", | ||
@@ -5,0 +5,0 @@ "main": "dist/Comlink.js", |
70088
1988