@remotion/streaming 4.0.314 → 4.0.316

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.
@@ -1,5 +1,6 @@
1
1
 
2
2
  
3
- > @remotion/streaming@4.0.314 make /Users/jonathanburger/remotion/packages/streaming
4
- > tsc -d
3
+ > @remotion/streaming@4.0.316 make /Users/jonathanburger/remotion/packages/streaming
4
+ > tsc -d && bun --env-file=../.env.bundle bundle.ts
5
5
 
6
+ [6.83ms] Generated.
package/bundle.ts ADDED
@@ -0,0 +1,15 @@
1
+ import {buildPackage} from '../.monorepo/builder';
2
+
3
+ await buildPackage({
4
+ formats: {
5
+ cjs: 'use-tsc',
6
+ esm: 'build',
7
+ },
8
+ external: 'dependencies',
9
+ entrypoints: [
10
+ {
11
+ path: 'src/index.ts',
12
+ target: 'node',
13
+ },
14
+ ],
15
+ });
@@ -0,0 +1,142 @@
1
+ // src/make-stream-payload-message.ts
2
+ var magicWordStr = "remotion_buffer:";
3
+ var makeStreamPayloadMessage = ({
4
+ status,
5
+ body,
6
+ nonce
7
+ }) => {
8
+ const nonceArr = new TextEncoder().encode(nonce);
9
+ const magicWordArr = new TextEncoder().encode(magicWordStr);
10
+ const separatorArr = new TextEncoder().encode(":");
11
+ const bodyLengthArr = new TextEncoder().encode(body.length.toString());
12
+ const statusArr = new TextEncoder().encode(String(status));
13
+ const totalLength = nonceArr.length + magicWordArr.length + separatorArr.length * 3 + bodyLengthArr.length + statusArr.length + body.length;
14
+ const concat = new Uint8Array(totalLength);
15
+ let offset = 0;
16
+ const appendToConcat = (data) => {
17
+ concat.set(data, offset);
18
+ offset += data.length;
19
+ };
20
+ appendToConcat(magicWordArr);
21
+ appendToConcat(nonceArr);
22
+ appendToConcat(separatorArr);
23
+ appendToConcat(bodyLengthArr);
24
+ appendToConcat(separatorArr);
25
+ appendToConcat(statusArr);
26
+ appendToConcat(separatorArr);
27
+ appendToConcat(body);
28
+ return concat;
29
+ };
30
+ // src/make-streamer.ts
31
+ var streamingKey = "remotion_buffer:";
32
+ var makeStreamer = (onMessage) => {
33
+ const separator = new Uint8Array(streamingKey.length);
34
+ for (let i = 0;i < streamingKey.length; i++) {
35
+ separator[i] = streamingKey.charCodeAt(i);
36
+ }
37
+ let unprocessedBuffers = [];
38
+ let outputBuffer = new Uint8Array(0);
39
+ let missingData = null;
40
+ const findSeparatorIndex = () => {
41
+ let searchIndex = 0;
42
+ while (true) {
43
+ const separatorIndex = outputBuffer.indexOf(separator[0], searchIndex);
44
+ if (separatorIndex === -1) {
45
+ return -1;
46
+ }
47
+ if (outputBuffer.subarray(separatorIndex, separatorIndex + separator.length).toString() !== separator.toString()) {
48
+ searchIndex = separatorIndex + 1;
49
+ continue;
50
+ }
51
+ return separatorIndex;
52
+ }
53
+ };
54
+ const processInput = () => {
55
+ let separatorIndex = findSeparatorIndex();
56
+ if (separatorIndex === -1) {
57
+ return;
58
+ }
59
+ separatorIndex += separator.length;
60
+ let nonceString = "";
61
+ let lengthString = "";
62
+ let statusString = "";
63
+ while (true) {
64
+ if (separatorIndex > outputBuffer.length - 1) {
65
+ return;
66
+ }
67
+ const nextDigit = outputBuffer[separatorIndex];
68
+ separatorIndex++;
69
+ if (nextDigit === 58) {
70
+ break;
71
+ }
72
+ nonceString += String.fromCharCode(nextDigit);
73
+ }
74
+ while (true) {
75
+ if (separatorIndex > outputBuffer.length - 1) {
76
+ return;
77
+ }
78
+ const nextDigit = outputBuffer[separatorIndex];
79
+ separatorIndex++;
80
+ if (nextDigit === 58) {
81
+ break;
82
+ }
83
+ lengthString += String.fromCharCode(nextDigit);
84
+ }
85
+ while (true) {
86
+ if (separatorIndex > outputBuffer.length - 1) {
87
+ return;
88
+ }
89
+ const nextDigit = outputBuffer[separatorIndex];
90
+ if (nextDigit === 58) {
91
+ break;
92
+ }
93
+ separatorIndex++;
94
+ statusString += String.fromCharCode(nextDigit);
95
+ }
96
+ const length = Number(lengthString);
97
+ const status = Number(statusString);
98
+ const dataLength = outputBuffer.length - separatorIndex - 1;
99
+ if (dataLength < length) {
100
+ missingData = {
101
+ dataMissing: length - dataLength
102
+ };
103
+ return;
104
+ }
105
+ const data = outputBuffer.subarray(separatorIndex + 1, separatorIndex + 1 + Number(lengthString));
106
+ onMessage(status === 1 ? "error" : "success", nonceString, data);
107
+ missingData = null;
108
+ outputBuffer = outputBuffer.subarray(separatorIndex + Number(lengthString) + 1);
109
+ processInput();
110
+ };
111
+ const onData = (data) => {
112
+ unprocessedBuffers.push(data);
113
+ if (missingData) {
114
+ missingData.dataMissing -= data.length;
115
+ }
116
+ if (missingData && missingData.dataMissing > 0) {
117
+ return;
118
+ }
119
+ const newBuffer = new Uint8Array(outputBuffer.length + unprocessedBuffers.reduce((acc, val) => acc + val.length, 0));
120
+ newBuffer.set(outputBuffer, 0);
121
+ let offset = outputBuffer.length;
122
+ for (const buf of unprocessedBuffers) {
123
+ newBuffer.set(buf, offset);
124
+ offset += buf.length;
125
+ }
126
+ outputBuffer = newBuffer;
127
+ unprocessedBuffers = [];
128
+ processInput();
129
+ };
130
+ return {
131
+ onData,
132
+ getOutputBuffer: () => outputBuffer,
133
+ clear: () => {
134
+ unprocessedBuffers = [];
135
+ outputBuffer = new Uint8Array(0);
136
+ }
137
+ };
138
+ };
139
+ export {
140
+ makeStreamer,
141
+ makeStreamPayloadMessage
142
+ };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/streaming"
4
4
  },
5
5
  "name": "@remotion/streaming",
6
- "version": "4.0.314",
6
+ "version": "4.0.316",
7
7
  "description": "Utilities for streaming data between programs",
8
8
  "main": "dist",
9
9
  "sideEffects": false,
@@ -18,15 +18,20 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "eslint": "9.19.0",
21
- "@remotion/eslint-config-internal": "4.0.314"
21
+ "@remotion/eslint-config-internal": "4.0.316"
22
22
  },
23
23
  "exports": {
24
- ".": "./dist/index.js",
25
- "./package.json": "./package.json"
24
+ "./package.json": "./package.json",
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "require": "./dist/index.js",
28
+ "module": "./dist/esm/index.mjs",
29
+ "import": "./dist/esm/index.mjs"
30
+ }
26
31
  },
27
32
  "scripts": {
28
33
  "lint": "eslint src",
29
34
  "formatting": "prettier src --check",
30
- "make": "tsc -d"
35
+ "make": "tsc -d && bun --env-file=../.env.bundle bundle.ts"
31
36
  }
32
37
  }