kroki 1.0.2 → 1.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/bin/kroki.js +24 -7
  2. package/package.json +1 -1
package/bin/kroki.js CHANGED
@@ -70,7 +70,9 @@ class RealtimeConnection {
70
70
  this.deviceId = config.deviceId;
71
71
  this.topic = `realtime:control:${this.googleId}`;
72
72
  this.ref = 0;
73
+ this.joinRef = null;
73
74
  this.ws = null;
75
+ this.heartbeatTimer = null;
74
76
  }
75
77
 
76
78
  nextRef() {
@@ -90,7 +92,16 @@ class RealtimeConnection {
90
92
  this.ws.onopen = () => {
91
93
  clearTimeout(timer);
92
94
  this.joinChannel()
93
- .then(() => resolve(this))
95
+ .then(() => {
96
+ this.heartbeatTimer = setInterval(() => {
97
+ if (this.ws && this.ws.readyState === globalThis.WebSocket.OPEN) {
98
+ this.ws.send(
99
+ JSON.stringify({ topic: 'phoenix', event: 'heartbeat', payload: {}, ref: this.nextRef() }),
100
+ );
101
+ }
102
+ }, 25000);
103
+ resolve(this);
104
+ })
94
105
  .catch(reject);
95
106
  };
96
107
 
@@ -103,21 +114,21 @@ class RealtimeConnection {
103
114
 
104
115
  joinChannel() {
105
116
  return new Promise((resolve, reject) => {
106
- const joinRef = this.nextRef();
117
+ this.joinRef = this.nextRef();
107
118
  const payload = {
108
119
  topic: this.topic,
109
120
  event: 'phx_join',
110
121
  payload: {
111
- config: { broadcast: { self: false } },
122
+ config: { private: true, broadcast: { self: false } },
112
123
  access_token: this.token,
113
124
  },
114
- ref: joinRef,
125
+ ref: this.joinRef,
115
126
  };
116
127
 
117
128
  const handler = event => {
118
129
  try {
119
130
  const msg = JSON.parse(event.data);
120
- if (msg.ref === joinRef) {
131
+ if (msg.ref === this.joinRef) {
121
132
  this.ws.removeEventListener('message', handler);
122
133
  if (msg.payload?.status === 'ok') {
123
134
  resolve();
@@ -173,6 +184,7 @@ class RealtimeConnection {
173
184
  payload: command,
174
185
  },
175
186
  ref: msgRef,
187
+ join_ref: this.joinRef,
176
188
  };
177
189
 
178
190
  this.ws.send(JSON.stringify(packet));
@@ -180,6 +192,10 @@ class RealtimeConnection {
180
192
  }
181
193
 
182
194
  close() {
195
+ if (this.heartbeatTimer) {
196
+ clearInterval(this.heartbeatTimer);
197
+ this.heartbeatTimer = null;
198
+ }
183
199
  if (this.ws) {
184
200
  try {
185
201
  this.ws.close();
@@ -323,7 +339,9 @@ function statusCommand() {
323
339
  console.log(' npx kroki pair <CODE>');
324
340
  return;
325
341
  }
326
- console.log(`\x1b[32m✔ Paired\x1b[0m with "${session.deviceName || session.deviceId}" (${session.platform || 'browser'})`);
342
+ console.log(
343
+ `\x1b[32m✔ Paired\x1b[0m with "${session.deviceName || session.deviceId}" (${session.platform || 'browser'})`,
344
+ );
327
345
  console.log(` Device ID: ${session.deviceId}`);
328
346
  }
329
347
 
@@ -388,4 +406,3 @@ switch (first) {
388
406
  });
389
407
  break;
390
408
  }
391
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kroki",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Kroki Browser Automation CLI — Control Chrome from terminal and AI agents",
5
5
  "keywords": [
6
6
  "kroki",