@crowdedkingdomstudios/crowdyjs 1.0.0

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.
@@ -0,0 +1,31 @@
1
+ /**
2
+ * WebSocket subscription manager with type-specific handlers
3
+ */
4
+ import type { ActorUpdateHandler, ActorUpdateResponseHandler, VoxelUpdateHandler, VoxelUpdateResponseHandler, ClientAudioHandler, ClientTextHandler, ClientEventHandler, ServerEventHandler, GenericErrorHandler, UnsubscribeFn } from './types.js';
5
+ export declare class SubscriptionManager {
6
+ private handlers;
7
+ private wsClient;
8
+ private wsUnsubscribe;
9
+ private subscriptionId;
10
+ private wsEndpoint;
11
+ private token;
12
+ constructor(config?: {
13
+ wsEndpoint?: string;
14
+ });
15
+ setAuthToken(token: string | null): void;
16
+ private ensureSubscription;
17
+ private startSubscription;
18
+ private handleNotification;
19
+ onActorUpdate(handler: ActorUpdateHandler): UnsubscribeFn;
20
+ onActorUpdateResponse(handler: ActorUpdateResponseHandler): UnsubscribeFn;
21
+ onVoxelUpdate(handler: VoxelUpdateHandler): UnsubscribeFn;
22
+ onVoxelUpdateResponse(handler: VoxelUpdateResponseHandler): UnsubscribeFn;
23
+ onClientAudio(handler: ClientAudioHandler): UnsubscribeFn;
24
+ onClientText(handler: ClientTextHandler): UnsubscribeFn;
25
+ onClientEvent(handler: ClientEventHandler): UnsubscribeFn;
26
+ onServerEvent(handler: ServerEventHandler): UnsubscribeFn;
27
+ onGenericError(handler: GenericErrorHandler): UnsubscribeFn;
28
+ private checkIfShouldUnsubscribe;
29
+ close(): void;
30
+ }
31
+ //# sourceMappingURL=subscriptions.d.ts.map
@@ -0,0 +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;IAM1B,OAAO,CAAC,iBAAiB;IAoMzB,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,kBAAkB,GAAG,aAAa;IAYzD,cAAc,CAAC,OAAO,EAAE,mBAAmB,GAAG,aAAa;IAY3D,OAAO,CAAC,wBAAwB;IAShC,KAAK,IAAI,IAAI;CAWd"}
@@ -0,0 +1,350 @@
1
+ /**
2
+ * WebSocket subscription manager with type-specific handlers
3
+ */
4
+ export class SubscriptionManager {
5
+ constructor(config = {}) {
6
+ this.handlers = {
7
+ ActorUpdateNotification: [],
8
+ ActorUpdateResponse: [],
9
+ VoxelUpdateNotification: [],
10
+ VoxelUpdateResponse: [],
11
+ ClientAudioNotification: [],
12
+ ClientTextNotification: [],
13
+ ClientEventNotification: [],
14
+ ServerEventNotification: [],
15
+ GenericErrorResponse: [],
16
+ };
17
+ this.wsClient = null;
18
+ this.wsUnsubscribe = null;
19
+ this.subscriptionId = null;
20
+ this.token = null;
21
+ this.wsEndpoint = config.wsEndpoint || 'ws://localhost:3000/graphql';
22
+ }
23
+ setAuthToken(token) {
24
+ this.token = token;
25
+ }
26
+ ensureSubscription() {
27
+ if (!this.wsClient || this.wsClient.readyState !== WebSocket.OPEN) {
28
+ this.startSubscription();
29
+ }
30
+ }
31
+ startSubscription() {
32
+ if (!this.token) {
33
+ throw new Error('Must be authenticated to subscribe');
34
+ }
35
+ if (this.wsClient && this.wsClient.readyState === WebSocket.OPEN) {
36
+ return; // Already connected
37
+ }
38
+ const wsUrl = this.wsEndpoint;
39
+ this.subscriptionId = 'udp-notifications-' + Date.now();
40
+ this.wsClient = new WebSocket(wsUrl, 'graphql-ws');
41
+ this.wsClient.onopen = () => {
42
+ // Send connection_init message with authorization
43
+ this.wsClient.send(JSON.stringify({
44
+ type: 'connection_init',
45
+ payload: {
46
+ authorization: `Bearer ${this.token}`,
47
+ Authorization: `Bearer ${this.token}`, // Some servers expect capitalized
48
+ },
49
+ }));
50
+ };
51
+ this.wsClient.onmessage = (event) => {
52
+ try {
53
+ const message = JSON.parse(event.data);
54
+ if (message.type === 'connection_ack') {
55
+ // Subscribe to udpNotifications
56
+ const startMessage = {
57
+ id: this.subscriptionId,
58
+ type: 'start',
59
+ payload: {
60
+ query: `subscription {
61
+ udpNotifications {
62
+ __typename
63
+ ... on ActorUpdateNotification {
64
+ mapId
65
+ chunkX
66
+ chunkY
67
+ chunkZ
68
+ uuid
69
+ state
70
+ }
71
+ ... on ActorUpdateResponse {
72
+ mapId
73
+ chunkX
74
+ chunkY
75
+ chunkZ
76
+ uuid
77
+ sequenceNumber
78
+ }
79
+ ... on VoxelUpdateNotification {
80
+ mapId
81
+ chunkX
82
+ chunkY
83
+ chunkZ
84
+ uuid
85
+ voxelX
86
+ voxelY
87
+ voxelZ
88
+ voxelType
89
+ voxelState
90
+ }
91
+ ... on VoxelUpdateResponse {
92
+ mapId
93
+ chunkX
94
+ chunkY
95
+ chunkZ
96
+ uuid
97
+ sequenceNumber
98
+ }
99
+ ... on ClientAudioNotification {
100
+ mapId
101
+ chunkX
102
+ chunkY
103
+ chunkZ
104
+ uuid
105
+ audioData
106
+ }
107
+ ... on ClientTextNotification {
108
+ mapId
109
+ chunkX
110
+ chunkY
111
+ chunkZ
112
+ uuid
113
+ text
114
+ }
115
+ ... on ClientEventNotification {
116
+ mapId
117
+ chunkX
118
+ chunkY
119
+ chunkZ
120
+ uuid
121
+ eventType
122
+ state
123
+ }
124
+ ... on ServerEventNotification {
125
+ mapId
126
+ chunkX
127
+ chunkY
128
+ chunkZ
129
+ uuid
130
+ eventType
131
+ state
132
+ }
133
+ ... on GenericErrorResponse {
134
+ sequenceNumber
135
+ errorCode
136
+ }
137
+ }
138
+ }`,
139
+ },
140
+ };
141
+ this.wsClient.send(JSON.stringify(startMessage));
142
+ }
143
+ else if (message.type === 'connection_error') {
144
+ console.error('Connection error:', message.payload);
145
+ const errorMsg = message.payload?.message || 'Connection rejected - check authorization token';
146
+ // Notify all handlers of error? Or just log?
147
+ console.error('WebSocket connection error:', errorMsg);
148
+ }
149
+ else if (message.type === 'data') {
150
+ // Handle null values (subscription is active but no notification yet)
151
+ if (message.payload?.data?.udpNotifications === null) {
152
+ // Don't call handlers for null values - subscription is working, just no data yet
153
+ return;
154
+ }
155
+ if (message.payload?.data?.udpNotifications) {
156
+ const notification = message.payload.data.udpNotifications;
157
+ this.handleNotification(notification);
158
+ }
159
+ else if (message.payload?.errors) {
160
+ console.error('Subscription errors:', message.payload.errors);
161
+ const firstError = message.payload.errors[0];
162
+ const errorMsg = firstError?.message
163
+ ? Array.isArray(firstError.message)
164
+ ? firstError.message.join(', ')
165
+ : String(firstError.message)
166
+ : firstError?.extensions?.message || 'Unknown subscription error';
167
+ console.error('Subscription error:', errorMsg);
168
+ }
169
+ }
170
+ else if (message.type === 'error') {
171
+ console.error('WebSocket error message:', message.payload);
172
+ const errorMsg = message.payload?.message
173
+ ? Array.isArray(message.payload.message)
174
+ ? message.payload.message.join(', ')
175
+ : String(message.payload.message)
176
+ : 'WebSocket error';
177
+ console.error('WebSocket error:', errorMsg);
178
+ }
179
+ else if (message.type === 'ping') {
180
+ // Respond to ping with pong (graphql-ws protocol keepalive)
181
+ this.wsClient.send(JSON.stringify({
182
+ type: 'pong',
183
+ }));
184
+ }
185
+ }
186
+ catch (error) {
187
+ console.error('Error parsing WebSocket message:', error);
188
+ }
189
+ };
190
+ this.wsClient.onerror = (error) => {
191
+ console.error('WebSocket error:', error);
192
+ };
193
+ this.wsClient.onclose = (event) => {
194
+ if (event.code !== 1000) {
195
+ console.warn(`WebSocket closed unexpectedly: ${event.reason || event.code}`);
196
+ }
197
+ this.wsClient = null;
198
+ };
199
+ // Store unsubscribe function
200
+ this.wsUnsubscribe = () => {
201
+ if (this.wsClient && this.wsClient.readyState === WebSocket.OPEN) {
202
+ // Send stop message before closing
203
+ if (this.subscriptionId) {
204
+ this.wsClient.send(JSON.stringify({
205
+ id: this.subscriptionId,
206
+ type: 'stop',
207
+ }));
208
+ }
209
+ this.wsClient.close();
210
+ }
211
+ this.wsClient = null;
212
+ this.wsUnsubscribe = null;
213
+ };
214
+ }
215
+ handleNotification(notification) {
216
+ const type = notification.__typename;
217
+ if (!type) {
218
+ console.warn('Received notification without __typename:', notification);
219
+ return;
220
+ }
221
+ const handlers = this.handlers[type];
222
+ if (handlers && handlers.length > 0) {
223
+ handlers.forEach((handler) => {
224
+ try {
225
+ handler(notification);
226
+ }
227
+ catch (error) {
228
+ console.error(`Error in handler for ${type}:`, error);
229
+ }
230
+ });
231
+ }
232
+ }
233
+ onActorUpdate(handler) {
234
+ this.handlers.ActorUpdateNotification.push(handler);
235
+ this.ensureSubscription();
236
+ return () => {
237
+ const index = this.handlers.ActorUpdateNotification.indexOf(handler);
238
+ if (index > -1) {
239
+ this.handlers.ActorUpdateNotification.splice(index, 1);
240
+ }
241
+ this.checkIfShouldUnsubscribe();
242
+ };
243
+ }
244
+ onActorUpdateResponse(handler) {
245
+ this.handlers.ActorUpdateResponse.push(handler);
246
+ this.ensureSubscription();
247
+ return () => {
248
+ const index = this.handlers.ActorUpdateResponse.indexOf(handler);
249
+ if (index > -1) {
250
+ this.handlers.ActorUpdateResponse.splice(index, 1);
251
+ }
252
+ this.checkIfShouldUnsubscribe();
253
+ };
254
+ }
255
+ onVoxelUpdate(handler) {
256
+ this.handlers.VoxelUpdateNotification.push(handler);
257
+ this.ensureSubscription();
258
+ return () => {
259
+ const index = this.handlers.VoxelUpdateNotification.indexOf(handler);
260
+ if (index > -1) {
261
+ this.handlers.VoxelUpdateNotification.splice(index, 1);
262
+ }
263
+ this.checkIfShouldUnsubscribe();
264
+ };
265
+ }
266
+ onVoxelUpdateResponse(handler) {
267
+ this.handlers.VoxelUpdateResponse.push(handler);
268
+ this.ensureSubscription();
269
+ return () => {
270
+ const index = this.handlers.VoxelUpdateResponse.indexOf(handler);
271
+ if (index > -1) {
272
+ this.handlers.VoxelUpdateResponse.splice(index, 1);
273
+ }
274
+ this.checkIfShouldUnsubscribe();
275
+ };
276
+ }
277
+ onClientAudio(handler) {
278
+ this.handlers.ClientAudioNotification.push(handler);
279
+ this.ensureSubscription();
280
+ return () => {
281
+ const index = this.handlers.ClientAudioNotification.indexOf(handler);
282
+ if (index > -1) {
283
+ this.handlers.ClientAudioNotification.splice(index, 1);
284
+ }
285
+ this.checkIfShouldUnsubscribe();
286
+ };
287
+ }
288
+ onClientText(handler) {
289
+ this.handlers.ClientTextNotification.push(handler);
290
+ this.ensureSubscription();
291
+ return () => {
292
+ const index = this.handlers.ClientTextNotification.indexOf(handler);
293
+ if (index > -1) {
294
+ this.handlers.ClientTextNotification.splice(index, 1);
295
+ }
296
+ this.checkIfShouldUnsubscribe();
297
+ };
298
+ }
299
+ onClientEvent(handler) {
300
+ this.handlers.ClientEventNotification.push(handler);
301
+ this.ensureSubscription();
302
+ return () => {
303
+ const index = this.handlers.ClientEventNotification.indexOf(handler);
304
+ if (index > -1) {
305
+ this.handlers.ClientEventNotification.splice(index, 1);
306
+ }
307
+ this.checkIfShouldUnsubscribe();
308
+ };
309
+ }
310
+ onServerEvent(handler) {
311
+ this.handlers.ServerEventNotification.push(handler);
312
+ this.ensureSubscription();
313
+ return () => {
314
+ const index = this.handlers.ServerEventNotification.indexOf(handler);
315
+ if (index > -1) {
316
+ this.handlers.ServerEventNotification.splice(index, 1);
317
+ }
318
+ this.checkIfShouldUnsubscribe();
319
+ };
320
+ }
321
+ onGenericError(handler) {
322
+ this.handlers.GenericErrorResponse.push(handler);
323
+ this.ensureSubscription();
324
+ return () => {
325
+ const index = this.handlers.GenericErrorResponse.indexOf(handler);
326
+ if (index > -1) {
327
+ this.handlers.GenericErrorResponse.splice(index, 1);
328
+ }
329
+ this.checkIfShouldUnsubscribe();
330
+ };
331
+ }
332
+ checkIfShouldUnsubscribe() {
333
+ // Check if any handlers are still registered
334
+ const hasHandlers = Object.values(this.handlers).some((handlers) => handlers.length > 0);
335
+ if (!hasHandlers && this.wsUnsubscribe) {
336
+ this.wsUnsubscribe();
337
+ this.wsUnsubscribe = null;
338
+ }
339
+ }
340
+ close() {
341
+ // Clear all handlers
342
+ Object.keys(this.handlers).forEach((key) => {
343
+ this.handlers[key] = [];
344
+ });
345
+ // Close WebSocket if open
346
+ if (this.wsUnsubscribe) {
347
+ this.wsUnsubscribe();
348
+ }
349
+ }
350
+ }
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Type definitions for Crowded Kingdoms SDK
3
+ */
4
+ export type BigInt = string;
5
+ export interface ChunkCoordinates {
6
+ x: BigInt;
7
+ y: BigInt;
8
+ z: BigInt;
9
+ }
10
+ export interface ChunkCoordinatesInput {
11
+ x: BigInt;
12
+ y: BigInt;
13
+ z: BigInt;
14
+ }
15
+ export interface VoxelCoordinates {
16
+ x: number;
17
+ y: number;
18
+ z: number;
19
+ }
20
+ export interface VoxelCoordinatesInput {
21
+ x: number;
22
+ y: number;
23
+ z: number;
24
+ }
25
+ export declare enum UdpErrorCode {
26
+ NO_ERROR = "NO_ERROR",
27
+ UNKNOWN_ERROR = "UNKNOWN_ERROR",
28
+ EMAIL_NOT_FOUND = "EMAIL_NOT_FOUND",
29
+ BAD_PASSWORD = "BAD_PASSWORD",
30
+ EMAIL_ALREADY_EXISTS = "EMAIL_ALREADY_EXISTS",
31
+ INVALID_TOKEN = "INVALID_TOKEN",
32
+ MAP_NOT_FOUND = "MAP_NOT_FOUND",
33
+ UNAUTHORIZED = "UNAUTHORIZED",
34
+ MAP_NOT_LOADED = "MAP_NOT_LOADED",
35
+ EMAIL_TOO_SHORT = "EMAIL_TOO_SHORT",
36
+ EMAIL_TOO_LONG = "EMAIL_TOO_LONG",
37
+ PASSWORD_TOO_SHORT = "PASSWORD_TOO_SHORT",
38
+ PASSWORD_TOO_LONG = "PASSWORD_TOO_LONG",
39
+ GAME_TOKEN_WRONG_SIZE = "GAME_TOKEN_WRONG_SIZE",
40
+ NAME_TOO_LONG = "NAME_TOO_LONG",
41
+ INVALID_REQUEST = "INVALID_REQUEST",
42
+ EMAIL_INVALID = "EMAIL_INVALID",
43
+ INVALID_TOKEN_LENGTH = "INVALID_TOKEN_LENGTH",
44
+ INVALID_MAP_ID = "INVALID_MAP_ID",
45
+ CHUNK_NOT_FOUND = "CHUNK_NOT_FOUND",
46
+ USER_NOT_AUTHENTICATED = "USER_NOT_AUTHENTICATED",
47
+ INVALID_STATE_DATA = "INVALID_STATE_DATA",
48
+ USER_NOT_APP_ADMIN = "USER_NOT_APP_ADMIN",
49
+ GRID_OUTSIDE_ASSIGNMENT = "GRID_OUTSIDE_ASSIGNMENT",
50
+ NO_MATCHING_GRID_ASSIGNMENT = "NO_MATCHING_GRID_ASSIGNMENT",
51
+ INVALID_GRID_COORDINATES = "INVALID_GRID_COORDINATES",
52
+ GRID_ALREADY_EXISTS = "GRID_ALREADY_EXISTS",
53
+ GRID_OVERLAPS_EXISTING = "GRID_OVERLAPS_EXISTING",
54
+ GAMERTAG_ALREADY_EXISTS = "GAMERTAG_ALREADY_EXISTS"
55
+ }
56
+ export interface User {
57
+ userId: BigInt;
58
+ email: string;
59
+ gamertag?: string;
60
+ disambiguation?: string;
61
+ state?: string;
62
+ isConfirmed: boolean;
63
+ createdAt: string;
64
+ grantEarlyAccess: boolean;
65
+ grantEarlyAccessOverride: boolean;
66
+ }
67
+ export interface AuthResponse {
68
+ token: string;
69
+ gameTokenId: string;
70
+ user: User;
71
+ }
72
+ export interface UdpProxyConnectionStatus {
73
+ connected: boolean;
74
+ serverIp6?: string;
75
+ serverClientPort?: number;
76
+ lastMessageTime?: string;
77
+ }
78
+ export interface ActorUpdateRequestInput {
79
+ mapId: BigInt;
80
+ chunk: ChunkCoordinatesInput;
81
+ uuid: string;
82
+ state: string;
83
+ distance?: number;
84
+ decayRate?: number;
85
+ sequenceNumber?: number;
86
+ }
87
+ export interface VoxelUpdateRequestInput {
88
+ mapId: BigInt;
89
+ chunk: ChunkCoordinatesInput;
90
+ uuid: string;
91
+ voxel: VoxelCoordinatesInput;
92
+ voxelType: number;
93
+ voxelState: string;
94
+ distance?: number;
95
+ decayRate?: number;
96
+ sequenceNumber?: number;
97
+ }
98
+ export interface ClientAudioPacketInput {
99
+ mapId: BigInt;
100
+ chunk: ChunkCoordinatesInput;
101
+ uuid: string;
102
+ audioData: string;
103
+ distance?: number;
104
+ decayRate?: number;
105
+ sequenceNumber?: number;
106
+ }
107
+ export interface ClientTextPacketInput {
108
+ mapId: BigInt;
109
+ chunk: ChunkCoordinatesInput;
110
+ uuid: string;
111
+ text: string;
112
+ distance?: number;
113
+ decayRate?: number;
114
+ sequenceNumber?: number;
115
+ }
116
+ export interface ClientEventNotificationInput {
117
+ mapId: BigInt;
118
+ chunk: ChunkCoordinatesInput;
119
+ uuid: string;
120
+ eventType: number;
121
+ state: string;
122
+ distance?: number;
123
+ decayRate?: number;
124
+ sequenceNumber?: number;
125
+ }
126
+ export interface ActorUpdateNotification {
127
+ __typename: 'ActorUpdateNotification';
128
+ mapId: BigInt;
129
+ chunkX: BigInt;
130
+ chunkY: BigInt;
131
+ chunkZ: BigInt;
132
+ uuid: string;
133
+ state: string;
134
+ }
135
+ export interface ActorUpdateResponse {
136
+ __typename: 'ActorUpdateResponse';
137
+ mapId: BigInt;
138
+ chunkX: BigInt;
139
+ chunkY: BigInt;
140
+ chunkZ: BigInt;
141
+ uuid: string;
142
+ sequenceNumber: number;
143
+ }
144
+ export interface VoxelUpdateNotification {
145
+ __typename: 'VoxelUpdateNotification';
146
+ mapId: BigInt;
147
+ chunkX: BigInt;
148
+ chunkY: BigInt;
149
+ chunkZ: BigInt;
150
+ uuid: string;
151
+ voxelX: number;
152
+ voxelY: number;
153
+ voxelZ: number;
154
+ voxelType: number;
155
+ voxelState: string;
156
+ }
157
+ export interface VoxelUpdateResponse {
158
+ __typename: 'VoxelUpdateResponse';
159
+ mapId: BigInt;
160
+ chunkX: BigInt;
161
+ chunkY: BigInt;
162
+ chunkZ: BigInt;
163
+ uuid: string;
164
+ sequenceNumber: number;
165
+ }
166
+ export interface ClientAudioNotification {
167
+ __typename: 'ClientAudioNotification';
168
+ mapId: BigInt;
169
+ chunkX: BigInt;
170
+ chunkY: BigInt;
171
+ chunkZ: BigInt;
172
+ uuid: string;
173
+ audioData: string;
174
+ }
175
+ export interface ClientTextNotification {
176
+ __typename: 'ClientTextNotification';
177
+ mapId: BigInt;
178
+ chunkX: BigInt;
179
+ chunkY: BigInt;
180
+ chunkZ: BigInt;
181
+ uuid: string;
182
+ text: string;
183
+ }
184
+ export interface ClientEventNotification {
185
+ __typename: 'ClientEventNotification';
186
+ mapId: BigInt;
187
+ chunkX: BigInt;
188
+ chunkY: BigInt;
189
+ chunkZ: BigInt;
190
+ uuid: string;
191
+ eventType: number;
192
+ state: string;
193
+ }
194
+ export interface ServerEventNotification {
195
+ __typename: 'ServerEventNotification';
196
+ mapId: BigInt;
197
+ chunkX: BigInt;
198
+ chunkY: BigInt;
199
+ chunkZ: BigInt;
200
+ uuid: string;
201
+ eventType: number;
202
+ state: string;
203
+ }
204
+ export interface GenericErrorResponse {
205
+ __typename: 'GenericErrorResponse';
206
+ sequenceNumber: number;
207
+ errorCode: UdpErrorCode;
208
+ }
209
+ export type UdpNotification = ActorUpdateNotification | ActorUpdateResponse | VoxelUpdateNotification | VoxelUpdateResponse | ClientAudioNotification | ClientTextNotification | ClientEventNotification | ServerEventNotification | GenericErrorResponse;
210
+ export interface CrowdyClientConfig {
211
+ graphqlEndpoint?: string;
212
+ wsEndpoint?: string;
213
+ timeout?: number;
214
+ }
215
+ export type ActorUpdateHandler = (notification: ActorUpdateNotification) => void;
216
+ export type ActorUpdateResponseHandler = (response: ActorUpdateResponse) => void;
217
+ export type VoxelUpdateHandler = (notification: VoxelUpdateNotification) => void;
218
+ export type VoxelUpdateResponseHandler = (response: VoxelUpdateResponse) => void;
219
+ export type ClientAudioHandler = (notification: ClientAudioNotification) => void;
220
+ export type ClientTextHandler = (notification: ClientTextNotification) => void;
221
+ export type ClientEventHandler = (notification: ClientEventNotification) => void;
222
+ export type ServerEventHandler = (notification: ServerEventNotification) => void;
223
+ export type GenericErrorHandler = (response: GenericErrorResponse) => void;
224
+ export type UnsubscribeFn = () => void;
225
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAG5B,MAAM,WAAW,gBAAgB;IAC/B,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,qBAAqB;IACpC,CAAC,EAAE,MAAM,CAAC;IACV,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AE,oBAAoB,KAAK,IAAI,CAAC;AAG3E,MAAM,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Type definitions for Crowded Kingdoms SDK
3
+ */
4
+ // Error codes
5
+ export var UdpErrorCode;
6
+ (function (UdpErrorCode) {
7
+ UdpErrorCode["NO_ERROR"] = "NO_ERROR";
8
+ UdpErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
9
+ UdpErrorCode["EMAIL_NOT_FOUND"] = "EMAIL_NOT_FOUND";
10
+ UdpErrorCode["BAD_PASSWORD"] = "BAD_PASSWORD";
11
+ UdpErrorCode["EMAIL_ALREADY_EXISTS"] = "EMAIL_ALREADY_EXISTS";
12
+ UdpErrorCode["INVALID_TOKEN"] = "INVALID_TOKEN";
13
+ UdpErrorCode["MAP_NOT_FOUND"] = "MAP_NOT_FOUND";
14
+ UdpErrorCode["UNAUTHORIZED"] = "UNAUTHORIZED";
15
+ UdpErrorCode["MAP_NOT_LOADED"] = "MAP_NOT_LOADED";
16
+ UdpErrorCode["EMAIL_TOO_SHORT"] = "EMAIL_TOO_SHORT";
17
+ UdpErrorCode["EMAIL_TOO_LONG"] = "EMAIL_TOO_LONG";
18
+ UdpErrorCode["PASSWORD_TOO_SHORT"] = "PASSWORD_TOO_SHORT";
19
+ UdpErrorCode["PASSWORD_TOO_LONG"] = "PASSWORD_TOO_LONG";
20
+ UdpErrorCode["GAME_TOKEN_WRONG_SIZE"] = "GAME_TOKEN_WRONG_SIZE";
21
+ UdpErrorCode["NAME_TOO_LONG"] = "NAME_TOO_LONG";
22
+ UdpErrorCode["INVALID_REQUEST"] = "INVALID_REQUEST";
23
+ UdpErrorCode["EMAIL_INVALID"] = "EMAIL_INVALID";
24
+ UdpErrorCode["INVALID_TOKEN_LENGTH"] = "INVALID_TOKEN_LENGTH";
25
+ UdpErrorCode["INVALID_MAP_ID"] = "INVALID_MAP_ID";
26
+ UdpErrorCode["CHUNK_NOT_FOUND"] = "CHUNK_NOT_FOUND";
27
+ UdpErrorCode["USER_NOT_AUTHENTICATED"] = "USER_NOT_AUTHENTICATED";
28
+ UdpErrorCode["INVALID_STATE_DATA"] = "INVALID_STATE_DATA";
29
+ UdpErrorCode["USER_NOT_APP_ADMIN"] = "USER_NOT_APP_ADMIN";
30
+ UdpErrorCode["GRID_OUTSIDE_ASSIGNMENT"] = "GRID_OUTSIDE_ASSIGNMENT";
31
+ UdpErrorCode["NO_MATCHING_GRID_ASSIGNMENT"] = "NO_MATCHING_GRID_ASSIGNMENT";
32
+ UdpErrorCode["INVALID_GRID_COORDINATES"] = "INVALID_GRID_COORDINATES";
33
+ UdpErrorCode["GRID_ALREADY_EXISTS"] = "GRID_ALREADY_EXISTS";
34
+ UdpErrorCode["GRID_OVERLAPS_EXISTING"] = "GRID_OVERLAPS_EXISTING";
35
+ UdpErrorCode["GAMERTAG_ALREADY_EXISTS"] = "GAMERTAG_ALREADY_EXISTS";
36
+ })(UdpErrorCode || (UdpErrorCode = {}));