Skip to content

Commit

Permalink
miscellaneous tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Mar 4, 2021
1 parent a2d682a commit 9890a74
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 98 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
npm test
env:
FORCE_COLOR: 1
JEST_IMAGE_SNAPSHOT_TRACK_OBSOLETE: 1

- name: Upload failed screenshot tests
uses: actions/upload-artifact@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __diff_output__
dist
.cache
index.d.ts
.jest*
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

18 changes: 9 additions & 9 deletions browser/jsmpeg.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ export type PlayerOptions = {
/** when streaming, size in bytes for the audio decode buffer. Default 128*1024 (128kb). You may have to increase this for very high bitrates. */
audioBufferSize?: number;
/** A callback that is called after each decoded and rendered video frame */
onVideoDecode?(cb: (decoder: unknown, time: unknown) => void): void;
onVideoDecode?(decoder: unknown, time: unknown): void;
/** A callback that is called after each decoded audio frame */
onAudioDecode?(cb: (decoder: unknown, time: unknown) => void): void;
onAudioDecode?(decoder: unknown, time: unknown): void;
/** A callback that is called whenever playback starts */
onPlay?(cb: (player: Player) => void);
onPlay?(player: Player): void;
/** A callback that is called whenever playback paused (e.g. when .pause() is called or the source has ended) */
onPause?(cb: (player: Player) => void);
onPause?(player: Player): void;
/** A callback that is called when playback has reached the end of the source (only called when loop is false). */
onEnded?(cb: (player: Player) => void);
/** A callback that is called whenever there's not enough data for playback */
onStalled?(cb: (player: Player) => void);
onEnded?(player: Player): void;
/** @deprecated A callback that is called whenever there's not enough data for playback */
onStalled?(player: Player): void;
/** A callback that is called when source has first received data */
onSourceEstablished?(cb: (source: unknown) => void);
onSourceEstablished?(source: unknown): void;
/** A callback that is called when the source has received all data */
onSourceCompleted?(cb: (source: unknown) => void);
onSourceCompleted?(source: unknown): void;
};

export class Player {
Expand Down
19 changes: 11 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,18 @@ class InboundStreamWrapper {
kill(clientsLeft) {
if (!this.stream) return; // the stream is currently dead
if (!clientsLeft) {
if (this.verbose)
if (this.verbose) {
console.log('[rtsp-relay] no clients left; destroying stream');
}
this.stream.kill('SIGTERM');
this.stream = null;
// next time it is requested it will be recreated
}
if (this.verbose)
if (this.verbose) {
console.log(
'[rtsp-relay] there are still some clients so not destroying stream',
);
}
}
}

Expand Down Expand Up @@ -132,12 +134,12 @@ module.exports = (app, server) => {
/** @param {WebSocket} ws */
function handler(ws) {
// these should be detected from the source stream
const [width, height] = [0, 0];
const [width, height] = [0x0, 0x0];

const streamHeader = Buffer.alloc(8);
const streamHeader = Buffer.alloc(0x8);
streamHeader.write('jsmp');
streamHeader.writeUInt16BE(width, 4);
streamHeader.writeUInt16BE(height, 6);
streamHeader.writeUInt16BE(width, 0x4);
streamHeader.writeUInt16BE(height, 0x6);
ws.send(streamHeader, { binary: true });

if (verbose) console.log('[rtsp-relay] New WebSocket Connection');
Expand All @@ -146,13 +148,14 @@ module.exports = (app, server) => {

/** @param {Buffer} chunk */
function onData(chunk) {
if (ws.readyState === 1) ws.send(chunk);
if (ws.readyState === ws.OPEN) ws.send(chunk);
}

ws.on('close', () => {
const c = wsServer.clients.size;
if (verbose)
if (verbose) {
console.log(`[rtsp-relay] WebSocket Disconnected ${c} left`);
}
Inbound[url].kill(c);
streamIn.stdout.off('data', onData);
});
Expand Down
142 changes: 71 additions & 71 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
],
"scripts": {
"pretest": "chmod u+x test/rtsp-simple-server && parcel build test/react/react.html",
"lint": "eslint --format pretty --ext .js --ignore-path .gitignore .",
"lint": "eslint --format pretty --ext .js,ts,.tsx --ignore-path .gitignore .",
"test": "tsc && jest --runInBand",
"build": "tsc index.js browser/index.js --declaration --allowJs --emitDeclarationOnly --resolveJsonModule",
"trypublish": "npm publish || true"
Expand All @@ -47,7 +47,7 @@
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.1",
"eslint": "^7.20.0",
"eslint-config-kyle": "^1.0.155",
"eslint-config-kyle": "^2.0.0",
"express": "^4.17.1",
"jest": "^26.6.3",
"jest-image-snapshot": "^4.3.0",
Expand All @@ -60,12 +60,17 @@
"eslintConfig": {
"extends": "kyle"
},
"prettier": "eslint-config-kyle/prettier",
"jest": {
"forceExit": true,
"testTimeout": 20000,
"setupFiles": [
"./test/setupTests.js"
],
"reporters": [
"default",
"jest-image-snapshot/src/outdated-snapshot-reporter.js"
],
"collectCoverage": true
}
}
Loading

0 comments on commit 9890a74

Please sign in to comment.