@borealise/pipeline 1.0.0-alpha.0 → 1.0.0-alpha.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.
package/dist/index.d.mts CHANGED
@@ -1,132 +1,6 @@
1
- /**
2
- * Pipeline Opcodes and event codes.
3
- */
4
- declare const Opcodes: {
5
- readonly IDENTIFY: 0;
6
- readonly HEARTBEAT: 1;
7
- readonly PRESENCE_UPDATE: 2;
8
- readonly SUBSCRIBE: 3;
9
- readonly UNSUBSCRIBE: 4;
10
- readonly REQUEST: 5;
11
- readonly CHAT_SEND: 6;
12
- readonly HELLO: 16;
13
- readonly HEARTBEAT_ACK: 17;
14
- readonly READY: 18;
15
- readonly INVALID_SESSION: 19;
16
- readonly RECONNECT: 20;
17
- readonly DISPATCH: 21;
18
- readonly ERROR: 255;
19
- };
20
- type Opcode = typeof Opcodes[keyof typeof Opcodes];
21
- declare const Events: {
22
- readonly USER_UPDATE: 0;
23
- readonly USER_PRESENCE_UPDATE: 1;
24
- readonly USER_TYPING: 2;
25
- readonly USER_LEVEL_UP: 3;
26
- readonly SESSION_CREATE: 16;
27
- readonly SESSION_DELETE: 17;
28
- readonly SESSION_UPDATE: 18;
29
- readonly NOTIFICATION_CREATE: 32;
30
- readonly NOTIFICATION_DELETE: 33;
31
- readonly ROOM_JOIN: 48;
32
- readonly ROOM_LEAVE: 49;
33
- readonly ROOM_UPDATE: 50;
34
- readonly ROOM_DELETE: 51;
35
- readonly ROOM_USER_JOIN: 64;
36
- readonly ROOM_USER_LEAVE: 65;
37
- readonly ROOM_USER_KICK: 66;
38
- readonly ROOM_USER_BAN: 67;
39
- readonly ROOM_USER_MUTE: 68;
40
- readonly ROOM_USER_UNMUTE: 69;
41
- readonly ROOM_USER_ROLE_UPDATE: 70;
42
- readonly ROOM_USER_AVATAR_UPDATE: 71;
43
- readonly ROOM_USER_SUBSCRIPTION_UPDATE: 72;
44
- readonly ROOM_CHAT_MESSAGE: 80;
45
- readonly ROOM_CHAT_DELETE: 81;
46
- readonly ROOM_DJ_ADVANCE: 96;
47
- readonly ROOM_DJ_UPDATE: 97;
48
- readonly ROOM_WAITLIST_JOIN: 98;
49
- readonly ROOM_WAITLIST_LEAVE: 99;
50
- readonly ROOM_WAITLIST_UPDATE: 100;
51
- readonly ROOM_WAITLIST_LOCK: 101;
52
- readonly ROOM_WAITLIST_CYCLE: 102;
53
- readonly ROOM_TIME_SYNC: 103;
54
- readonly ROOM_VOTE: 112;
55
- readonly ROOM_GRAB: 113;
56
- readonly FRIEND_REQUEST: 128;
57
- readonly FRIEND_REQUEST_CANCEL: 129;
58
- readonly FRIEND_ACCEPT: 130;
59
- readonly FRIEND_REMOVE: 131;
60
- readonly SYSTEM_MESSAGE: 240;
61
- readonly MAINTENANCE: 241;
62
- readonly RATE_LIMIT: 242;
63
- };
64
- type EventCode = typeof Events[keyof typeof Events];
65
- declare const Presence: {
66
- readonly ONLINE: 0;
67
- readonly IDLE: 1;
68
- readonly DND: 2;
69
- readonly INVISIBLE: 3;
70
- readonly OFFLINE: 4;
71
- };
72
- type PresenceCode = typeof Presence[keyof typeof Presence];
73
- declare const Activity: {
74
- readonly NONE: 0;
75
- readonly VIEWING: 1;
76
- readonly EDITING: 2;
77
- readonly IDLE: 3;
78
- readonly STREAMING: 4;
79
- readonly LISTENING: 5;
80
- readonly WATCHING: 6;
81
- readonly CUSTOM: 255;
82
- };
83
- type ActivityCode = typeof Activity[keyof typeof Activity];
84
- declare const Roles: {
85
- readonly USER: 0;
86
- readonly MODERATOR: 1;
87
- readonly ADMIN: 2;
88
- readonly OWNER: 255;
89
- };
90
- type RoleCode = typeof Roles[keyof typeof Roles];
91
- declare const CloseCodes: {
92
- readonly NORMAL: 1000;
93
- readonly GOING_AWAY: 1001;
94
- readonly PROTOCOL_ERROR: 1002;
95
- readonly UNKNOWN_ERROR: 4000;
96
- readonly UNKNOWN_OPCODE: 4001;
97
- readonly DECODE_ERROR: 4002;
98
- readonly NOT_AUTHENTICATED: 4003;
99
- readonly AUTHENTICATION_FAILED: 4004;
100
- readonly ALREADY_AUTHENTICATED: 4005;
101
- readonly INVALID_SESSION: 4006;
102
- readonly RATE_LIMITED: 4008;
103
- readonly SESSION_TIMEOUT: 4009;
104
- readonly SERVER_SHUTDOWN: 4010;
105
- };
106
- type CloseCode = typeof CloseCodes[keyof typeof CloseCodes];
107
- declare const PipelineErrors: {
108
- readonly CHAT_MESSAGE_EMPTY: 4100;
109
- readonly CHAT_MESSAGE_TOO_LONG: 4101;
110
- readonly CHAT_ROOM_NOT_FOUND: 4102;
111
- readonly CHAT_NOT_IN_ROOM: 4103;
112
- readonly CHAT_USER_MUTED: 4104;
113
- readonly ROOM_NOT_FOUND: 4200;
114
- readonly ROOM_NOT_ACTIVE: 4201;
115
- readonly ROOM_ALREADY_MEMBER: 4202;
116
- readonly ROOM_NOT_MEMBER: 4203;
117
- readonly ROOM_BANNED: 4204;
118
- readonly ROOM_FULL: 4205;
119
- readonly WAITLIST_LOCKED: 4300;
120
- readonly WAITLIST_FULL: 4301;
121
- readonly WAITLIST_ALREADY_IN: 4302;
122
- readonly WAITLIST_NOT_IN: 4303;
123
- readonly VOTE_INVALID: 4400;
124
- readonly VOTE_ALREADY_VOTED: 4401;
125
- readonly VOTE_NO_TRACK: 4402;
126
- };
127
- type PipelineError = typeof PipelineErrors[keyof typeof PipelineErrors];
128
- declare function getPipelineErrorName(code: PipelineError): string;
129
- declare function getEventName(code: EventCode): string;
1
+ import { RoleCode, PresenceCode, ActivityCode, EventCode, Opcode } from '@borealise/shared';
2
+ export * from '@borealise/shared';
3
+ export { PipelineError, PipelineErrors, getPipelineErrorName } from '@borealise/shared';
130
4
 
131
5
  interface PipelineMessage<T = unknown> {
132
6
  op: Opcode;
@@ -207,6 +81,8 @@ interface PipelineClientOptions {
207
81
  }
208
82
 
209
83
  declare class PipelineClient {
84
+ private static readonly WS_CONNECTING;
85
+ private static readonly WS_OPEN;
210
86
  private readonly logger;
211
87
  private readonly options;
212
88
  private ws;
@@ -263,4 +139,4 @@ declare class PipelineClient {
263
139
  }
264
140
  declare function createPipeline(options: PipelineClientOptions): PipelineClient;
265
141
 
266
- export { Activity, type ActivityCode, type ChatSendPayload, type CloseCode, CloseCodes, type ConnectionState, type DispatchHandler, type ErrorPayload, type EventCode, type EventListener, Events, type HeartbeatPayload, type HelloPayload, type IdentifyPayload, type InvalidSessionPayload, type Opcode, Opcodes, PipelineClient, type PipelineClientOptions, type PipelineError, PipelineErrors, type PipelineEvents, type PipelineMessage, Presence, type PresenceCode, type PresenceUpdatePayload, type ReadyPayload, type RoleCode, Roles, type SubscribePayload, type UnsubscribePayload, createPipeline, getEventName, getPipelineErrorName };
142
+ export { type ChatSendPayload, type ConnectionState, type DispatchHandler, type ErrorPayload, type EventListener, type HeartbeatPayload, type HelloPayload, type IdentifyPayload, type InvalidSessionPayload, PipelineClient, type PipelineClientOptions, type PipelineEvents, type PipelineMessage, type PresenceUpdatePayload, type ReadyPayload, type SubscribePayload, type UnsubscribePayload, createPipeline };
package/dist/index.d.ts CHANGED
@@ -1,132 +1,6 @@
1
- /**
2
- * Pipeline Opcodes and event codes.
3
- */
4
- declare const Opcodes: {
5
- readonly IDENTIFY: 0;
6
- readonly HEARTBEAT: 1;
7
- readonly PRESENCE_UPDATE: 2;
8
- readonly SUBSCRIBE: 3;
9
- readonly UNSUBSCRIBE: 4;
10
- readonly REQUEST: 5;
11
- readonly CHAT_SEND: 6;
12
- readonly HELLO: 16;
13
- readonly HEARTBEAT_ACK: 17;
14
- readonly READY: 18;
15
- readonly INVALID_SESSION: 19;
16
- readonly RECONNECT: 20;
17
- readonly DISPATCH: 21;
18
- readonly ERROR: 255;
19
- };
20
- type Opcode = typeof Opcodes[keyof typeof Opcodes];
21
- declare const Events: {
22
- readonly USER_UPDATE: 0;
23
- readonly USER_PRESENCE_UPDATE: 1;
24
- readonly USER_TYPING: 2;
25
- readonly USER_LEVEL_UP: 3;
26
- readonly SESSION_CREATE: 16;
27
- readonly SESSION_DELETE: 17;
28
- readonly SESSION_UPDATE: 18;
29
- readonly NOTIFICATION_CREATE: 32;
30
- readonly NOTIFICATION_DELETE: 33;
31
- readonly ROOM_JOIN: 48;
32
- readonly ROOM_LEAVE: 49;
33
- readonly ROOM_UPDATE: 50;
34
- readonly ROOM_DELETE: 51;
35
- readonly ROOM_USER_JOIN: 64;
36
- readonly ROOM_USER_LEAVE: 65;
37
- readonly ROOM_USER_KICK: 66;
38
- readonly ROOM_USER_BAN: 67;
39
- readonly ROOM_USER_MUTE: 68;
40
- readonly ROOM_USER_UNMUTE: 69;
41
- readonly ROOM_USER_ROLE_UPDATE: 70;
42
- readonly ROOM_USER_AVATAR_UPDATE: 71;
43
- readonly ROOM_USER_SUBSCRIPTION_UPDATE: 72;
44
- readonly ROOM_CHAT_MESSAGE: 80;
45
- readonly ROOM_CHAT_DELETE: 81;
46
- readonly ROOM_DJ_ADVANCE: 96;
47
- readonly ROOM_DJ_UPDATE: 97;
48
- readonly ROOM_WAITLIST_JOIN: 98;
49
- readonly ROOM_WAITLIST_LEAVE: 99;
50
- readonly ROOM_WAITLIST_UPDATE: 100;
51
- readonly ROOM_WAITLIST_LOCK: 101;
52
- readonly ROOM_WAITLIST_CYCLE: 102;
53
- readonly ROOM_TIME_SYNC: 103;
54
- readonly ROOM_VOTE: 112;
55
- readonly ROOM_GRAB: 113;
56
- readonly FRIEND_REQUEST: 128;
57
- readonly FRIEND_REQUEST_CANCEL: 129;
58
- readonly FRIEND_ACCEPT: 130;
59
- readonly FRIEND_REMOVE: 131;
60
- readonly SYSTEM_MESSAGE: 240;
61
- readonly MAINTENANCE: 241;
62
- readonly RATE_LIMIT: 242;
63
- };
64
- type EventCode = typeof Events[keyof typeof Events];
65
- declare const Presence: {
66
- readonly ONLINE: 0;
67
- readonly IDLE: 1;
68
- readonly DND: 2;
69
- readonly INVISIBLE: 3;
70
- readonly OFFLINE: 4;
71
- };
72
- type PresenceCode = typeof Presence[keyof typeof Presence];
73
- declare const Activity: {
74
- readonly NONE: 0;
75
- readonly VIEWING: 1;
76
- readonly EDITING: 2;
77
- readonly IDLE: 3;
78
- readonly STREAMING: 4;
79
- readonly LISTENING: 5;
80
- readonly WATCHING: 6;
81
- readonly CUSTOM: 255;
82
- };
83
- type ActivityCode = typeof Activity[keyof typeof Activity];
84
- declare const Roles: {
85
- readonly USER: 0;
86
- readonly MODERATOR: 1;
87
- readonly ADMIN: 2;
88
- readonly OWNER: 255;
89
- };
90
- type RoleCode = typeof Roles[keyof typeof Roles];
91
- declare const CloseCodes: {
92
- readonly NORMAL: 1000;
93
- readonly GOING_AWAY: 1001;
94
- readonly PROTOCOL_ERROR: 1002;
95
- readonly UNKNOWN_ERROR: 4000;
96
- readonly UNKNOWN_OPCODE: 4001;
97
- readonly DECODE_ERROR: 4002;
98
- readonly NOT_AUTHENTICATED: 4003;
99
- readonly AUTHENTICATION_FAILED: 4004;
100
- readonly ALREADY_AUTHENTICATED: 4005;
101
- readonly INVALID_SESSION: 4006;
102
- readonly RATE_LIMITED: 4008;
103
- readonly SESSION_TIMEOUT: 4009;
104
- readonly SERVER_SHUTDOWN: 4010;
105
- };
106
- type CloseCode = typeof CloseCodes[keyof typeof CloseCodes];
107
- declare const PipelineErrors: {
108
- readonly CHAT_MESSAGE_EMPTY: 4100;
109
- readonly CHAT_MESSAGE_TOO_LONG: 4101;
110
- readonly CHAT_ROOM_NOT_FOUND: 4102;
111
- readonly CHAT_NOT_IN_ROOM: 4103;
112
- readonly CHAT_USER_MUTED: 4104;
113
- readonly ROOM_NOT_FOUND: 4200;
114
- readonly ROOM_NOT_ACTIVE: 4201;
115
- readonly ROOM_ALREADY_MEMBER: 4202;
116
- readonly ROOM_NOT_MEMBER: 4203;
117
- readonly ROOM_BANNED: 4204;
118
- readonly ROOM_FULL: 4205;
119
- readonly WAITLIST_LOCKED: 4300;
120
- readonly WAITLIST_FULL: 4301;
121
- readonly WAITLIST_ALREADY_IN: 4302;
122
- readonly WAITLIST_NOT_IN: 4303;
123
- readonly VOTE_INVALID: 4400;
124
- readonly VOTE_ALREADY_VOTED: 4401;
125
- readonly VOTE_NO_TRACK: 4402;
126
- };
127
- type PipelineError = typeof PipelineErrors[keyof typeof PipelineErrors];
128
- declare function getPipelineErrorName(code: PipelineError): string;
129
- declare function getEventName(code: EventCode): string;
1
+ import { RoleCode, PresenceCode, ActivityCode, EventCode, Opcode } from '@borealise/shared';
2
+ export * from '@borealise/shared';
3
+ export { PipelineError, PipelineErrors, getPipelineErrorName } from '@borealise/shared';
130
4
 
131
5
  interface PipelineMessage<T = unknown> {
132
6
  op: Opcode;
@@ -207,6 +81,8 @@ interface PipelineClientOptions {
207
81
  }
208
82
 
209
83
  declare class PipelineClient {
84
+ private static readonly WS_CONNECTING;
85
+ private static readonly WS_OPEN;
210
86
  private readonly logger;
211
87
  private readonly options;
212
88
  private ws;
@@ -263,4 +139,4 @@ declare class PipelineClient {
263
139
  }
264
140
  declare function createPipeline(options: PipelineClientOptions): PipelineClient;
265
141
 
266
- export { Activity, type ActivityCode, type ChatSendPayload, type CloseCode, CloseCodes, type ConnectionState, type DispatchHandler, type ErrorPayload, type EventCode, type EventListener, Events, type HeartbeatPayload, type HelloPayload, type IdentifyPayload, type InvalidSessionPayload, type Opcode, Opcodes, PipelineClient, type PipelineClientOptions, type PipelineError, PipelineErrors, type PipelineEvents, type PipelineMessage, Presence, type PresenceCode, type PresenceUpdatePayload, type ReadyPayload, type RoleCode, Roles, type SubscribePayload, type UnsubscribePayload, createPipeline, getEventName, getPipelineErrorName };
142
+ export { type ChatSendPayload, type ConnectionState, type DispatchHandler, type ErrorPayload, type EventListener, type HeartbeatPayload, type HelloPayload, type IdentifyPayload, type InvalidSessionPayload, PipelineClient, type PipelineClientOptions, type PipelineEvents, type PipelineMessage, type PresenceUpdatePayload, type ReadyPayload, type SubscribePayload, type UnsubscribePayload, createPipeline };
package/dist/index.js CHANGED
@@ -15,149 +15,25 @@ var __copyProps = (to, from, except, desc) => {
15
15
  }
16
16
  return to;
17
17
  };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
20
 
20
21
  // src/index.ts
21
22
  var index_exports = {};
22
23
  __export(index_exports, {
23
- Activity: () => Activity,
24
- CloseCodes: () => CloseCodes,
25
- Events: () => Events,
26
- Opcodes: () => Opcodes,
27
24
  PipelineClient: () => PipelineClient,
28
- PipelineErrors: () => PipelineErrors,
29
- Presence: () => Presence,
30
- Roles: () => Roles,
25
+ PipelineErrors: () => opcodes_exports.PipelineErrors,
31
26
  createPipeline: () => createPipeline,
32
- getEventName: () => getEventName,
33
- getPipelineErrorName: () => getPipelineErrorName
27
+ getPipelineErrorName: () => opcodes_exports.getPipelineErrorName
34
28
  });
35
29
  module.exports = __toCommonJS(index_exports);
36
30
 
37
31
  // src/constants/opcodes.ts
38
- var Opcodes = {
39
- IDENTIFY: 0,
40
- HEARTBEAT: 1,
41
- PRESENCE_UPDATE: 2,
42
- SUBSCRIBE: 3,
43
- UNSUBSCRIBE: 4,
44
- REQUEST: 5,
45
- CHAT_SEND: 6,
46
- HELLO: 16,
47
- HEARTBEAT_ACK: 17,
48
- READY: 18,
49
- INVALID_SESSION: 19,
50
- RECONNECT: 20,
51
- DISPATCH: 21,
52
- ERROR: 255
53
- };
54
- var Events = {
55
- USER_UPDATE: 0,
56
- USER_PRESENCE_UPDATE: 1,
57
- USER_TYPING: 2,
58
- USER_LEVEL_UP: 3,
59
- SESSION_CREATE: 16,
60
- SESSION_DELETE: 17,
61
- SESSION_UPDATE: 18,
62
- NOTIFICATION_CREATE: 32,
63
- NOTIFICATION_DELETE: 33,
64
- ROOM_JOIN: 48,
65
- ROOM_LEAVE: 49,
66
- ROOM_UPDATE: 50,
67
- ROOM_DELETE: 51,
68
- ROOM_USER_JOIN: 64,
69
- ROOM_USER_LEAVE: 65,
70
- ROOM_USER_KICK: 66,
71
- ROOM_USER_BAN: 67,
72
- ROOM_USER_MUTE: 68,
73
- ROOM_USER_UNMUTE: 69,
74
- ROOM_USER_ROLE_UPDATE: 70,
75
- ROOM_USER_AVATAR_UPDATE: 71,
76
- ROOM_USER_SUBSCRIPTION_UPDATE: 72,
77
- ROOM_CHAT_MESSAGE: 80,
78
- ROOM_CHAT_DELETE: 81,
79
- ROOM_DJ_ADVANCE: 96,
80
- ROOM_DJ_UPDATE: 97,
81
- ROOM_WAITLIST_JOIN: 98,
82
- ROOM_WAITLIST_LEAVE: 99,
83
- ROOM_WAITLIST_UPDATE: 100,
84
- ROOM_WAITLIST_LOCK: 101,
85
- ROOM_WAITLIST_CYCLE: 102,
86
- ROOM_TIME_SYNC: 103,
87
- ROOM_VOTE: 112,
88
- ROOM_GRAB: 113,
89
- FRIEND_REQUEST: 128,
90
- FRIEND_REQUEST_CANCEL: 129,
91
- FRIEND_ACCEPT: 130,
92
- FRIEND_REMOVE: 131,
93
- SYSTEM_MESSAGE: 240,
94
- MAINTENANCE: 241,
95
- RATE_LIMIT: 242
96
- };
97
- var Presence = {
98
- ONLINE: 0,
99
- IDLE: 1,
100
- DND: 2,
101
- INVISIBLE: 3,
102
- OFFLINE: 4
103
- };
104
- var Activity = {
105
- NONE: 0,
106
- VIEWING: 1,
107
- EDITING: 2,
108
- IDLE: 3,
109
- STREAMING: 4,
110
- LISTENING: 5,
111
- WATCHING: 6,
112
- CUSTOM: 255
113
- };
114
- var Roles = {
115
- USER: 0,
116
- MODERATOR: 1,
117
- ADMIN: 2,
118
- OWNER: 255
119
- };
120
- var CloseCodes = {
121
- NORMAL: 1e3,
122
- GOING_AWAY: 1001,
123
- PROTOCOL_ERROR: 1002,
124
- UNKNOWN_ERROR: 4e3,
125
- UNKNOWN_OPCODE: 4001,
126
- DECODE_ERROR: 4002,
127
- NOT_AUTHENTICATED: 4003,
128
- AUTHENTICATION_FAILED: 4004,
129
- ALREADY_AUTHENTICATED: 4005,
130
- INVALID_SESSION: 4006,
131
- RATE_LIMITED: 4008,
132
- SESSION_TIMEOUT: 4009,
133
- SERVER_SHUTDOWN: 4010
134
- };
135
- var PipelineErrors = {
136
- CHAT_MESSAGE_EMPTY: 4100,
137
- CHAT_MESSAGE_TOO_LONG: 4101,
138
- CHAT_ROOM_NOT_FOUND: 4102,
139
- CHAT_NOT_IN_ROOM: 4103,
140
- CHAT_USER_MUTED: 4104,
141
- ROOM_NOT_FOUND: 4200,
142
- ROOM_NOT_ACTIVE: 4201,
143
- ROOM_ALREADY_MEMBER: 4202,
144
- ROOM_NOT_MEMBER: 4203,
145
- ROOM_BANNED: 4204,
146
- ROOM_FULL: 4205,
147
- WAITLIST_LOCKED: 4300,
148
- WAITLIST_FULL: 4301,
149
- WAITLIST_ALREADY_IN: 4302,
150
- WAITLIST_NOT_IN: 4303,
151
- VOTE_INVALID: 4400,
152
- VOTE_ALREADY_VOTED: 4401,
153
- VOTE_NO_TRACK: 4402
154
- };
155
- function getPipelineErrorName(code) {
156
- return Object.entries(PipelineErrors).find(([, value]) => value === code)?.[0] || "UNKNOWN_ERROR";
157
- }
158
- function getEventName(code) {
159
- return Object.entries(Events).find(([, value]) => value === code)?.[0] || "UNKNOWN";
160
- }
32
+ var opcodes_exports = {};
33
+ __reExport(opcodes_exports, require("@borealise/shared"));
34
+
35
+ // src/index.ts
36
+ __reExport(index_exports, opcodes_exports, module.exports);
161
37
 
162
38
  // src/logger.ts
163
39
  var _Logger = class _Logger {
@@ -194,7 +70,7 @@ _Logger.loggers = /* @__PURE__ */ new Map();
194
70
  var Logger = _Logger;
195
71
 
196
72
  // src/PipelineClient.ts
197
- var PipelineClient = class {
73
+ var _PipelineClient = class _PipelineClient {
198
74
  constructor(options) {
199
75
  this.ws = null;
200
76
  this.sessionId = null;
@@ -234,13 +110,18 @@ var PipelineClient = class {
234
110
  this.logger.error("Cannot connect: missing pipeline url");
235
111
  return;
236
112
  }
237
- if (this.ws && (this.ws.readyState === WebSocket.CONNECTING || this.ws.readyState === WebSocket.OPEN)) {
113
+ if (this.ws && (this.ws.readyState === _PipelineClient.WS_CONNECTING || this.ws.readyState === _PipelineClient.WS_OPEN)) {
238
114
  this.logger.warn("Already connected or connecting");
239
115
  return;
240
116
  }
241
117
  this.setState("connecting");
242
118
  try {
243
- const factory = this.options.webSocketFactory || ((url) => new WebSocket(url));
119
+ const factory = this.options.webSocketFactory || (typeof globalThis.WebSocket !== "undefined" ? ((url) => new globalThis.WebSocket(url)) : null);
120
+ if (!factory) {
121
+ this.logger.error("No WebSocket runtime found. In Node.js, provide webSocketFactory (for example using ws).");
122
+ this.setState("disconnected");
123
+ return;
124
+ }
244
125
  this.ws = factory(this.options.url);
245
126
  this.ws.onopen = () => this.handleOpen();
246
127
  this.ws.onmessage = (event) => this.handleMessage(event);
@@ -255,7 +136,7 @@ var PipelineClient = class {
255
136
  this.clearTimers();
256
137
  this.reconnectAttempts = 0;
257
138
  if (this.ws) {
258
- this.ws.close(CloseCodes.NORMAL, "client disconnect");
139
+ this.ws.close(opcodes_exports.CloseCodes.NORMAL, "client disconnect");
259
140
  this.ws = null;
260
141
  }
261
142
  this.sessionId = null;
@@ -263,17 +144,17 @@ var PipelineClient = class {
263
144
  this.setState("disconnected");
264
145
  }
265
146
  identify(token) {
266
- this.send(Opcodes.IDENTIFY, { token });
147
+ this.send(opcodes_exports.Opcodes.IDENTIFY, { token });
267
148
  }
268
149
  updatePresence(status, activity) {
269
- this.send(Opcodes.PRESENCE_UPDATE, { status, activity });
150
+ this.send(opcodes_exports.Opcodes.PRESENCE_UPDATE, { status, activity });
270
151
  }
271
152
  subscribe(events) {
272
153
  for (const event of events) {
273
154
  this.subscriptions.add(event);
274
155
  }
275
156
  if (this.isIdentified) {
276
- this.send(Opcodes.SUBSCRIBE, { events });
157
+ this.send(opcodes_exports.Opcodes.SUBSCRIBE, { events });
277
158
  }
278
159
  }
279
160
  unsubscribe(events) {
@@ -281,7 +162,7 @@ var PipelineClient = class {
281
162
  this.subscriptions.delete(event);
282
163
  }
283
164
  if (this.isIdentified) {
284
- this.send(Opcodes.UNSUBSCRIBE, { events });
165
+ this.send(opcodes_exports.Opcodes.UNSUBSCRIBE, { events });
285
166
  }
286
167
  }
287
168
  sendChatMessage(roomSlug, content) {
@@ -289,7 +170,7 @@ var PipelineClient = class {
289
170
  this.logger.warn("Cannot send chat: not identified");
290
171
  return false;
291
172
  }
292
- this.send(Opcodes.CHAT_SEND, {
173
+ this.send(opcodes_exports.Opcodes.CHAT_SEND, {
293
174
  room_slug: roomSlug,
294
175
  content
295
176
  });
@@ -341,24 +222,24 @@ var PipelineClient = class {
341
222
  try {
342
223
  const message = JSON.parse(String(event.data));
343
224
  switch (message.op) {
344
- case Opcodes.HELLO:
225
+ case opcodes_exports.Opcodes.HELLO:
345
226
  this.handleHello(message.d);
346
227
  break;
347
- case Opcodes.HEARTBEAT_ACK:
228
+ case opcodes_exports.Opcodes.HEARTBEAT_ACK:
348
229
  break;
349
- case Opcodes.READY:
230
+ case opcodes_exports.Opcodes.READY:
350
231
  this.handleReady(message.d);
351
232
  break;
352
- case Opcodes.INVALID_SESSION:
233
+ case opcodes_exports.Opcodes.INVALID_SESSION:
353
234
  this.handleInvalidSession(message.d);
354
235
  break;
355
- case Opcodes.RECONNECT:
236
+ case opcodes_exports.Opcodes.RECONNECT:
356
237
  this.handleReconnect();
357
238
  break;
358
- case Opcodes.DISPATCH:
239
+ case opcodes_exports.Opcodes.DISPATCH:
359
240
  this.handleDispatch(message.t, message.d, message.s);
360
241
  break;
361
- case Opcodes.ERROR:
242
+ case opcodes_exports.Opcodes.ERROR:
362
243
  this.handleServerError(message.d);
363
244
  break;
364
245
  default:
@@ -374,9 +255,9 @@ var PipelineClient = class {
374
255
  this.ws = null;
375
256
  this.emit("onDisconnect", event.code, event.reason);
376
257
  const noReconnectCodes = [
377
- CloseCodes.AUTHENTICATION_FAILED,
378
- CloseCodes.NOT_AUTHENTICATED,
379
- CloseCodes.NORMAL
258
+ opcodes_exports.CloseCodes.AUTHENTICATION_FAILED,
259
+ opcodes_exports.CloseCodes.NOT_AUTHENTICATED,
260
+ opcodes_exports.CloseCodes.NORMAL
380
261
  ];
381
262
  if (!noReconnectCodes.includes(event.code)) {
382
263
  this.scheduleReconnect();
@@ -437,13 +318,13 @@ var PipelineClient = class {
437
318
  if (!this.heartbeatInterval) return;
438
319
  const jitter = this.heartbeatInterval * 0.1 * (Math.random() * 2 - 1);
439
320
  const interval = this.heartbeatInterval + jitter;
440
- this.heartbeatTimer = window.setInterval(() => {
321
+ this.heartbeatTimer = globalThis.setInterval(() => {
441
322
  this.sendHeartbeat();
442
323
  }, interval);
443
324
  this.sendHeartbeat();
444
325
  }
445
326
  sendHeartbeat() {
446
- this.send(Opcodes.HEARTBEAT, {
327
+ this.send(opcodes_exports.Opcodes.HEARTBEAT, {
447
328
  seq: this.lastSequence || null
448
329
  });
449
330
  }
@@ -456,14 +337,14 @@ var PipelineClient = class {
456
337
  this.setState("reconnecting");
457
338
  const backoffIndex = Math.min(this.reconnectAttempts, this.reconnectBackoff.length - 1);
458
339
  const delay = this.reconnectBackoff[backoffIndex];
459
- this.reconnectTimer = window.setTimeout(() => {
340
+ this.reconnectTimer = globalThis.setTimeout(() => {
460
341
  this.reconnectAttempts += 1;
461
342
  this.emit("onReconnect", this.reconnectAttempts);
462
343
  this.connect();
463
344
  }, delay);
464
345
  }
465
346
  send(op, data) {
466
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
347
+ if (!this.ws || this.ws.readyState !== _PipelineClient.WS_OPEN) {
467
348
  this.logger.warn("Cannot send: not connected");
468
349
  return;
469
350
  }
@@ -499,20 +380,16 @@ var PipelineClient = class {
499
380
  return fromProvider;
500
381
  }
501
382
  };
383
+ _PipelineClient.WS_CONNECTING = 0;
384
+ _PipelineClient.WS_OPEN = 1;
385
+ var PipelineClient = _PipelineClient;
502
386
  function createPipeline(options) {
503
387
  return new PipelineClient(options);
504
388
  }
505
389
  // Annotate the CommonJS export names for ESM import in node:
506
390
  0 && (module.exports = {
507
- Activity,
508
- CloseCodes,
509
- Events,
510
- Opcodes,
511
391
  PipelineClient,
512
392
  PipelineErrors,
513
- Presence,
514
- Roles,
515
393
  createPipeline,
516
- getEventName,
517
394
  getPipelineErrorName
518
395
  });
package/dist/index.mjs CHANGED
@@ -1,127 +1,37 @@
1
- // src/constants/opcodes.ts
2
- var Opcodes = {
3
- IDENTIFY: 0,
4
- HEARTBEAT: 1,
5
- PRESENCE_UPDATE: 2,
6
- SUBSCRIBE: 3,
7
- UNSUBSCRIBE: 4,
8
- REQUEST: 5,
9
- CHAT_SEND: 6,
10
- HELLO: 16,
11
- HEARTBEAT_ACK: 17,
12
- READY: 18,
13
- INVALID_SESSION: 19,
14
- RECONNECT: 20,
15
- DISPATCH: 21,
16
- ERROR: 255
17
- };
18
- var Events = {
19
- USER_UPDATE: 0,
20
- USER_PRESENCE_UPDATE: 1,
21
- USER_TYPING: 2,
22
- USER_LEVEL_UP: 3,
23
- SESSION_CREATE: 16,
24
- SESSION_DELETE: 17,
25
- SESSION_UPDATE: 18,
26
- NOTIFICATION_CREATE: 32,
27
- NOTIFICATION_DELETE: 33,
28
- ROOM_JOIN: 48,
29
- ROOM_LEAVE: 49,
30
- ROOM_UPDATE: 50,
31
- ROOM_DELETE: 51,
32
- ROOM_USER_JOIN: 64,
33
- ROOM_USER_LEAVE: 65,
34
- ROOM_USER_KICK: 66,
35
- ROOM_USER_BAN: 67,
36
- ROOM_USER_MUTE: 68,
37
- ROOM_USER_UNMUTE: 69,
38
- ROOM_USER_ROLE_UPDATE: 70,
39
- ROOM_USER_AVATAR_UPDATE: 71,
40
- ROOM_USER_SUBSCRIPTION_UPDATE: 72,
41
- ROOM_CHAT_MESSAGE: 80,
42
- ROOM_CHAT_DELETE: 81,
43
- ROOM_DJ_ADVANCE: 96,
44
- ROOM_DJ_UPDATE: 97,
45
- ROOM_WAITLIST_JOIN: 98,
46
- ROOM_WAITLIST_LEAVE: 99,
47
- ROOM_WAITLIST_UPDATE: 100,
48
- ROOM_WAITLIST_LOCK: 101,
49
- ROOM_WAITLIST_CYCLE: 102,
50
- ROOM_TIME_SYNC: 103,
51
- ROOM_VOTE: 112,
52
- ROOM_GRAB: 113,
53
- FRIEND_REQUEST: 128,
54
- FRIEND_REQUEST_CANCEL: 129,
55
- FRIEND_ACCEPT: 130,
56
- FRIEND_REMOVE: 131,
57
- SYSTEM_MESSAGE: 240,
58
- MAINTENANCE: 241,
59
- RATE_LIMIT: 242
60
- };
61
- var Presence = {
62
- ONLINE: 0,
63
- IDLE: 1,
64
- DND: 2,
65
- INVISIBLE: 3,
66
- OFFLINE: 4
67
- };
68
- var Activity = {
69
- NONE: 0,
70
- VIEWING: 1,
71
- EDITING: 2,
72
- IDLE: 3,
73
- STREAMING: 4,
74
- LISTENING: 5,
75
- WATCHING: 6,
76
- CUSTOM: 255
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
77
8
  };
78
- var Roles = {
79
- USER: 0,
80
- MODERATOR: 1,
81
- ADMIN: 2,
82
- OWNER: 255
83
- };
84
- var CloseCodes = {
85
- NORMAL: 1e3,
86
- GOING_AWAY: 1001,
87
- PROTOCOL_ERROR: 1002,
88
- UNKNOWN_ERROR: 4e3,
89
- UNKNOWN_OPCODE: 4001,
90
- DECODE_ERROR: 4002,
91
- NOT_AUTHENTICATED: 4003,
92
- AUTHENTICATION_FAILED: 4004,
93
- ALREADY_AUTHENTICATED: 4005,
94
- INVALID_SESSION: 4006,
95
- RATE_LIMITED: 4008,
96
- SESSION_TIMEOUT: 4009,
97
- SERVER_SHUTDOWN: 4010
98
- };
99
- var PipelineErrors = {
100
- CHAT_MESSAGE_EMPTY: 4100,
101
- CHAT_MESSAGE_TOO_LONG: 4101,
102
- CHAT_ROOM_NOT_FOUND: 4102,
103
- CHAT_NOT_IN_ROOM: 4103,
104
- CHAT_USER_MUTED: 4104,
105
- ROOM_NOT_FOUND: 4200,
106
- ROOM_NOT_ACTIVE: 4201,
107
- ROOM_ALREADY_MEMBER: 4202,
108
- ROOM_NOT_MEMBER: 4203,
109
- ROOM_BANNED: 4204,
110
- ROOM_FULL: 4205,
111
- WAITLIST_LOCKED: 4300,
112
- WAITLIST_FULL: 4301,
113
- WAITLIST_ALREADY_IN: 4302,
114
- WAITLIST_NOT_IN: 4303,
115
- VOTE_INVALID: 4400,
116
- VOTE_ALREADY_VOTED: 4401,
117
- VOTE_NO_TRACK: 4402
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
118
16
  };
119
- function getPipelineErrorName(code) {
120
- return Object.entries(PipelineErrors).find(([, value]) => value === code)?.[0] || "UNKNOWN_ERROR";
121
- }
122
- function getEventName(code) {
123
- return Object.entries(Events).find(([, value]) => value === code)?.[0] || "UNKNOWN";
124
- }
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+
19
+ // src/index.ts
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ PipelineClient: () => PipelineClient,
23
+ PipelineErrors: () => opcodes_exports.PipelineErrors,
24
+ createPipeline: () => createPipeline,
25
+ getPipelineErrorName: () => opcodes_exports.getPipelineErrorName
26
+ });
27
+
28
+ // src/constants/opcodes.ts
29
+ var opcodes_exports = {};
30
+ __reExport(opcodes_exports, shared_star);
31
+ import * as shared_star from "@borealise/shared";
32
+
33
+ // src/index.ts
34
+ __reExport(index_exports, opcodes_exports);
125
35
 
126
36
  // src/logger.ts
127
37
  var _Logger = class _Logger {
@@ -158,7 +68,7 @@ _Logger.loggers = /* @__PURE__ */ new Map();
158
68
  var Logger = _Logger;
159
69
 
160
70
  // src/PipelineClient.ts
161
- var PipelineClient = class {
71
+ var _PipelineClient = class _PipelineClient {
162
72
  constructor(options) {
163
73
  this.ws = null;
164
74
  this.sessionId = null;
@@ -198,13 +108,18 @@ var PipelineClient = class {
198
108
  this.logger.error("Cannot connect: missing pipeline url");
199
109
  return;
200
110
  }
201
- if (this.ws && (this.ws.readyState === WebSocket.CONNECTING || this.ws.readyState === WebSocket.OPEN)) {
111
+ if (this.ws && (this.ws.readyState === _PipelineClient.WS_CONNECTING || this.ws.readyState === _PipelineClient.WS_OPEN)) {
202
112
  this.logger.warn("Already connected or connecting");
203
113
  return;
204
114
  }
205
115
  this.setState("connecting");
206
116
  try {
207
- const factory = this.options.webSocketFactory || ((url) => new WebSocket(url));
117
+ const factory = this.options.webSocketFactory || (typeof globalThis.WebSocket !== "undefined" ? ((url) => new globalThis.WebSocket(url)) : null);
118
+ if (!factory) {
119
+ this.logger.error("No WebSocket runtime found. In Node.js, provide webSocketFactory (for example using ws).");
120
+ this.setState("disconnected");
121
+ return;
122
+ }
208
123
  this.ws = factory(this.options.url);
209
124
  this.ws.onopen = () => this.handleOpen();
210
125
  this.ws.onmessage = (event) => this.handleMessage(event);
@@ -219,7 +134,7 @@ var PipelineClient = class {
219
134
  this.clearTimers();
220
135
  this.reconnectAttempts = 0;
221
136
  if (this.ws) {
222
- this.ws.close(CloseCodes.NORMAL, "client disconnect");
137
+ this.ws.close(opcodes_exports.CloseCodes.NORMAL, "client disconnect");
223
138
  this.ws = null;
224
139
  }
225
140
  this.sessionId = null;
@@ -227,17 +142,17 @@ var PipelineClient = class {
227
142
  this.setState("disconnected");
228
143
  }
229
144
  identify(token) {
230
- this.send(Opcodes.IDENTIFY, { token });
145
+ this.send(opcodes_exports.Opcodes.IDENTIFY, { token });
231
146
  }
232
147
  updatePresence(status, activity) {
233
- this.send(Opcodes.PRESENCE_UPDATE, { status, activity });
148
+ this.send(opcodes_exports.Opcodes.PRESENCE_UPDATE, { status, activity });
234
149
  }
235
150
  subscribe(events) {
236
151
  for (const event of events) {
237
152
  this.subscriptions.add(event);
238
153
  }
239
154
  if (this.isIdentified) {
240
- this.send(Opcodes.SUBSCRIBE, { events });
155
+ this.send(opcodes_exports.Opcodes.SUBSCRIBE, { events });
241
156
  }
242
157
  }
243
158
  unsubscribe(events) {
@@ -245,7 +160,7 @@ var PipelineClient = class {
245
160
  this.subscriptions.delete(event);
246
161
  }
247
162
  if (this.isIdentified) {
248
- this.send(Opcodes.UNSUBSCRIBE, { events });
163
+ this.send(opcodes_exports.Opcodes.UNSUBSCRIBE, { events });
249
164
  }
250
165
  }
251
166
  sendChatMessage(roomSlug, content) {
@@ -253,7 +168,7 @@ var PipelineClient = class {
253
168
  this.logger.warn("Cannot send chat: not identified");
254
169
  return false;
255
170
  }
256
- this.send(Opcodes.CHAT_SEND, {
171
+ this.send(opcodes_exports.Opcodes.CHAT_SEND, {
257
172
  room_slug: roomSlug,
258
173
  content
259
174
  });
@@ -305,24 +220,24 @@ var PipelineClient = class {
305
220
  try {
306
221
  const message = JSON.parse(String(event.data));
307
222
  switch (message.op) {
308
- case Opcodes.HELLO:
223
+ case opcodes_exports.Opcodes.HELLO:
309
224
  this.handleHello(message.d);
310
225
  break;
311
- case Opcodes.HEARTBEAT_ACK:
226
+ case opcodes_exports.Opcodes.HEARTBEAT_ACK:
312
227
  break;
313
- case Opcodes.READY:
228
+ case opcodes_exports.Opcodes.READY:
314
229
  this.handleReady(message.d);
315
230
  break;
316
- case Opcodes.INVALID_SESSION:
231
+ case opcodes_exports.Opcodes.INVALID_SESSION:
317
232
  this.handleInvalidSession(message.d);
318
233
  break;
319
- case Opcodes.RECONNECT:
234
+ case opcodes_exports.Opcodes.RECONNECT:
320
235
  this.handleReconnect();
321
236
  break;
322
- case Opcodes.DISPATCH:
237
+ case opcodes_exports.Opcodes.DISPATCH:
323
238
  this.handleDispatch(message.t, message.d, message.s);
324
239
  break;
325
- case Opcodes.ERROR:
240
+ case opcodes_exports.Opcodes.ERROR:
326
241
  this.handleServerError(message.d);
327
242
  break;
328
243
  default:
@@ -338,9 +253,9 @@ var PipelineClient = class {
338
253
  this.ws = null;
339
254
  this.emit("onDisconnect", event.code, event.reason);
340
255
  const noReconnectCodes = [
341
- CloseCodes.AUTHENTICATION_FAILED,
342
- CloseCodes.NOT_AUTHENTICATED,
343
- CloseCodes.NORMAL
256
+ opcodes_exports.CloseCodes.AUTHENTICATION_FAILED,
257
+ opcodes_exports.CloseCodes.NOT_AUTHENTICATED,
258
+ opcodes_exports.CloseCodes.NORMAL
344
259
  ];
345
260
  if (!noReconnectCodes.includes(event.code)) {
346
261
  this.scheduleReconnect();
@@ -401,13 +316,13 @@ var PipelineClient = class {
401
316
  if (!this.heartbeatInterval) return;
402
317
  const jitter = this.heartbeatInterval * 0.1 * (Math.random() * 2 - 1);
403
318
  const interval = this.heartbeatInterval + jitter;
404
- this.heartbeatTimer = window.setInterval(() => {
319
+ this.heartbeatTimer = globalThis.setInterval(() => {
405
320
  this.sendHeartbeat();
406
321
  }, interval);
407
322
  this.sendHeartbeat();
408
323
  }
409
324
  sendHeartbeat() {
410
- this.send(Opcodes.HEARTBEAT, {
325
+ this.send(opcodes_exports.Opcodes.HEARTBEAT, {
411
326
  seq: this.lastSequence || null
412
327
  });
413
328
  }
@@ -420,14 +335,14 @@ var PipelineClient = class {
420
335
  this.setState("reconnecting");
421
336
  const backoffIndex = Math.min(this.reconnectAttempts, this.reconnectBackoff.length - 1);
422
337
  const delay = this.reconnectBackoff[backoffIndex];
423
- this.reconnectTimer = window.setTimeout(() => {
338
+ this.reconnectTimer = globalThis.setTimeout(() => {
424
339
  this.reconnectAttempts += 1;
425
340
  this.emit("onReconnect", this.reconnectAttempts);
426
341
  this.connect();
427
342
  }, delay);
428
343
  }
429
344
  send(op, data) {
430
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
345
+ if (!this.ws || this.ws.readyState !== _PipelineClient.WS_OPEN) {
431
346
  this.logger.warn("Cannot send: not connected");
432
347
  return;
433
348
  }
@@ -463,19 +378,17 @@ var PipelineClient = class {
463
378
  return fromProvider;
464
379
  }
465
380
  };
381
+ _PipelineClient.WS_CONNECTING = 0;
382
+ _PipelineClient.WS_OPEN = 1;
383
+ var PipelineClient = _PipelineClient;
466
384
  function createPipeline(options) {
467
385
  return new PipelineClient(options);
468
386
  }
387
+ var export_PipelineErrors = opcodes_exports.PipelineErrors;
388
+ var export_getPipelineErrorName = opcodes_exports.getPipelineErrorName;
469
389
  export {
470
- Activity,
471
- CloseCodes,
472
- Events,
473
- Opcodes,
474
390
  PipelineClient,
475
- PipelineErrors,
476
- Presence,
477
- Roles,
391
+ export_PipelineErrors as PipelineErrors,
478
392
  createPipeline,
479
- getEventName,
480
- getPipelineErrorName
393
+ export_getPipelineErrorName as getPipelineErrorName
481
394
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@borealise/pipeline",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.0-alpha.2",
4
4
  "description": "Official realtime pipeline client for Borealise",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -42,5 +42,8 @@
42
42
  "devDependencies": {
43
43
  "tsup": "^8.5.0",
44
44
  "typescript": "^5.9.2"
45
+ },
46
+ "dependencies": {
47
+ "@borealise/shared": "^1.0.0"
45
48
  }
46
49
  }