@petezah-games/scramjet-controller 0.0.10 → 0.1.1
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/README.md +68 -0
- package/package.json +21 -2
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Scramjet Controller
|
|
2
|
+
|
|
3
|
+
The controller package manages the coordination between the main application, service workers, and proxy transports in the Scramjet proxy. It handles RPC communication, request routing, and resource management across different execution contexts.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides the core orchestration layer for Scramjet, enabling:
|
|
8
|
+
|
|
9
|
+
- **RPC Communication**: Two-way RPC communication between the main thread, service workers, and transport layers
|
|
10
|
+
- **Request Routing**: Handling and forwarding HTTP/HTTPS requests through configured proxy transports
|
|
11
|
+
- **Resource Injection**: Injecting Scramjet utilities into web pages
|
|
12
|
+
- **Service Worker Integration**: Managing multiple service worker instances and their lifecycle
|
|
13
|
+
- **Cookie Management**: Centralized cookie jar for maintaining session state across requests
|
|
14
|
+
|
|
15
|
+
## Structure
|
|
16
|
+
|
|
17
|
+
### Core Modules
|
|
18
|
+
|
|
19
|
+
- **`index.ts`** - Main Controller class that coordinates between transports and service workers. Handles request processing, frame management, and RPC setup.
|
|
20
|
+
- **`inject.ts`** - Injection script that runs in the service worker context. Implements RemoteTransport to communicate back to the main controller via MessagePort.
|
|
21
|
+
- **`sw.ts`** - Service worker hooks that manage controller registration, request interception, and service worker lifecycle.
|
|
22
|
+
- **`types.d.ts`** - Type definitions for RPC messages and communication interfaces between different contexts.
|
|
23
|
+
- **`typesEntry.ts`** - Type entry point for the package exports.
|
|
24
|
+
|
|
25
|
+
## Exports
|
|
26
|
+
|
|
27
|
+
The package exports three main entry points:
|
|
28
|
+
|
|
29
|
+
- **`@petezah-games/scramjet-controller`** - Main Controller API
|
|
30
|
+
- **`@petezah-games/scramjet-controller/inject`** - Injection utilities for service workers
|
|
31
|
+
- **`@petezah-games/scramjet-controller/worker`** - Service worker
|
|
32
|
+
|
|
33
|
+
## Key Features
|
|
34
|
+
|
|
35
|
+
### Controller Class
|
|
36
|
+
|
|
37
|
+
The main `Controller` class manages:
|
|
38
|
+
- Connection to proxy transports
|
|
39
|
+
- Service worker lifecycle and registration
|
|
40
|
+
- Frame management for multiple contexts
|
|
41
|
+
- RPC communication with service workers
|
|
42
|
+
- Request interception and routing via Scramjet
|
|
43
|
+
|
|
44
|
+
### Configuration
|
|
45
|
+
|
|
46
|
+
Default configuration includes:
|
|
47
|
+
- `prefix`: `/~/sj/` - URL prefix for controller routes
|
|
48
|
+
- `virtualWasmPath`: `scramjet.wasm.js` - Virtual path for WASM module
|
|
49
|
+
- `injectPath`: `/controller/controller.inject.js` - Path to injection script
|
|
50
|
+
- `scramjetPath`: `/scramjet/scramjet.js` - Path to main Scramjet library
|
|
51
|
+
- `wasmPath`: `/scramjet/scramjet.wasm` - Path to WASM binary
|
|
52
|
+
|
|
53
|
+
### RPC Methods
|
|
54
|
+
|
|
55
|
+
The controller exposes RPC methods for:
|
|
56
|
+
- `ready` - Signals when the service worker is ready
|
|
57
|
+
- `request` - Processes HTTP requests
|
|
58
|
+
- Additional transport initialization and management
|
|
59
|
+
|
|
60
|
+
## Dependencies
|
|
61
|
+
|
|
62
|
+
- `@mercuryworkshop/scramjet` - Core proxy rewriting library
|
|
63
|
+
- `@mercuryworkshop/proxy-transports` - Transport abstraction layer
|
|
64
|
+
- `@mercuryworkshop/rpc` - RPC helper for inter-context communication
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
The controller is typically initialized by the bootstrap package, which sets up the service worker registration and injects the controller into the page context. Applications should interact with the controller through the RPC interface for request handling and configuration.
|
package/package.json
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@petezah-games/scramjet-controller",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Controller for Scramjet proxy, it manages coordination between application, service workers, and proxy transports",
|
|
4
5
|
"type": "module",
|
|
6
|
+
"license": "AGPL-3.0-only",
|
|
7
|
+
"author": "PeteZah Games",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/petezah-games/scramjet"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/petezah-games/scramjet/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/petezah-games/scramjet#readme",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"proxy",
|
|
18
|
+
"scramjet",
|
|
19
|
+
"web-proxy",
|
|
20
|
+
"service-worker",
|
|
21
|
+
"rpc",
|
|
22
|
+
"transport"
|
|
23
|
+
],
|
|
5
24
|
"exports": {
|
|
6
25
|
".": {
|
|
7
26
|
"import": "./dist/controller.api.js",
|
|
@@ -11,7 +30,7 @@
|
|
|
11
30
|
"import": "./dist/controller.inject.js",
|
|
12
31
|
"types": "./dist/types/inject.d.ts"
|
|
13
32
|
},
|
|
14
|
-
"./
|
|
33
|
+
"./worker": {
|
|
15
34
|
"import": "./dist/controller.sw.js",
|
|
16
35
|
"types": "./dist/types/sw.d.ts"
|
|
17
36
|
}
|