oorja 2.1.2 → 2.1.3

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.
@@ -4,6 +4,7 @@ import { getDimensions, initScreen, areDimensionEqual, resizeBestFit } from './a
4
4
  import chalk from 'chalk';
5
5
  import { Unauthorized } from '../connect/errors.js';
6
6
  import { encrypt, decrypt } from '../encryption.js';
7
+ import { Future } from '../utils.js';
7
8
  var MessageType;
8
9
  (function (MessageType) {
9
10
  MessageType["IN"] = "i";
@@ -28,6 +29,8 @@ export const teletypeApp = (options) => {
28
29
  };
29
30
  return new Promise((resolve, reject) => {
30
31
  let sessionCount = 0;
32
+ let ptyReady = false;
33
+ const ptyFuture = new Future();
31
34
  const channel = options.joinChannel({
32
35
  channel: `teletype:${options.roomKey.roomId}`,
33
36
  params: {
@@ -47,7 +50,7 @@ export const teletypeApp = (options) => {
47
50
  cwd: options.process.cwd(),
48
51
  env: options.process.env,
49
52
  });
50
- setTimeout(() => {
53
+ ptyFuture.promise.then(() => {
51
54
  if (options.shell.endsWith('bash')) {
52
55
  stdout.write('Adjusting shell prompt to show streaming indicator\n');
53
56
  term.write("export PS1='📡 [streaming] '$PS1\n");
@@ -64,10 +67,14 @@ export const teletypeApp = (options) => {
64
67
  term.write('functions -c fish_prompt __orig_fish_prompt; ' +
65
68
  "function fish_prompt; echo -n '📡 [streaming] '; __orig_fish_prompt; end\n");
66
69
  }
67
- }, 100); // wait for shell to be ready
70
+ });
68
71
  // track own dimensions and keep it up to date
69
72
  setInterval(reEvaluateOwnDimensions, 1000);
70
73
  term.onData((d) => {
74
+ if (!ptyReady) {
75
+ ptyReady = true;
76
+ ptyFuture.resolve(true);
77
+ }
71
78
  stdout.write(d);
72
79
  if (sessionCount < 2) {
73
80
  // 1 sub for own channel session
@@ -1 +1,8 @@
1
1
  export declare const promptRoomLink: () => Promise<any>;
2
+ export declare class Future<T> {
3
+ promise: Promise<T>;
4
+ resolve?: (arg: T) => void;
5
+ reject?: (e: any) => void;
6
+ onFinally?: () => void;
7
+ constructor(futureBase?: (resolve: (arg: T) => void, reject: (e: any) => void) => void, onFinally?: () => void);
8
+ }
package/dist/lib/utils.js CHANGED
@@ -9,3 +9,20 @@ export const promptRoomLink = async () => {
9
9
  ]);
10
10
  return spaceLink;
11
11
  };
12
+ export class Future {
13
+ promise;
14
+ resolve;
15
+ reject;
16
+ onFinally;
17
+ constructor(futureBase, onFinally) {
18
+ this.onFinally = onFinally;
19
+ // eslint-disable-next-line no-async-promise-executor
20
+ this.promise = new Promise(async (resolve, reject) => {
21
+ this.resolve = resolve;
22
+ this.reject = reject;
23
+ if (futureBase) {
24
+ await futureBase(resolve, reject);
25
+ }
26
+ }).finally(() => this.onFinally?.());
27
+ }
28
+ }
@@ -85,5 +85,5 @@
85
85
  ]
86
86
  }
87
87
  },
88
- "version": "2.1.2"
88
+ "version": "2.1.3"
89
89
  }
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.1.2",
4
+ "version": "2.1.3",
5
5
  "keywords": [
6
6
  "teletype",
7
7
  "terminal",