Skip to content

Commit a7a1b74

Browse files
merge
2 parents daad8c7 + cb67ca6 commit a7a1b74

File tree

7 files changed

+65
-31
lines changed

7 files changed

+65
-31
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## [0.11.1](https://github.com/codesandbox/codesandbox-sdk/compare/v0.11.0...v0.11.1) (2025-03-13)
4+
5+
6+
### Bug Fixes
7+
8+
* support `keepActiveWhileConnected` for browser sessions ([#81](https://github.com/codesandbox/codesandbox-sdk/issues/81)) ([ca1f825](https://github.com/codesandbox/codesandbox-sdk/commit/ca1f82582d2f12b84cdf379902c596e6d5bfed52))
9+
10+
## [0.11.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.10.0...v0.11.0) (2025-03-11)
11+
12+
13+
### Features
14+
15+
* add support for configuring auto-wake behaviour ([#79](https://github.com/codesandbox/codesandbox-sdk/issues/79)) ([8c2ef89](https://github.com/codesandbox/codesandbox-sdk/commit/8c2ef897b03ce2d3f4865f6e68e2c2f07824852c))
16+
317
## [0.10.0](https://github.com/codesandbox/codesandbox-sdk/compare/v0.9.0...v0.10.0) (2025-02-28)
418

519

openapi.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
"type": "boolean"
244244
},
245245
"websocket": {
246-
"default": false,
246+
"default": true,
247247
"description": "Whether the VM should automatically wake up on WebSocket connections",
248248
"type": "boolean"
249249
}
@@ -520,7 +520,7 @@
520520
"type": "boolean"
521521
},
522522
"websocket": {
523-
"default": false,
523+
"default": true,
524524
"description": "Whether the VM should automatically wake up on WebSocket connections",
525525
"type": "boolean"
526526
}
@@ -1957,6 +1957,6 @@
19571957
}
19581958
},
19591959
"security": [],
1960-
"servers": [{ "url": "https://api.codesandbox.io", "variables": {} }],
1960+
"servers": [{ "url": "https://api.codesandbox.stream", "variables": {} }],
19611961
"tags": []
19621962
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codesandbox/sdk",
3-
"version": "0.10.0",
3+
"version": "0.11.1",
44
"description": "The CodeSandbox SDK",
55
"author": "CodeSandbox",
66
"license": "MIT",

src/sandbox-client.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ function startOptionsFromOpts(opts: StartSandboxOpts | undefined) {
212212
ipcountry: opts.ipcountry,
213213
tier: opts.vmTier?.name,
214214
hibernation_timeout_seconds: opts.hibernationTimeoutSeconds,
215+
automatic_wakeup_config: opts.automaticWakeupConfig,
215216
};
216217
}
217218

@@ -240,6 +241,25 @@ export interface StartSandboxOpts {
240241
* Defaults to 300 seconds for free users, 1800 seconds for pro users. Maximum is 86400 seconds (1 day).
241242
*/
242243
hibernationTimeoutSeconds?: number;
244+
245+
/**
246+
* Configuration for when the VM should automatically wake up from hibernation.
247+
*/
248+
automaticWakeupConfig?: {
249+
/**
250+
* Whether the VM should automatically wake up on HTTP requests to preview URLs (excludes WebSocket requests)
251+
*
252+
* @default true
253+
*/
254+
http: boolean;
255+
256+
/**
257+
* Whether the VM should automatically wake up on WebSocket connections to preview URLs
258+
*
259+
* @default false
260+
*/
261+
websocket: boolean;
262+
};
243263
}
244264

245265
export type HandledResponse<D, E> = {

src/sandbox.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,30 @@ export class SandboxSession extends Disposable {
183183
this.pitcherClient.disconnect();
184184
this.dispose();
185185
}
186+
187+
private keepAliveInterval: NodeJS.Timeout | null = null;
188+
/**
189+
* If enabled, we will keep the sandbox from hibernating as long as the SDK is connected to it.
190+
*/
191+
public keepActiveWhileConnected(enabled: boolean) {
192+
if (enabled && !this.keepAliveInterval) {
193+
this.keepAliveInterval = setInterval(() => {
194+
this.pitcherClient.clients.system.update();
195+
}, 1000 * 30);
196+
197+
this.onWillDispose(() => {
198+
if (this.keepAliveInterval) {
199+
clearInterval(this.keepAliveInterval);
200+
this.keepAliveInterval = null;
201+
}
202+
});
203+
} else {
204+
if (this.keepAliveInterval) {
205+
clearInterval(this.keepAliveInterval);
206+
this.keepAliveInterval = null;
207+
}
208+
}
209+
}
186210
}
187211

188212
export class Sandbox extends SandboxSession {
@@ -281,28 +305,4 @@ export class Sandbox extends SandboxSession {
281305
public async updateHibernationTimeout(timeoutSeconds: number): Promise<void> {
282306
await this.sandboxClient.updateHibernationTimeout(this.id, timeoutSeconds);
283307
}
284-
285-
private keepAliveInterval: NodeJS.Timeout | null = null;
286-
/**
287-
* If enabled, we will keep the sandbox from hibernating as long as the SDK is connected to it.
288-
*/
289-
public keepActiveWhileConnected(enabled: boolean) {
290-
if (enabled && !this.keepAliveInterval) {
291-
this.keepAliveInterval = setInterval(() => {
292-
this.pitcherClient.clients.system.update();
293-
}, 1000 * 30);
294-
295-
this.onWillDispose(() => {
296-
if (this.keepAliveInterval) {
297-
clearInterval(this.keepAliveInterval);
298-
this.keepAliveInterval = null;
299-
}
300-
});
301-
} else {
302-
if (this.keepAliveInterval) {
303-
clearInterval(this.keepAliveInterval);
304-
this.keepAliveInterval = null;
305-
}
306-
}
307-
}
308308
}

src/shells.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class Shells extends Disposable {
108108
* ## Example
109109
*
110110
* ```ts
111-
* const shell = await sandbox.shell.runCommand("echo 'Hello, world!'");
111+
* const shell = sandbox.shell.run("echo 'Hello, world!'");
112112
*
113113
* shell.onOutput((data) => {
114114
* console.log(data);

0 commit comments

Comments
 (0)