Skip to content

Commit 3b3722d

Browse files
Moved control pages to client project. Abstracted away db creation.
1 parent 113ae1c commit 3b3722d

File tree

6 files changed

+97
-91
lines changed

6 files changed

+97
-91
lines changed

README.md

+34-4
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,48 @@ Then just run the following command:
1414
npx @streamerjs/streamerjs
1515
```
1616

17-
## Configuration
17+
## Scenes
18+
19+
Scenes are HTML files that are used to create the layout of the video stream. You can create multiple scenes and add them to OBS Studio as browser sources.
20+
21+
You can also create multiple files for different layers and group in folders per scene - ultimately, file organization is up to you.
22+
23+
### Create a basic scene
24+
25+
Run the following command to create a basic scene:
26+
27+
```bash
28+
npx @streamerjs/streamerjs create-scene my-scene.html
29+
```
30+
31+
Streamer JS will create a basic scene in `/scenes/` folder that has some basic HTML elements, CSS stylesheet and a JavaScript file that uses PouchDB synchronization with the [control panel](#control-panel).
32+
33+
For further customization, you can modify the scene HTML, CSS and JavaScript to accomplish whatever you want.
34+
35+
## Additional Configuration
1836

1937
To configure the application, you need to create a file named `config.json` in the root of the project. This file can contain the following information:
2038

2139
```json
2240
{
2341
"port": 2525,
24-
"dbpath": "db",
25-
"control": true
42+
"dbpath": "db"
2643
}
2744
```
2845

2946
- `port`: The port where the web server will run
3047
- `dbpath`: The path where the database will be stored
31-
- `control`: If `true`, the application will allow remote control of the stream
48+
49+
## Control Panel
50+
51+
To enable control panel, create a folder named `/control/` in the root of the project and add HTML page with a control panel that uses the PouchDB to update the UI.
52+
53+
### Create a basic control panel
54+
55+
To create a basic control panel file in `/control/` folder, run the following command:
56+
57+
```bash
58+
npx @streamerjs/streamerjs create-control-panel index.html
59+
```
60+
61+
The page will include the control panel HTML, CSS and JavaScript files and will use PouchDB to synchronize with the [scenes](#scenes).

cli.js

+32-13
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,26 @@ const insecurePort = config.port || process.env.PORT;
4040

4141
const app = express();
4242

43-
// project resources
43+
// Scenes in user's project
4444
app.use(
45-
"/scenes",
45+
"/scenes/",
4646
express.static("scenes"),
4747
serveIndex("scenes", { icons: true })
4848
);
49+
50+
// Assets in user's project
4951
app.use("/assets/", express.static("assets"));
5052

5153
// streamer resources
52-
const templates = url.fileURLToPath(import.meta.resolve("./public/"));
54+
const templates = url.fileURLToPath(import.meta.resolve("./templates/"));
5355
app.set("view engine", "ejs").set("views", templates);
5456

55-
app.get("/", (req, res) => {
56-
app.engine("ejs", ejs.renderFile);
57-
res.render("index", { control: config.control });
58-
});
57+
let enableControlPanel = false;
58+
59+
// check if control folder exists to indicate that the user wants to create the control panel(s)
60+
if (fs.existsSync("control")) {
61+
enableControlPanel = true;
5962

60-
if (config.control) {
6163
// Check if the db folder exists, create it if it doesn't
6264
if (!fs.existsSync(config.dbpath)) {
6365
try {
@@ -72,19 +74,24 @@ if (config.control) {
7274

7375
new StreamerPouchDB("streamer");
7476

75-
const controlPath = url.fileURLToPath(import.meta.resolve("./control/"));
76-
app.use("/control/", express.static(controlPath));
77+
// Control panel resources in user's project
78+
app.use("/control/", express.static("control"));
7779

80+
/**
81+
* Server paths
82+
*/
7883
const pouchDBLibPath = url.fileURLToPath(
7984
import.meta.resolve("Pouchdb/dist/")
8085
);
81-
app.use("/pouchdb/", express.static(pouchDBLibPath));
86+
// PouchDB client library
87+
app.use("/_resources/pouchdb/", express.static(pouchDBLibPath));
8288

8389
const pouchApp = ExpressPutchDBFactory(StreamerPouchDB, {
8490
logPath: config.dbpath + "/log.txt",
8591
configPath: config.dbpath + "/config.json",
8692
});
87-
app.use("/db", pouchApp);
93+
// PouchDB server
94+
app.use("/_db", pouchApp);
8895
}
8996

9097
// Get network interfaces
@@ -105,6 +112,18 @@ Object.keys(networkInterfaces).forEach((interfaceName) => {
105112
});
106113
});
107114

115+
// Server index linking to other parts of the server
116+
app.get("/", (req, res) => {
117+
app.engine("ejs", ejs.renderFile);
118+
res.render("index", { control: enableControlPanel });
119+
});
120+
121+
// Assets in user's project
122+
app.use(
123+
"/_resources/",
124+
express.static(url.fileURLToPath(import.meta.resolve("./resources/")))
125+
);
126+
108127
// HTTP server
109128
app.listen(insecurePort);
110129

@@ -113,7 +132,7 @@ ips.forEach((ip) => {
113132
console.log(`http://${ip}:${insecurePort}`);
114133
});
115134

116-
if (config.control) {
135+
if (enableControlPanel) {
117136
console.log("\nControl your stream by opening:");
118137
ips.forEach((ip) => {
119138
console.log(`http://${ip}:${insecurePort}/control/`);

control/control.js

-60
This file was deleted.

control/index.html

-14
This file was deleted.

resources/db.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const db = (() => {
2+
var localDB = new PouchDB("streamer");
3+
4+
const remoteURL = new URL("/_db/streamer", location.href).href;
5+
console.log("remoteURL", remoteURL);
6+
7+
var remoteDB = new PouchDB(remoteURL);
8+
9+
localDB
10+
.sync(remoteDB, {
11+
live: true,
12+
retry: true,
13+
})
14+
.on("change", function (change) {
15+
console.log("yo, something changed!", change);
16+
})
17+
.on("paused", function (info) {
18+
console.log(
19+
"replication was paused, usually because of a lost connection",
20+
info
21+
);
22+
})
23+
.on("active", function (info) {
24+
console.log("replication was resumed", info);
25+
})
26+
.on("error", function (err) {
27+
console.log("totally unhandled error (shouldn't happen)", err);
28+
});
29+
30+
return localDB;
31+
})();
File renamed without changes.

0 commit comments

Comments
 (0)