oorja 2.5.3 → 2.5.4

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,4 +1,5 @@
1
1
  import { IPty } from 'node-pty';
2
+ export declare const DEFAULT_DIMENSIONS: dimensions;
2
3
  export declare const initScreen: (username: string, hostname: string, shell: string, multiplexed: boolean) => void;
3
4
  export type dimensions = {
4
5
  rows: number;
@@ -1,5 +1,6 @@
1
1
  import chalk from 'chalk';
2
2
  import termSize from 'terminal-size';
3
+ export const DEFAULT_DIMENSIONS = { rows: 24, cols: 80 };
3
4
  export const initScreen = (username, hostname, shell, multiplexed) => {
4
5
  console.log(chalk.bold(chalk.blueBright('TeleType')));
5
6
  if (multiplexed) {
@@ -11,6 +12,9 @@ To terminate stream run ${chalk.yellowBright('exit')} or press ${chalk.yellowBri
11
12
  };
12
13
  export const getDimensions = () => {
13
14
  const { rows, columns } = termSize();
15
+ if (!Number.isFinite(rows) || !Number.isFinite(columns) || rows < 1 || columns < 1) {
16
+ return DEFAULT_DIMENSIONS;
17
+ }
14
18
  return { rows, cols: columns };
15
19
  };
16
20
  export const areDimensionEqual = (a, b) => {
@@ -18,6 +22,9 @@ export const areDimensionEqual = (a, b) => {
18
22
  };
19
23
  export const resizeBestFit = (term, userDimensions, shouldClearScreen = false) => {
20
24
  const allViewports = Object.values(userDimensions);
25
+ if (allViewports.length === 0) {
26
+ return;
27
+ }
21
28
  const minrows = Math.min(...allViewports.map((d) => d.rows));
22
29
  const mincols = Math.min(...allViewports.map((d) => d.cols));
23
30
  term.resize(mincols, minrows);
@@ -1,6 +1,6 @@
1
1
  import { spawn } from 'node-pty';
2
2
  import * as os from 'os';
3
- import { getDimensions, initScreen, areDimensionEqual, resizeBestFit } from 'oorja/lib/teletype/auxiliary';
3
+ import { DEFAULT_DIMENSIONS, getDimensions, initScreen, areDimensionEqual, resizeBestFit, } from 'oorja/lib/teletype/auxiliary';
4
4
  import chalk from 'chalk';
5
5
  import { Unauthorized } from 'oorja/lib/connect/errors';
6
6
  import { encrypt, decrypt } from 'oorja/lib/encryption';
@@ -17,9 +17,7 @@ export class TeletypeSession {
17
17
  options;
18
18
  username = os.userInfo().username;
19
19
  hostname = os.hostname();
20
- userDimensions = {
21
- [SELF]: getDimensions(),
22
- };
20
+ userDimensions = {};
23
21
  channel;
24
22
  term;
25
23
  sessionCount = 0;
@@ -50,7 +48,11 @@ export class TeletypeSession {
50
48
  });
51
49
  startTerm = () => {
52
50
  const { stdin, stdout } = this.options.process;
53
- const dimensions = this.userDimensions[SELF];
51
+ const shouldReadLocalStdin = stdin.isTTY && typeof stdin.setRawMode === 'function';
52
+ const dimensions = shouldReadLocalStdin ? getDimensions() : DEFAULT_DIMENSIONS;
53
+ if (shouldReadLocalStdin) {
54
+ this.userDimensions[SELF] = dimensions;
55
+ }
54
56
  console.log(chalk.blue(`${chalk.bold(`${this.username}@${this.hostname}`)} Spawning streaming shell: ${chalk.bold(`${this.options.shell}`)}`));
55
57
  this.term = spawn(this.options.shell, [], {
56
58
  name: 'xterm-256color',
@@ -61,6 +63,9 @@ export class TeletypeSession {
61
63
  });
62
64
  this.ptyFuture.promise.then(() => {
63
65
  initScreen(this.username, this.hostname, this.options.shell, this.options.multiplex);
66
+ if (!shouldReadLocalStdin) {
67
+ return;
68
+ }
64
69
  if (this.options.shell.endsWith('bash')) {
65
70
  stdout.write('Adjusting shell prompt to show streaming indicator\n');
66
71
  this.term.write("export PS1='📡 [streaming] '$PS1\n");
@@ -102,7 +107,6 @@ export class TeletypeSession {
102
107
  this.stop({ killTerm: false });
103
108
  this.resolve?.(null);
104
109
  });
105
- const shouldReadLocalStdin = stdin.isTTY && typeof stdin.setRawMode === 'function';
106
110
  const stdinDataHandler = (d) => this.term.write(d.toString('utf8'));
107
111
  if (shouldReadLocalStdin) {
108
112
  stdin.setEncoding('utf8');
@@ -123,6 +127,9 @@ export class TeletypeSession {
123
127
  };
124
128
  };
125
129
  reEvaluateOwnDimensions = () => {
130
+ if (!this.userDimensions[SELF]) {
131
+ return;
132
+ }
126
133
  const lastKnown = this.userDimensions[SELF];
127
134
  const latest = getDimensions();
128
135
  if (areDimensionEqual(lastKnown, latest)) {
@@ -105,5 +105,5 @@
105
105
  ]
106
106
  }
107
107
  },
108
- "version": "2.5.3"
108
+ "version": "2.5.4"
109
109
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oorja",
3
3
  "description": "stream terminals to the web and more.",
4
- "version": "2.5.3",
4
+ "version": "2.5.4",
5
5
  "packageManager": "pnpm@11.5.2",
6
6
  "keywords": [
7
7
  "teletype",