dashcam 0.4.3 → 0.5.0
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 +8 -0
- package/index.js +46 -4
- package/lib.js +32 -3
- package/package.json +1 -1
- package/recorder.js +9 -4
package/README.md
CHANGED
|
@@ -55,6 +55,14 @@ Anything you type in your terminal will appear in your dash. To exit, simply typ
|
|
|
55
55
|
exit
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
## Pipe command output into dashcam for recording
|
|
59
|
+
|
|
60
|
+
To record the output of a command in the Dashcam app (In this example the `ping 1.1.1.1` command ), use the following command
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
ping 1.1.1.1 | dashcam pipe
|
|
64
|
+
```
|
|
65
|
+
|
|
58
66
|
### Create a Replay
|
|
59
67
|
|
|
60
68
|
```sh
|
package/index.js
CHANGED
|
@@ -6,7 +6,6 @@ const lib = require("./lib");
|
|
|
6
6
|
const Recorder = require("./recorder");
|
|
7
7
|
const packageMetadata = require("./package.json");
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
if (module.parent) {
|
|
11
10
|
module.exports = lib;
|
|
12
11
|
return;
|
|
@@ -37,6 +36,10 @@ program
|
|
|
37
36
|
"Markdown body. This may also be piped in: `cat README.md | dashcam create`"
|
|
38
37
|
)
|
|
39
38
|
.option("--md", "Returns code for a rich markdown image link.")
|
|
39
|
+
.option(
|
|
40
|
+
"-p, --publish",
|
|
41
|
+
"Whether to publish the clip instantly after creation or not."
|
|
42
|
+
)
|
|
40
43
|
.action(async function (str, options) {
|
|
41
44
|
try {
|
|
42
45
|
let description = this.opts().description;
|
|
@@ -49,6 +52,7 @@ program
|
|
|
49
52
|
description,
|
|
50
53
|
private: this.opts().private,
|
|
51
54
|
md: this.opts().md,
|
|
55
|
+
publish: this.opts().publish,
|
|
52
56
|
png: this.opts().png,
|
|
53
57
|
});
|
|
54
58
|
console.log(result);
|
|
@@ -60,10 +64,11 @@ program
|
|
|
60
64
|
|
|
61
65
|
program
|
|
62
66
|
.command("record")
|
|
67
|
+
.option("-s, --silent", "Use silent mode when recording")
|
|
63
68
|
.description(
|
|
64
69
|
"Start a recording terminal to be included in your dashcam video recording"
|
|
65
70
|
)
|
|
66
|
-
.action(async function (
|
|
71
|
+
.action(async function ({ silent }) {
|
|
67
72
|
try {
|
|
68
73
|
const dashcam = new lib.PersistantDashcamIPC();
|
|
69
74
|
const id = crypto.randomUUID();
|
|
@@ -71,14 +76,51 @@ program
|
|
|
71
76
|
|
|
72
77
|
dashcam.onConnected = () => dashcam.emit("track-cli", logFile);
|
|
73
78
|
fs.appendFileSync(logFile, "");
|
|
74
|
-
const recorder = new Recorder(logFile);
|
|
79
|
+
const recorder = new Recorder(logFile, silent);
|
|
75
80
|
await recorder.start();
|
|
76
81
|
} catch (e) {
|
|
77
82
|
console.log("Error: ", e);
|
|
78
83
|
}
|
|
79
84
|
});
|
|
80
85
|
|
|
81
|
-
|
|
86
|
+
program
|
|
87
|
+
.command("pipe")
|
|
88
|
+
.description(
|
|
89
|
+
"Pipe command output to dashcam to be included in recorded video"
|
|
90
|
+
)
|
|
91
|
+
.action(async function () {
|
|
92
|
+
try {
|
|
93
|
+
const dashcam = new lib.PersistantDashcamIPC();
|
|
94
|
+
const id = crypto.randomUUID();
|
|
95
|
+
const logFile = lib.getLogFilePath(id);
|
|
96
|
+
|
|
97
|
+
dashcam.onConnected = () => dashcam.emit("track-cli", logFile);
|
|
98
|
+
fs.appendFileSync(logFile, "");
|
|
99
|
+
process.stdin.on("data", (data) => {
|
|
100
|
+
process.stdout.write(data);
|
|
101
|
+
fs.appendFileSync(logFile, data);
|
|
102
|
+
});
|
|
103
|
+
process.stdin.on("close", () => process.exit());
|
|
104
|
+
process.stdin.on("error", () => process.exit(1));
|
|
105
|
+
} catch (e) {
|
|
106
|
+
console.log("Error: ", e);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
program
|
|
111
|
+
.command("start")
|
|
112
|
+
.description("Start instant replay recording on dashcam")
|
|
113
|
+
.action(async function (name, options) {
|
|
114
|
+
try {
|
|
115
|
+
await lib.startInstantReplay();
|
|
116
|
+
process.exit(0);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
console.log("startInstantReplay error: ", e);
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
if (process.stdin.isTTY || process.argv[2] === "pipe") {
|
|
82
124
|
program.parse(process.argv);
|
|
83
125
|
} else {
|
|
84
126
|
process.stdin.on("error", function () {});
|
package/lib.js
CHANGED
|
@@ -36,6 +36,7 @@ const connectToIpc = function () {
|
|
|
36
36
|
|
|
37
37
|
const createReplay = async function (options = {}) {
|
|
38
38
|
options.md = options.md || false;
|
|
39
|
+
options.publish = options.publish || false;
|
|
39
40
|
|
|
40
41
|
options.title = options.title || false;
|
|
41
42
|
options.description = options.description || null;
|
|
@@ -46,7 +47,7 @@ const createReplay = async function (options = {}) {
|
|
|
46
47
|
ipc.of.dashcam.on(
|
|
47
48
|
"upload", //any event or message type your server listens for
|
|
48
49
|
function (data) {
|
|
49
|
-
if (options.md) {
|
|
50
|
+
if (options.md && !options.publish) {
|
|
50
51
|
resolve(data.replay.markdown);
|
|
51
52
|
} else {
|
|
52
53
|
resolve(data.replay.shareLink);
|
|
@@ -60,9 +61,33 @@ const createReplay = async function (options = {}) {
|
|
|
60
61
|
);
|
|
61
62
|
}, 60000 * 5);
|
|
62
63
|
|
|
63
|
-
|
|
64
|
+
const replay = {
|
|
64
65
|
title: options.title,
|
|
65
66
|
description: options.description,
|
|
67
|
+
publish: options.publish,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
ipc.of.dashcam.emit("create", replay);
|
|
71
|
+
|
|
72
|
+
if (!options.publish) {
|
|
73
|
+
resolve(replay);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const startInstantReplay = async function (options = {}) {
|
|
79
|
+
return new Promise(async (resolve, reject) => {
|
|
80
|
+
await connectToIpc();
|
|
81
|
+
setTimeout(() => {
|
|
82
|
+
reject(
|
|
83
|
+
"Dashcam Desktop App did not respond in time. Cancel startInstantReplay"
|
|
84
|
+
);
|
|
85
|
+
}, 60000 * 5);
|
|
86
|
+
|
|
87
|
+
ipc.of.dashcam.emit("start-instant-replay");
|
|
88
|
+
|
|
89
|
+
resolve({
|
|
90
|
+
started: true,
|
|
66
91
|
});
|
|
67
92
|
});
|
|
68
93
|
};
|
|
@@ -92,7 +117,10 @@ class PersistantDashcamIPC {
|
|
|
92
117
|
}
|
|
93
118
|
|
|
94
119
|
emit(event, payload) {
|
|
95
|
-
if (!this.#isConnected)
|
|
120
|
+
if (!this.#isConnected) {
|
|
121
|
+
console.log(`Cannot emit event: ${event}. Disconnected!`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
96
124
|
persistantIPC.of.dashcam.emit(event, payload);
|
|
97
125
|
}
|
|
98
126
|
}
|
|
@@ -103,6 +131,7 @@ const getLogFilePath = (id) => {
|
|
|
103
131
|
|
|
104
132
|
module.exports = {
|
|
105
133
|
createReplay,
|
|
134
|
+
startInstantReplay,
|
|
106
135
|
getLogFilePath,
|
|
107
136
|
PersistantDashcamIPC,
|
|
108
137
|
};
|
package/package.json
CHANGED
package/recorder.js
CHANGED
|
@@ -6,12 +6,15 @@ const find = require("find-process");
|
|
|
6
6
|
class Recorder {
|
|
7
7
|
#ptyProcess = null;
|
|
8
8
|
#logFile = null;
|
|
9
|
+
#silent = false;
|
|
9
10
|
|
|
10
|
-
constructor(logFile) {
|
|
11
|
+
constructor(logFile, silent) {
|
|
11
12
|
// This way we don't run the recording script recursively, especially
|
|
12
13
|
// if it's inside bash/zsh configs
|
|
14
|
+
this.#silent = silent;
|
|
13
15
|
if (process.env.DASHCAM_TERMINAL_RECORDING) {
|
|
14
|
-
|
|
16
|
+
if (!this.#silent)
|
|
17
|
+
console.log("The current terminal is already being recorded");
|
|
15
18
|
process.exit(0);
|
|
16
19
|
}
|
|
17
20
|
this.#logFile = logFile;
|
|
@@ -27,8 +30,10 @@ class Recorder {
|
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
async start() {
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
if (!this.#silent) {
|
|
34
|
+
console.log("This session is being recorded by Dashcam");
|
|
35
|
+
console.log("Type `exit` to stop recording");
|
|
36
|
+
}
|
|
32
37
|
|
|
33
38
|
// TODO: Find a way to consistently get the current shell this is running from
|
|
34
39
|
// instead of using the default user shell (Maybe use parent processId to find
|