quidproquo-web 0.0.128 → 0.0.129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- export declare const tmp: () => void;
1
+ export * from "./services";
@@ -1,8 +1,18 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tmp = void 0;
4
- const tmp = () => {
5
- console.log("Hello world");
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
6
15
  };
7
- exports.tmp = tmp;
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./services"), exports);
8
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAO,MAAM,GAAG,GAAG,GAAG,EAAE;IACpB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AAC/B,CAAC,CAAA;AAFY,QAAA,GAAG,OAEf"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B"}
@@ -0,0 +1,33 @@
1
+ export declare enum WebsocketServiceEvent {
2
+ OPEN = "open",
3
+ CLOSE = "close",
4
+ MESSAGE = "message",
5
+ ERROR = "error"
6
+ }
7
+ export type SubscriptionHandle = {
8
+ type: WebsocketServiceEvent;
9
+ };
10
+ export type WebSocketServiceSubscriptionFunction = (websocketService: WebsocketService, data?: string) => any;
11
+ export declare class WebsocketService {
12
+ private url;
13
+ private socket;
14
+ private eventListeners;
15
+ private isDestroyed;
16
+ private subscriptions;
17
+ constructor(url: string);
18
+ destroy(): void;
19
+ close(): void;
20
+ subscribe(subscriptionType: WebsocketServiceEvent, callback: WebSocketServiceSubscriptionFunction): SubscriptionHandle;
21
+ unsubscribe(subscriptionHandle: SubscriptionHandle): boolean;
22
+ unsubscribeAll(): void;
23
+ private connect;
24
+ private addEventListener;
25
+ private removeAllEventListeners;
26
+ private reconnectIfNotDestroyed;
27
+ private onConnect;
28
+ private onClose;
29
+ private onMessage;
30
+ private onError;
31
+ private notifySubscribers;
32
+ send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void;
33
+ }
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebsocketService = exports.WebsocketServiceEvent = void 0;
4
+ var WebsocketServiceEvent;
5
+ (function (WebsocketServiceEvent) {
6
+ WebsocketServiceEvent["OPEN"] = "open";
7
+ WebsocketServiceEvent["CLOSE"] = "close";
8
+ WebsocketServiceEvent["MESSAGE"] = "message";
9
+ WebsocketServiceEvent["ERROR"] = "error";
10
+ })(WebsocketServiceEvent = exports.WebsocketServiceEvent || (exports.WebsocketServiceEvent = {}));
11
+ ;
12
+ class WebsocketService {
13
+ constructor(url) {
14
+ this.socket = null;
15
+ this.eventListeners = {};
16
+ this.isDestroyed = false;
17
+ this.subscriptions = {
18
+ [WebsocketServiceEvent.OPEN]: new Map(),
19
+ [WebsocketServiceEvent.CLOSE]: new Map(),
20
+ [WebsocketServiceEvent.MESSAGE]: new Map(),
21
+ [WebsocketServiceEvent.ERROR]: new Map()
22
+ };
23
+ this.url = url;
24
+ this.connect();
25
+ }
26
+ destroy() {
27
+ var _a;
28
+ this.isDestroyed = true;
29
+ this.unsubscribeAll();
30
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
31
+ }
32
+ close() {
33
+ var _a;
34
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close();
35
+ }
36
+ subscribe(subscriptionType, callback) {
37
+ var _a;
38
+ const subscriptionHandle = {
39
+ type: subscriptionType
40
+ };
41
+ this.subscriptions[subscriptionType].set(subscriptionHandle, callback);
42
+ // If we are already open, then call the callback immediately
43
+ if (subscriptionType === WebsocketServiceEvent.OPEN && ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === WebSocket.OPEN) {
44
+ try {
45
+ callback(this);
46
+ }
47
+ catch (e) {
48
+ console.error('Error in Websocket onConnect callback: ', e);
49
+ }
50
+ }
51
+ return subscriptionHandle;
52
+ }
53
+ unsubscribe(subscriptionHandle) {
54
+ return this.subscriptions[subscriptionHandle.type].delete(subscriptionHandle);
55
+ }
56
+ unsubscribeAll() {
57
+ for (const subscriptionType in this.subscriptions) {
58
+ if (this.subscriptions.hasOwnProperty(subscriptionType)) {
59
+ this.subscriptions[subscriptionType].clear();
60
+ }
61
+ }
62
+ }
63
+ connect() {
64
+ this.removeAllEventListeners();
65
+ this.socket = new WebSocket(this.url);
66
+ this.addEventListener("open", this.onConnect.bind(this));
67
+ this.addEventListener("close", this.onClose.bind(this));
68
+ this.addEventListener("message", this.onMessage.bind(this));
69
+ this.addEventListener("error", this.onError.bind(this));
70
+ }
71
+ addEventListener(event, listener) {
72
+ if (this.socket) {
73
+ this.socket.addEventListener(event, listener);
74
+ if (!this.eventListeners[event]) {
75
+ this.eventListeners[event] = [];
76
+ }
77
+ this.eventListeners[event].push(listener);
78
+ }
79
+ }
80
+ removeAllEventListeners() {
81
+ if (this.socket) {
82
+ for (const event in this.eventListeners) {
83
+ if (this.eventListeners.hasOwnProperty(event)) {
84
+ for (const listener of this.eventListeners[event]) {
85
+ console.log('remove', event);
86
+ this.socket.removeEventListener(event, listener);
87
+ }
88
+ }
89
+ }
90
+ }
91
+ // Clear the eventListeners object
92
+ this.eventListeners = {};
93
+ }
94
+ reconnectIfNotDestroyed() {
95
+ setTimeout(() => {
96
+ if (!this.isDestroyed) {
97
+ this.connect();
98
+ }
99
+ }, 1000);
100
+ }
101
+ onConnect() {
102
+ console.log(`WebSocket connected: ${this.url}`);
103
+ this.notifySubscribers(this.subscriptions.open);
104
+ }
105
+ onClose() {
106
+ this.removeAllEventListeners();
107
+ this.reconnectIfNotDestroyed();
108
+ this.notifySubscribers(this.subscriptions.close);
109
+ }
110
+ onMessage(event) {
111
+ this.notifySubscribers(this.subscriptions.message, event.data);
112
+ }
113
+ onError() {
114
+ this.notifySubscribers(this.subscriptions.error);
115
+ }
116
+ notifySubscribers(subscibers, data) {
117
+ subscibers.forEach((callback) => {
118
+ callback(this, data);
119
+ });
120
+ }
121
+ send(data) {
122
+ var _a;
123
+ if (this.socket && this.socket.readyState === WebSocket.OPEN) {
124
+ this.socket.send(data);
125
+ }
126
+ else {
127
+ console.error(`WebSocket is not open [${(_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState}]. Unable to send data.`);
128
+ }
129
+ }
130
+ }
131
+ exports.WebsocketService = WebsocketService;
132
+ //# sourceMappingURL=WebsocketService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebsocketService.js","sourceRoot":"","sources":["../../../src/services/WebsocketService.ts"],"names":[],"mappings":";;;AAIA,IAAY,qBAKX;AALD,WAAY,qBAAqB;IAC7B,sCAAa,CAAA;IACb,wCAAe,CAAA;IACf,4CAAmB,CAAA;IACnB,wCAAe,CAAA;AACnB,CAAC,EALW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAKhC;AAAA,CAAC;AAcF,MAAa,gBAAgB;IAYzB,YAAY,GAAW;QAVf,WAAM,GAAqB,IAAI,CAAC;QAChC,mBAAc,GAAuD,EAAE,CAAC;QACxE,gBAAW,GAAY,KAAK,CAAC;QAC7B,kBAAa,GAAkB;YACnC,CAAC,qBAAqB,CAAC,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IAAa;QAChE,UAAU,CAAC,OAAO,CAAC,CAAC,QAA8C,EAAE,EAAE;YAClE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACP,CAAC;IAEM,IAAI,CAAC,IAAuD;;QACjE,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC,IAAI,EAAE;YAC5D,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACxB;aAAM;YACL,OAAO,CAAC,KAAK,CAAC,0BAA0B,MAAA,IAAI,CAAC,MAAM,0CAAE,UAAU,yBAAyB,CAAC,CAAC;SAC3F;IACH,CAAC;CACF;AA3IH,4CA2IG"}
@@ -0,0 +1 @@
1
+ export * from "./WebsocketService";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./WebsocketService"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAkC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-web",
3
- "version": "0.0.128",
3
+ "version": "0.0.129",
4
4
  "description": "",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "types": "./lib/commonjs/index.d.js",
@@ -27,6 +27,7 @@
27
27
  "devDependencies": {
28
28
  "quidproquo-core": "*",
29
29
  "quidproquo-tsconfig": "*",
30
+ "quidproquo-webserver": "*",
30
31
  "typescript": "^4.9.3"
31
32
  }
32
33
  }