@jcbuisson/express-x-client 3.0.2 → 3.0.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/client.mts +11 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jcbuisson/express-x-client",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "type": "module",
5
5
  "description": "Client library for ExpressX framework",
6
6
  "main": "src/client.mts",
package/src/client.mts CHANGED
@@ -136,8 +136,6 @@ export function createClient(socket, options={}) {
136
136
  return new Proxy(service, handler)
137
137
  }
138
138
 
139
- //-------------------- APPLICATION-LEVEL EVENTS --------------------
140
-
141
139
  // There is a need for application-wide events sent outside any service method call, for example when backend state changes
142
140
  // without front-end interactions
143
141
  socket.on('app-event', ({ type, value }) => {
@@ -152,6 +150,16 @@ export function createClient(socket, options={}) {
152
150
  type2appHandler[type] = handler
153
151
  }
154
152
 
153
+ function connect() {
154
+ if (options.debug) console.log('connecting...')
155
+ socket.connect()
156
+ }
157
+
158
+ function disconnect() {
159
+ if (options.debug) console.log('disconnecting...')
160
+ socket.disconnect()
161
+ }
162
+
155
163
  const app = {
156
164
  configure,
157
165
  addConnectListener,
@@ -163,6 +171,7 @@ export function createClient(socket, options={}) {
163
171
 
164
172
  service,
165
173
  on,
174
+ connect, disconnect,
166
175
  }
167
176
 
168
177
  return app