@crowdedkingdomstudios/crowdyjs 1.0.1 → 1.0.2

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
- {"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../src/subscriptions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAEV,kBAAkB,EAClB,0BAA0B,EAC1B,kBAAkB,EAClB,0BAA0B,EAC1B,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACd,MAAM,YAAY,CAAC;AAcpB,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAUd;IAEF,OAAO,CAAC,QAAQ,CAA0B;IAC1C,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,cAAc,CAAuB;IAC7C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,KAAK,CAAuB;gBAExB,MAAM,GAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAA;KAAO;IAIhD,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;IAIxC,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,iBAAiB;IAwMzB,OAAO,CAAC,kBAAkB;IAmB1B,aAAa,CAAC,OAAO,EAAE,kBAAkB,GAAG,aAAa;IAYzD,qBAAqB,CAAC,OAAO,EAAE,0BAA0B,GAAG,aAAa;IAYzE,aAAa,CAAC,OAAO,EAAE,kBAAkB,GAAG,aAAa;IAYzD,qBAAqB,CAAC,OAAO,EAAE,0BAA0B,GAAG,aAAa;IAYzE,aAAa,CAAC,OAAO,EAAE,kBAAkB,GAAG,aAAa;IAYzD,YAAY,CAAC,OAAO,EAAE,iBAAiB,GAAG,aAAa;IAYvD,aAAa,CAAC,OAAO,EAAE,kBAAkB,GAAG,aAAa;IAYzD,aAAa,CAAC,OAAO,EAAE,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kB,GAAG,aAAa;IAYzD,cAAc,CAAC,OAAO,EAAE,mBAAmB,GAAG,aAAa;IAY3D,OAAO,CAAC,wBAAwB;IAShC,KAAK,IAAI,IAAI;CAWd"}
@@ -41,22 +41,21 @@ export class SubscriptionManager {
41
41
  }
42
42
  const wsUrl = this.wsEndpoint;
43
43
  this.subscriptionId = 'udp-notifications-' + Date.now();
44
- this.wsClient = new WebSocket(wsUrl, 'graphql-ws');
45
- this.wsClient.onopen = () => {
46
- // Send connection_init message with authorization
47
- this.wsClient.send(JSON.stringify({
44
+ const ws = new WebSocket(wsUrl, 'graphql-ws');
45
+ this.wsClient = ws;
46
+ ws.onopen = () => {
47
+ ws.send(JSON.stringify({
48
48
  type: 'connection_init',
49
49
  payload: {
50
50
  authorization: `Bearer ${this.token}`,
51
- Authorization: `Bearer ${this.token}`, // Some servers expect capitalized
51
+ Authorization: `Bearer ${this.token}`,
52
52
  },
53
53
  }));
54
54
  };
55
- this.wsClient.onmessage = (event) => {
55
+ ws.onmessage = (event) => {
56
56
  try {
57
57
  const message = JSON.parse(event.data);
58
58
  if (message.type === 'connection_ack') {
59
- // Subscribe to udpNotifications
60
59
  const startMessage = {
61
60
  id: this.subscriptionId,
62
61
  type: 'start',
@@ -142,18 +141,15 @@ export class SubscriptionManager {
142
141
  }`,
143
142
  },
144
143
  };
145
- this.wsClient.send(JSON.stringify(startMessage));
144
+ ws.send(JSON.stringify(startMessage));
146
145
  }
147
146
  else if (message.type === 'connection_error') {
148
147
  console.error('Connection error:', message.payload);
149
148
  const errorMsg = message.payload?.message || 'Connection rejected - check authorization token';
150
- // Notify all handlers of error? Or just log?
151
149
  console.error('WebSocket connection error:', errorMsg);
152
150
  }
153
151
  else if (message.type === 'data') {
154
- // Handle null values (subscription is active but no notification yet)
155
152
  if (message.payload?.data?.udpNotifications === null) {
156
- // Don't call handlers for null values - subscription is working, just no data yet
157
153
  return;
158
154
  }
159
155
  if (message.payload?.data?.udpNotifications) {
@@ -181,38 +177,37 @@ export class SubscriptionManager {
181
177
  console.error('WebSocket error:', errorMsg);
182
178
  }
183
179
  else if (message.type === 'ping') {
184
- // Respond to ping with pong (graphql-ws protocol keepalive)
185
- this.wsClient.send(JSON.stringify({
186
- type: 'pong',
187
- }));
180
+ ws.send(JSON.stringify({ type: 'pong' }));
188
181
  }
189
182
  }
190
183
  catch (error) {
191
184
  console.error('Error parsing WebSocket message:', error);
192
185
  }
193
186
  };
194
- this.wsClient.onerror = (error) => {
187
+ ws.onerror = (error) => {
195
188
  console.error('WebSocket error:', error);
196
189
  };
197
- this.wsClient.onclose = (event) => {
190
+ ws.onclose = (event) => {
198
191
  if (event.code !== 1000) {
199
192
  console.warn(`WebSocket closed unexpectedly: ${event.reason || event.code}`);
200
193
  }
201
- this.wsClient = null;
194
+ if (this.wsClient === ws) {
195
+ this.wsClient = null;
196
+ }
202
197
  };
203
- // Store unsubscribe function
204
198
  this.wsUnsubscribe = () => {
205
- if (this.wsClient && this.wsClient.readyState === WebSocket.OPEN) {
206
- // Send stop message before closing
199
+ if (ws.readyState === WebSocket.OPEN) {
207
200
  if (this.subscriptionId) {
208
- this.wsClient.send(JSON.stringify({
201
+ ws.send(JSON.stringify({
209
202
  id: this.subscriptionId,
210
203
  type: 'stop',
211
204
  }));
212
205
  }
213
- this.wsClient.close();
206
+ ws.close();
207
+ }
208
+ if (this.wsClient === ws) {
209
+ this.wsClient = null;
214
210
  }
215
- this.wsClient = null;
216
211
  this.wsUnsubscribe = null;
217
212
  };
218
213
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crowdedkingdomstudios/crowdyjs",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Client SDK for Crowded Kingdoms GraphQL API with UDP proxy support",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,7 +26,7 @@
26
26
  "keywords": [
27
27
  "crowded-kingdoms",
28
28
  "graphql",
29
- "udp-proxy",
29
+ "game-api",
30
30
  "multiplayer",
31
31
  "sdk"
32
32
  ],
@@ -34,7 +34,7 @@
34
34
  "license": "MIT",
35
35
  "devDependencies": {
36
36
  "@types/node": "^22.10.7",
37
- "typescript": "^5.7.3"
37
+ "typescript": "^5.7.3",
38
+ "ws": "^8.20.0"
38
39
  }
39
40
  }
40
-