@celljs/ta-host 4.17.0 → 4.19.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.
Files changed (153) hide show
  1. package/esm/node/account-service.d.ts +73 -0
  2. package/esm/node/account-service.js +304 -0
  3. package/esm/node/app-commands.d.ts +1 -1
  4. package/esm/node/app-commands.js +46 -29
  5. package/esm/node/credentials.d.ts +12 -0
  6. package/esm/node/credentials.js +35 -0
  7. package/esm/node/host-protocol.d.ts +2 -0
  8. package/esm/node/host-protocol.js +2 -0
  9. package/esm/node/index.d.ts +3 -0
  10. package/esm/node/index.js +3 -0
  11. package/esm/node/keep-awake.d.ts +3 -0
  12. package/esm/node/keep-awake.js +6 -1
  13. package/esm/node/package-hosts.d.ts +4 -0
  14. package/esm/node/package-hosts.js +18 -1
  15. package/esm/node/relay-bridge.js +1 -1
  16. package/esm/node/rooms-bridge.d.ts +10 -1
  17. package/esm/node/rooms-bridge.js +25 -0
  18. package/esm/node/screen-share/desktop-picture.d.ts +51 -0
  19. package/esm/node/screen-share/desktop-picture.js +133 -0
  20. package/esm/node/screen-share/desktop-session.d.ts +128 -0
  21. package/esm/node/screen-share/desktop-session.js +437 -0
  22. package/esm/node/screen-share/desktop-targets.d.ts +24 -0
  23. package/esm/node/screen-share/desktop-targets.js +80 -0
  24. package/esm/node/screen-share/desktop-viewer.d.ts +146 -0
  25. package/esm/node/screen-share/desktop-viewer.js +339 -0
  26. package/esm/node/screen-share/index.d.ts +8 -0
  27. package/esm/node/screen-share/index.js +9 -0
  28. package/esm/node/screen-share/rfb-client.d.ts +54 -0
  29. package/esm/node/screen-share/rfb-client.js +179 -0
  30. package/esm/node/screen-share/rfb-des.d.ts +11 -0
  31. package/esm/node/screen-share/rfb-des.js +143 -0
  32. package/esm/node/screen-share/rfb-encodings.d.ts +71 -0
  33. package/esm/node/screen-share/rfb-encodings.js +288 -0
  34. package/esm/node/screen-share/rfb-framebuffer.d.ts +16 -0
  35. package/esm/node/screen-share/rfb-framebuffer.js +53 -0
  36. package/esm/node/screen-share/rfb-protocol.d.ts +90 -0
  37. package/esm/node/screen-share/rfb-protocol.js +36 -0
  38. package/esm/node/screen-share/rfb-reader.d.ts +34 -0
  39. package/esm/node/screen-share/rfb-reader.js +110 -0
  40. package/esm/node/screen-share/rfb-security.d.ts +30 -0
  41. package/esm/node/screen-share/rfb-security.js +136 -0
  42. package/esm/node/screen-share/rfb-test-server.d.ts +37 -0
  43. package/esm/node/screen-share/rfb-test-server.js +116 -0
  44. package/esm/node/screen-share/screen-share-server-impl.d.ts +37 -0
  45. package/esm/node/screen-share/screen-share-server-impl.js +76 -0
  46. package/esm/node/screen-share/screen-shares.d.ts +123 -0
  47. package/esm/node/screen-share/screen-shares.js +463 -0
  48. package/esm/node/session-info-util.d.ts +10 -11
  49. package/esm/node/session-info-util.js +16 -94
  50. package/esm/node/settings-store.d.ts +1 -1
  51. package/esm/node/settings-store.js +7 -4
  52. package/esm/node/sign-in/access-store.d.ts +1 -1
  53. package/esm/node/sign-in/access-store.js +4 -1
  54. package/esm/node/sign-in/index.d.ts +2 -0
  55. package/esm/node/sign-in/index.js +2 -0
  56. package/esm/node/sign-in/polled-sign-in.d.ts +50 -0
  57. package/esm/node/sign-in/polled-sign-in.js +83 -0
  58. package/esm/node/sign-in/sign-in-devices.d.ts +55 -0
  59. package/esm/node/sign-in/sign-in-devices.js +113 -0
  60. package/esm/node/sign-in/sign-in-flow.d.ts +38 -4
  61. package/esm/node/sign-in/sign-in-flow.js +79 -4
  62. package/esm/node/sign-in/sign-in-pages.d.ts +8 -0
  63. package/esm/node/sign-in/sign-in-pages.js +137 -8
  64. package/esm/node/sign-in/sign-in-provider.d.ts +6 -0
  65. package/esm/node/sign-in/sign-in-provider.js +15 -0
  66. package/esm/node/sources-extension.d.ts +10 -0
  67. package/esm/node/sources-extension.js +18 -0
  68. package/esm/node/ta-server-impl.js +3 -3
  69. package/esm/node/ta-session-factory.js +2 -0
  70. package/esm/node/team/team-calls.js +35 -0
  71. package/esm/node/voice-bridge.d.ts +3 -1
  72. package/esm/node/voice-bridge.js +10 -3
  73. package/esm/node/voices-file.d.ts +5 -0
  74. package/esm/node/voices-file.js +14 -3
  75. package/esm/node/working-directory.d.ts +8 -2
  76. package/esm/node/working-directory.js +7 -0
  77. package/lib/node/account-service.d.ts +74 -0
  78. package/lib/node/account-service.js +307 -0
  79. package/lib/node/app-commands.d.ts +1 -1
  80. package/lib/node/app-commands.js +46 -29
  81. package/lib/node/credentials.d.ts +13 -0
  82. package/lib/node/credentials.js +38 -0
  83. package/lib/node/host-protocol.d.ts +2 -0
  84. package/lib/node/host-protocol.js +3 -1
  85. package/lib/node/index.d.ts +3 -0
  86. package/lib/node/index.js +3 -0
  87. package/lib/node/keep-awake.d.ts +3 -0
  88. package/lib/node/keep-awake.js +6 -1
  89. package/lib/node/package-hosts.d.ts +4 -0
  90. package/lib/node/package-hosts.js +17 -0
  91. package/lib/node/relay-bridge.js +1 -1
  92. package/lib/node/rooms-bridge.d.ts +10 -1
  93. package/lib/node/rooms-bridge.js +25 -0
  94. package/lib/node/screen-share/desktop-picture.d.ts +52 -0
  95. package/lib/node/screen-share/desktop-picture.js +136 -0
  96. package/lib/node/screen-share/desktop-session.d.ts +129 -0
  97. package/lib/node/screen-share/desktop-session.js +442 -0
  98. package/lib/node/screen-share/desktop-targets.d.ts +25 -0
  99. package/lib/node/screen-share/desktop-targets.js +84 -0
  100. package/lib/node/screen-share/desktop-viewer.d.ts +147 -0
  101. package/lib/node/screen-share/desktop-viewer.js +343 -0
  102. package/lib/node/screen-share/index.d.ts +9 -0
  103. package/lib/node/screen-share/index.js +25 -0
  104. package/lib/node/screen-share/rfb-client.d.ts +55 -0
  105. package/lib/node/screen-share/rfb-client.js +183 -0
  106. package/lib/node/screen-share/rfb-des.d.ts +12 -0
  107. package/lib/node/screen-share/rfb-des.js +146 -0
  108. package/lib/node/screen-share/rfb-encodings.d.ts +72 -0
  109. package/lib/node/screen-share/rfb-encodings.js +295 -0
  110. package/lib/node/screen-share/rfb-framebuffer.d.ts +17 -0
  111. package/lib/node/screen-share/rfb-framebuffer.js +57 -0
  112. package/lib/node/screen-share/rfb-protocol.d.ts +91 -0
  113. package/lib/node/screen-share/rfb-protocol.js +39 -0
  114. package/lib/node/screen-share/rfb-reader.d.ts +35 -0
  115. package/lib/node/screen-share/rfb-reader.js +115 -0
  116. package/lib/node/screen-share/rfb-security.d.ts +31 -0
  117. package/lib/node/screen-share/rfb-security.js +141 -0
  118. package/lib/node/screen-share/rfb-test-server.d.ts +38 -0
  119. package/lib/node/screen-share/rfb-test-server.js +120 -0
  120. package/lib/node/screen-share/screen-share-server-impl.d.ts +38 -0
  121. package/lib/node/screen-share/screen-share-server-impl.js +79 -0
  122. package/lib/node/screen-share/screen-shares.d.ts +124 -0
  123. package/lib/node/screen-share/screen-shares.js +464 -0
  124. package/lib/node/session-info-util.d.ts +10 -11
  125. package/lib/node/session-info-util.js +15 -93
  126. package/lib/node/settings-store.d.ts +1 -1
  127. package/lib/node/settings-store.js +6 -3
  128. package/lib/node/sign-in/access-store.d.ts +1 -1
  129. package/lib/node/sign-in/access-store.js +4 -1
  130. package/lib/node/sign-in/index.d.ts +2 -0
  131. package/lib/node/sign-in/index.js +2 -0
  132. package/lib/node/sign-in/polled-sign-in.d.ts +51 -0
  133. package/lib/node/sign-in/polled-sign-in.js +87 -0
  134. package/lib/node/sign-in/sign-in-devices.d.ts +56 -0
  135. package/lib/node/sign-in/sign-in-devices.js +117 -0
  136. package/lib/node/sign-in/sign-in-flow.d.ts +38 -4
  137. package/lib/node/sign-in/sign-in-flow.js +80 -5
  138. package/lib/node/sign-in/sign-in-pages.d.ts +8 -0
  139. package/lib/node/sign-in/sign-in-pages.js +136 -7
  140. package/lib/node/sign-in/sign-in-provider.d.ts +6 -0
  141. package/lib/node/sign-in/sign-in-provider.js +15 -0
  142. package/lib/node/sources-extension.d.ts +11 -0
  143. package/lib/node/sources-extension.js +22 -0
  144. package/lib/node/ta-server-impl.js +2 -2
  145. package/lib/node/ta-session-factory.js +2 -0
  146. package/lib/node/team/team-calls.js +35 -0
  147. package/lib/node/voice-bridge.d.ts +3 -1
  148. package/lib/node/voice-bridge.js +9 -2
  149. package/lib/node/voices-file.d.ts +5 -0
  150. package/lib/node/voices-file.js +14 -3
  151. package/lib/node/working-directory.d.ts +8 -2
  152. package/lib/node/working-directory.js +7 -0
  153. package/package.json +14 -10
@@ -123,4 +123,6 @@ export interface TaPresenceBook {
123
123
  /** What `people` gives may have changed. */
124
124
  onChange(listener: () => void): () => void;
125
125
  }
126
+ /** TaAccountService (account-service.ts): the account of this computer, by this symbol so that the relay bridge needs no import of it. */
127
+ export declare const TA_ACCOUNT: unique symbol;
126
128
  //# sourceMappingURL=host-protocol.d.ts.map
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TA_EXEC_OPTIONS = exports.TA_HOST_OPTIONS = exports.TaPresenceBook = exports.KeepAwake = exports.WebExtensionCatalog = exports.TaSessionCatalog = exports.TaSessionRegistry = exports.TaSessionFactory = void 0;
3
+ exports.TA_ACCOUNT = exports.TA_EXEC_OPTIONS = exports.TA_HOST_OPTIONS = exports.TaPresenceBook = exports.KeepAwake = exports.WebExtensionCatalog = exports.TaSessionCatalog = exports.TaSessionRegistry = exports.TaSessionFactory = void 0;
4
4
  exports.TaSessionFactory = Symbol('TaSessionFactory');
5
5
  exports.TaSessionRegistry = Symbol('TaSessionRegistry');
6
6
  exports.TaSessionCatalog = Symbol('TaSessionCatalog');
@@ -9,4 +9,6 @@ exports.KeepAwake = Symbol('KeepAwake');
9
9
  exports.TaPresenceBook = Symbol('TaPresenceBook');
10
10
  exports.TA_HOST_OPTIONS = 'ta.host';
11
11
  exports.TA_EXEC_OPTIONS = 'ta.exec';
12
+ /** TaAccountService (account-service.ts): the account of this computer, by this symbol so that the relay bridge needs no import of it. */
13
+ exports.TA_ACCOUNT = Symbol('TaAccount');
12
14
  //# sourceMappingURL=host-protocol.js.map
@@ -1,7 +1,9 @@
1
+ export * from './account-service';
1
2
  export * from './app-commands';
2
3
  export * from './auth-server-impl';
3
4
  export * from './client-channel';
4
5
  export * from './client-tool-broker';
6
+ export * from './credentials';
5
7
  export * from './directory-relocator';
6
8
  export * from './event-log';
7
9
  export * from './exec-endpoint';
@@ -24,6 +26,7 @@ export * from './relay-bridge';
24
26
  export * from './remote';
25
27
  export * from './remote-ui-context';
26
28
  export * from './rooms-bridge';
29
+ export * from './screen-share';
27
30
  export * from './serve-updates';
28
31
  export * from './session-catalog';
29
32
  export * from './session-files';
package/lib/node/index.js CHANGED
@@ -14,10 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./account-service"), exports);
17
18
  __exportStar(require("./app-commands"), exports);
18
19
  __exportStar(require("./auth-server-impl"), exports);
19
20
  __exportStar(require("./client-channel"), exports);
20
21
  __exportStar(require("./client-tool-broker"), exports);
22
+ __exportStar(require("./credentials"), exports);
21
23
  __exportStar(require("./directory-relocator"), exports);
22
24
  __exportStar(require("./event-log"), exports);
23
25
  __exportStar(require("./exec-endpoint"), exports);
@@ -40,6 +42,7 @@ __exportStar(require("./relay-bridge"), exports);
40
42
  __exportStar(require("./remote"), exports);
41
43
  __exportStar(require("./remote-ui-context"), exports);
42
44
  __exportStar(require("./rooms-bridge"), exports);
45
+ __exportStar(require("./screen-share"), exports);
43
46
  __exportStar(require("./serve-updates"), exports);
44
47
  __exportStar(require("./session-catalog"), exports);
45
48
  __exportStar(require("./session-files"), exports);
@@ -2,6 +2,7 @@ import { type ChildProcess } from 'node:child_process';
2
2
  import { type Application, ApplicationLifecycle } from '@celljs/core';
3
3
  import { KeepAwake, TaSessionRegistry } from './host-protocol';
4
4
  import { type RelayBridge } from './relay-bridge';
5
+ import { ScreenShares } from './screen-share/screen-shares';
5
6
  /** What KeepAwakeUtil.wanted weighs. */
6
7
  export interface KeepAwakeState {
7
8
  /** Not turned off (RelayConfig.keepAwake). */
@@ -30,6 +31,8 @@ export declare namespace KeepAwakeUtil {
30
31
  export declare class KeepAwakeImpl implements KeepAwake, ApplicationLifecycle<Application> {
31
32
  protected readonly bridge: RelayBridge;
32
33
  protected readonly sessions: TaSessionRegistry;
34
+ /** A page looking at a desktop keeps the computer awake as a session that runs does. */
35
+ protected readonly desktops: ScreenShares;
33
36
  protected deviceAt: number;
34
37
  protected timer?: ReturnType<typeof setInterval>;
35
38
  protected child?: ChildProcess;
@@ -14,6 +14,7 @@ const node_child_process_1 = require("node:child_process");
14
14
  const core_1 = require("@celljs/core");
15
15
  const host_protocol_1 = require("./host-protocol");
16
16
  const relay_bridge_1 = require("./relay-bridge");
17
+ const screen_shares_1 = require("./screen-share/screen-shares");
17
18
  var KeepAwakeUtil;
18
19
  (function (KeepAwakeUtil) {
19
20
  /** How long after a device left the computer stays awake: a phone put away a while comes back to a Ta that answers. */
@@ -78,7 +79,7 @@ let KeepAwakeImpl = class KeepAwakeImpl {
78
79
  if (this.bridge.devicesOpen > 0) {
79
80
  this.deviceAt = now;
80
81
  }
81
- const running = this.sessions.list().some(session => session.pi.isStreaming);
82
+ const running = this.sessions.list().some(session => session.pi.isStreaming) || this.desktops.watched;
82
83
  const enabled = this.bridge.store.read().keepAwake !== false;
83
84
  if (KeepAwakeUtil.wanted({ enabled, running, deviceAt: this.deviceAt, now })) {
84
85
  this.hold();
@@ -125,6 +126,10 @@ __decorate([
125
126
  (0, core_1.Autowired)(host_protocol_1.TaSessionRegistry),
126
127
  __metadata("design:type", Object)
127
128
  ], KeepAwakeImpl.prototype, "sessions", void 0);
129
+ __decorate([
130
+ (0, core_1.Autowired)(screen_shares_1.ScreenShares),
131
+ __metadata("design:type", screen_shares_1.ScreenShares)
132
+ ], KeepAwakeImpl.prototype, "desktops", void 0);
128
133
  exports.KeepAwakeImpl = KeepAwakeImpl = __decorate([
129
134
  (0, core_1.Component)([host_protocol_1.KeepAwake, core_1.ApplicationLifecycle])
130
135
  ], KeepAwakeImpl);
@@ -1,7 +1,9 @@
1
1
  import { type CodingAgentOptions } from '@celljs/ai-coding-agent';
2
2
  import { type Application, ApplicationLifecycle } from '@celljs/core';
3
3
  import { type TaExtensionHost, type TaHostAnswer, type TaHostSessionEvent, TaPackageServer, type TaPackageService, TaServer } from '@celljs/ta-protocol';
4
+ import type { TaAccountService } from './account-service';
4
5
  import { TaAppCommands } from './app-commands';
6
+ import { TaCredentials } from './credentials';
5
7
  import { ExtensionDataStore } from './extension-data';
6
8
  import { TaPresenceBook, TaSessionRegistry } from './host-protocol';
7
9
  import { TaPageBook } from './page-book';
@@ -56,8 +58,10 @@ export declare class PackageHostsImpl implements PackageHosts, ApplicationLifecy
56
58
  protected readonly server: TaServer;
57
59
  protected readonly packages: TaPackageServer;
58
60
  protected readonly relay: RelayBridge;
61
+ protected readonly account: TaAccountService;
59
62
  protected readonly roomsBridge: RoomsBridge;
60
63
  protected readonly voiceBridge: VoiceBridge;
64
+ protected readonly credentials: TaCredentials;
61
65
  protected readonly settings: TaSettingsStore;
62
66
  protected readonly sessions: TaSessionRegistry;
63
67
  protected readonly presenceBook: TaPresenceBook;
@@ -20,6 +20,7 @@ const ta_brand_1 = require("@celljs/ta-harness/lib/node/ta-brand");
20
20
  const ta_packages_1 = require("@celljs/ta-harness/lib/node/ta-packages");
21
21
  const ta_protocol_1 = require("@celljs/ta-protocol");
22
22
  const app_commands_1 = require("./app-commands");
23
+ const credentials_1 = require("./credentials");
23
24
  const extension_data_1 = require("./extension-data");
24
25
  const host_protocol_1 = require("./host-protocol");
25
26
  const page_book_1 = require("./page-book");
@@ -184,6 +185,13 @@ let PackageHostsImpl = class PackageHostsImpl {
184
185
  },
185
186
  prompt: (sessionId, input) => host.prompt(sessionId, mark(input)),
186
187
  followUp: (sessionId, input) => host.followUp(sessionId, mark(input)),
188
+ // A package speaks with itself on the user's other computers, under its own name.
189
+ account: {
190
+ self: async () => this.account.self(),
191
+ computers: async () => this.account.computers(),
192
+ tell: (to, value) => this.account.tell(to, name, value),
193
+ onTold: listener => this.account.onTold(name, listener),
194
+ },
187
195
  };
188
196
  }
189
197
  host() {
@@ -203,6 +211,7 @@ let PackageHostsImpl = class PackageHostsImpl {
203
211
  rooms: this.roomsBridge.rooms,
204
212
  relays: this.relay.extensionRelays,
205
213
  voices: this.voiceBridge.extensionVoices,
214
+ credentials: this.credentials.extension,
206
215
  sessionMessages: file => this.sessionMessages(file),
207
216
  sessionRole: async (file) => session_catalog_1.SessionCatalogUtil.roleOf((await ai_coding_agent_1.PiSdkUtil.load()).SessionManager.open(file).getEntries()),
208
217
  createSession: (cwd, messages, name) => this.createSession(cwd, messages, name),
@@ -296,6 +305,10 @@ __decorate([
296
305
  (0, core_1.Autowired)({ id: relay_bridge_1.RELAY_BRIDGE, detached: true }),
297
306
  __metadata("design:type", Function)
298
307
  ], PackageHostsImpl.prototype, "relay", void 0);
308
+ __decorate([
309
+ (0, core_1.Autowired)({ id: host_protocol_1.TA_ACCOUNT, detached: true }),
310
+ __metadata("design:type", Function)
311
+ ], PackageHostsImpl.prototype, "account", void 0);
299
312
  __decorate([
300
313
  (0, core_1.Autowired)({ id: rooms_bridge_1.ROOMS_BRIDGE, detached: true }),
301
314
  __metadata("design:type", Function)
@@ -304,6 +317,10 @@ __decorate([
304
317
  (0, core_1.Autowired)({ id: voice_bridge_1.VOICE_BRIDGE, detached: true }),
305
318
  __metadata("design:type", Function)
306
319
  ], PackageHostsImpl.prototype, "voiceBridge", void 0);
320
+ __decorate([
321
+ (0, core_1.Autowired)(credentials_1.TaCredentials),
322
+ __metadata("design:type", credentials_1.TaCredentials)
323
+ ], PackageHostsImpl.prototype, "credentials", void 0);
307
324
  __decorate([
308
325
  (0, core_1.Autowired)({ id: settings_store_1.TaSettingsStore, detached: true }),
309
326
  __metadata("design:type", Object)
@@ -355,7 +355,7 @@ let TaRelayServerImpl = class TaRelayServerImpl {
355
355
  defaultRelay: relay,
356
356
  online: this.bridge.online,
357
357
  // Those of people let in are theirs, not the user's: ta-team lists them.
358
- devices: devices.filter(each => !each.member).map(each => device({ ...each, relay: node_1.RelayStore.relayOf(each, config) })),
358
+ devices: devices.filter(each => !each.member && !each.account).map(each => device({ ...each, relay: node_1.RelayStore.relayOf(each, config) })),
359
359
  ...(this.keepAwake.supported ? { keepAwake: keepAwake !== false } : {}),
360
360
  };
361
361
  }
@@ -1,6 +1,6 @@
1
1
  import { type Application, ApplicationLifecycle } from '@celljs/core';
2
2
  import { type RpcConnection } from '@celljs/rpc/lib/node';
3
- import { type TaFriend, type TaFriendRequest, type TaIdentity, type TaRoomEvent, type TaRoomInfo, type TaRoomRequest, TaRoomServer, type TaRooms, type TaRoomValue, type TaRoomWatch } from '@celljs/ta-protocol';
3
+ import { type TaFriend, type TaFriendRequest, type TaFriendShare, type TaGroupInvite, type TaIdentity, type TaRoomEvent, type TaRoomInfo, type TaRoomRequest, TaRoomServer, type TaRooms, type TaRoomValue, type TaRoomWatch } from '@celljs/ta-protocol';
4
4
  import type { RelayHubs } from '@celljs/ta-relay/lib/node';
5
5
  import { ExtensionDataStore } from './extension-data';
6
6
  import { type RelayBridge } from './relay-bridge';
@@ -70,6 +70,15 @@ export declare class TaRoomServerImpl implements TaRoomServer {
70
70
  }>;
71
71
  addFriend(link: string): Promise<void>;
72
72
  offerFriend(room: string, member: string): Promise<void>;
73
+ inviteFriends(room: string, friends: string[]): Promise<number>;
74
+ listGroupInvites(): Promise<TaGroupInvite[]>;
75
+ answerGroupInvite(room: string, accept: boolean): Promise<void>;
76
+ sendToFriends(friends: string[], item: {
77
+ link: string;
78
+ title: string;
79
+ }): Promise<number>;
80
+ listFriendShares(): Promise<TaFriendShare[]>;
81
+ answerFriendShare(id: string, keep: boolean): Promise<void>;
73
82
  listFriendRequests(): Promise<TaFriendRequest[]>;
74
83
  answerFriend(id: string, accept: boolean): Promise<void>;
75
84
  removeFriend(id: string): Promise<boolean>;
@@ -48,6 +48,12 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
48
48
  friendLink: renew => this.hubs.friendLink(renew === true),
49
49
  addFriend: link => this.hubs.addFriend(link),
50
50
  offerFriend: (room, member) => this.hubs.offerFriend(room, member),
51
+ inviteFriends: (room, friends) => this.hubs.inviteFriends(room, friends),
52
+ listGroupInvites: () => this.hubs.groupInvites(),
53
+ answerGroupInvite: (room, accept) => this.hubs.answerGroupInvite(room, accept),
54
+ sendToFriends: (friends, item) => this.hubs.sendToFriends(friends, item),
55
+ listFriendShares: () => this.hubs.friendShares(),
56
+ answerFriendShare: async (id, keep) => this.hubs.answerFriendShare(id, keep),
51
57
  listFriendRequests: async () => this.hubs.friendRequests(),
52
58
  answerFriend: (id, accept) => this.hubs.answerFriend(id, accept),
53
59
  removeFriend: id => this.hubs.removeFriend(id),
@@ -180,6 +186,25 @@ let TaRoomServerImpl = class TaRoomServerImpl {
180
186
  offerFriend(room, member) {
181
187
  return ta_errors_1.TaErrors.guard(() => this.rooms.offerFriend(room, member));
182
188
  }
189
+ inviteFriends(room, friends) {
190
+ return ta_errors_1.TaErrors.guard(() => this.rooms.inviteFriends(room, Array.isArray(friends) ? friends.map(String) : []));
191
+ }
192
+ listGroupInvites() {
193
+ return ta_errors_1.TaErrors.guard(() => this.rooms.listGroupInvites());
194
+ }
195
+ answerGroupInvite(room, accept) {
196
+ return ta_errors_1.TaErrors.guard(() => this.rooms.answerGroupInvite(room, accept === true));
197
+ }
198
+ sendToFriends(friends, item) {
199
+ const ids = Array.isArray(friends) ? friends.map(String) : [];
200
+ return ta_errors_1.TaErrors.guard(() => { var _a, _b; return this.rooms.sendToFriends(ids, { link: String((_a = item === null || item === void 0 ? void 0 : item.link) !== null && _a !== void 0 ? _a : ''), title: String((_b = item === null || item === void 0 ? void 0 : item.title) !== null && _b !== void 0 ? _b : '') }); });
201
+ }
202
+ listFriendShares() {
203
+ return ta_errors_1.TaErrors.guard(() => this.rooms.listFriendShares());
204
+ }
205
+ answerFriendShare(id, keep) {
206
+ return ta_errors_1.TaErrors.guard(() => this.rooms.answerFriendShare(String(id), keep === true));
207
+ }
183
208
  listFriendRequests() {
184
209
  return ta_errors_1.TaErrors.guard(() => this.rooms.listFriendRequests());
185
210
  }
@@ -0,0 +1,52 @@
1
+ import type { RfbFramebuffer } from './rfb-framebuffer';
2
+ import type { RfbRect } from './rfb-protocol';
3
+ /** The side of a tile of a view, in its pixels: each changed tile goes as a JPEG of its own. */
4
+ export declare const DESKTOP_TILE = 128;
5
+ /** The most a view may be on a side, whatever a page asks. */
6
+ export declare const DESKTOP_MAX_VIEW = 4096;
7
+ /** What part of the framebuffer a page looks at, in how many of its pixels. */
8
+ export interface DesktopViewSize {
9
+ rect: RfbRect;
10
+ width: number;
11
+ height: number;
12
+ }
13
+ export declare namespace DesktopPicture {
14
+ /**
15
+ * The view a page asked for, made safe: a part inside the framebuffer (all of it by default), drawn in at most as
16
+ * many pixels as it has (the page scales up itself) and at most DESKTOP_MAX_VIEW, keeping its proportions.
17
+ */
18
+ function fit(framebuffer: {
19
+ width: number;
20
+ height: number;
21
+ }, asked: {
22
+ rect?: RfbRect;
23
+ width: number;
24
+ height: number;
25
+ }): DesktopViewSize;
26
+ /** The tiles of a view (columns, rows). */
27
+ function grid(view: DesktopViewSize): {
28
+ columns: number;
29
+ rows: number;
30
+ };
31
+ /** The tiles a changed part of the framebuffer touches, as indices of the grid of the view. */
32
+ function touched(view: DesktopViewSize, changed: RfbRect): number[];
33
+ /**
34
+ * The pixels of a tile of the view, RGBA: each the average of the pixels of the framebuffer it covers (at most 4
35
+ * by 4 of them, evenly spread), so that text scaled down stays readable rather than broken up.
36
+ */
37
+ function sample(framebuffer: RfbFramebuffer, view: DesktopViewSize, tile: RfbRect): Uint8Array;
38
+ /** The rectangle of a tile of the grid, in the pixels of the view. */
39
+ function tileRect(view: DesktopViewSize, index: number): RfbRect;
40
+ /**
41
+ * The tiles as JPEGs, in base64. Encoding a whole screen takes about 90 ms of a core, so it yields to the event loop
42
+ * every SLICE_MS; `still` says whether the view is still the one asked for, and stops when it is not.
43
+ */
44
+ function encode(framebuffer: RfbFramebuffer, view: DesktopViewSize, tiles: number[], quality: number, still?: () => boolean): Promise<{
45
+ x: number;
46
+ y: number;
47
+ w: number;
48
+ h: number;
49
+ jpeg: string;
50
+ }[]>;
51
+ }
52
+ //# sourceMappingURL=desktop-picture.d.ts.map
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DesktopPicture = exports.DESKTOP_MAX_VIEW = exports.DESKTOP_TILE = void 0;
4
+ const jpeg_encoder_1 = require("../jpeg-encoder");
5
+ /** The side of a tile of a view, in its pixels: each changed tile goes as a JPEG of its own. */
6
+ exports.DESKTOP_TILE = 128;
7
+ /** The most a view may be on a side, whatever a page asks. */
8
+ exports.DESKTOP_MAX_VIEW = 4096;
9
+ /** Work done between two turns of the event loop while tiles are encoded: sessions and terminals go on meanwhile. */
10
+ const SLICE_MS = 8;
11
+ var DesktopPicture;
12
+ (function (DesktopPicture) {
13
+ /**
14
+ * The view a page asked for, made safe: a part inside the framebuffer (all of it by default), drawn in at most as
15
+ * many pixels as it has (the page scales up itself) and at most DESKTOP_MAX_VIEW, keeping its proportions.
16
+ */
17
+ function fit(framebuffer, asked) {
18
+ var _a;
19
+ const rect = clampRect((_a = asked.rect) !== null && _a !== void 0 ? _a : { x: 0, y: 0, w: framebuffer.width, h: framebuffer.height }, framebuffer);
20
+ const wanted = Math.max(1, Math.round(Number(asked.width) || rect.w));
21
+ const scale = Math.min(1, wanted / rect.w, Math.max(1, Math.round(Number(asked.height) || rect.h)) / rect.h, exports.DESKTOP_MAX_VIEW / rect.w, exports.DESKTOP_MAX_VIEW / rect.h);
22
+ return { rect, width: Math.max(1, Math.round(rect.w * scale)), height: Math.max(1, Math.round(rect.h * scale)) };
23
+ }
24
+ DesktopPicture.fit = fit;
25
+ function clampRect(rect, framebuffer) {
26
+ const x = Math.max(0, Math.min(framebuffer.width - 1, Math.floor(Number(rect.x) || 0)));
27
+ const y = Math.max(0, Math.min(framebuffer.height - 1, Math.floor(Number(rect.y) || 0)));
28
+ const w = Math.max(1, Math.min(framebuffer.width - x, Math.ceil(Number(rect.w) || framebuffer.width)));
29
+ const h = Math.max(1, Math.min(framebuffer.height - y, Math.ceil(Number(rect.h) || framebuffer.height)));
30
+ return { x, y, w, h };
31
+ }
32
+ /** The tiles of a view (columns, rows). */
33
+ function grid(view) {
34
+ return { columns: Math.ceil(view.width / exports.DESKTOP_TILE), rows: Math.ceil(view.height / exports.DESKTOP_TILE) };
35
+ }
36
+ DesktopPicture.grid = grid;
37
+ /** The tiles a changed part of the framebuffer touches, as indices of the grid of the view. */
38
+ function touched(view, changed) {
39
+ const { rect } = view;
40
+ const left = Math.max(changed.x, rect.x);
41
+ const top = Math.max(changed.y, rect.y);
42
+ const right = Math.min(changed.x + changed.w, rect.x + rect.w);
43
+ const bottom = Math.min(changed.y + changed.h, rect.y + rect.h);
44
+ if (right <= left || bottom <= top) {
45
+ return [];
46
+ }
47
+ const sx = view.width / rect.w;
48
+ const sy = view.height / rect.h;
49
+ const { columns, rows } = grid(view);
50
+ const c0 = Math.max(0, Math.floor(((left - rect.x) * sx) / exports.DESKTOP_TILE));
51
+ const c1 = Math.min(columns - 1, Math.floor(((right - rect.x) * sx - 1e-6) / exports.DESKTOP_TILE));
52
+ const r0 = Math.max(0, Math.floor(((top - rect.y) * sy) / exports.DESKTOP_TILE));
53
+ const r1 = Math.min(rows - 1, Math.floor(((bottom - rect.y) * sy - 1e-6) / exports.DESKTOP_TILE));
54
+ const out = [];
55
+ for (let row = r0; row <= r1; row++) {
56
+ for (let column = c0; column <= c1; column++) {
57
+ out.push(row * columns + column);
58
+ }
59
+ }
60
+ return out;
61
+ }
62
+ DesktopPicture.touched = touched;
63
+ /**
64
+ * The pixels of a tile of the view, RGBA: each the average of the pixels of the framebuffer it covers (at most 4
65
+ * by 4 of them, evenly spread), so that text scaled down stays readable rather than broken up.
66
+ */
67
+ function sample(framebuffer, view, tile) {
68
+ const out = new Uint8Array(tile.w * tile.h * 4);
69
+ const { rect } = view;
70
+ const sx = rect.w / view.width;
71
+ const sy = rect.h / view.height;
72
+ const source = framebuffer.rgba;
73
+ const stride = framebuffer.width;
74
+ let at = 0;
75
+ for (let y = 0; y < tile.h; y++) {
76
+ const y0 = rect.y + Math.floor((tile.y + y) * sy);
77
+ const y1 = Math.max(y0 + 1, Math.min(rect.y + rect.h, rect.y + Math.floor((tile.y + y + 1) * sy)));
78
+ const stepY = Math.max(1, Math.floor((y1 - y0) / 4));
79
+ for (let x = 0; x < tile.w; x++) {
80
+ const x0 = rect.x + Math.floor((tile.x + x) * sx);
81
+ const x1 = Math.max(x0 + 1, Math.min(rect.x + rect.w, rect.x + Math.floor((tile.x + x + 1) * sx)));
82
+ const stepX = Math.max(1, Math.floor((x1 - x0) / 4));
83
+ let r = 0;
84
+ let g = 0;
85
+ let b = 0;
86
+ let count = 0;
87
+ for (let py = y0; py < y1; py += stepY) {
88
+ let index = (py * stride + x0) * 4;
89
+ for (let px = x0; px < x1; px += stepX, index += stepX * 4) {
90
+ r += source[index];
91
+ g += source[index + 1];
92
+ b += source[index + 2];
93
+ count++;
94
+ }
95
+ }
96
+ out[at++] = r / count;
97
+ out[at++] = g / count;
98
+ out[at++] = b / count;
99
+ out[at++] = 255;
100
+ }
101
+ }
102
+ return out;
103
+ }
104
+ DesktopPicture.sample = sample;
105
+ /** The rectangle of a tile of the grid, in the pixels of the view. */
106
+ function tileRect(view, index) {
107
+ const { columns } = grid(view);
108
+ const x = (index % columns) * exports.DESKTOP_TILE;
109
+ const y = Math.floor(index / columns) * exports.DESKTOP_TILE;
110
+ return { x, y, w: Math.min(exports.DESKTOP_TILE, view.width - x), h: Math.min(exports.DESKTOP_TILE, view.height - y) };
111
+ }
112
+ DesktopPicture.tileRect = tileRect;
113
+ /**
114
+ * The tiles as JPEGs, in base64. Encoding a whole screen takes about 90 ms of a core, so it yields to the event loop
115
+ * every SLICE_MS; `still` says whether the view is still the one asked for, and stops when it is not.
116
+ */
117
+ async function encode(framebuffer, view, tiles, quality, still = () => true) {
118
+ const out = [];
119
+ let slice = performance.now();
120
+ for (const index of tiles) {
121
+ if (performance.now() - slice > SLICE_MS) {
122
+ await new Promise(resolve => setImmediate(resolve));
123
+ slice = performance.now();
124
+ if (!still()) {
125
+ break;
126
+ }
127
+ }
128
+ const rect = tileRect(view, index);
129
+ const jpeg = jpeg_encoder_1.JpegEncoder.encode(sample(framebuffer, view, rect), rect.w, rect.h, quality);
130
+ out.push({ ...rect, jpeg: Buffer.from(jpeg).toString('base64') });
131
+ }
132
+ return out;
133
+ }
134
+ DesktopPicture.encode = encode;
135
+ })(DesktopPicture || (exports.DesktopPicture = DesktopPicture = {}));
136
+ //# sourceMappingURL=desktop-picture.js.map
@@ -0,0 +1,129 @@
1
+ import type { ExecSocket } from '@celljs/ta-exec';
2
+ import type { TaDesktopCapabilities, TaDesktopControl, TaDesktopFrames, TaDesktopInput, TaDesktopLink, TaDesktopScreen, TaDesktopWatcher } from '@celljs/ta-protocol';
3
+ import type { DesktopViewer } from './desktop-viewer';
4
+ import { RfbClient } from './rfb-client';
5
+ import type { RfbCredentials, RfbCursor, RfbRect, RfbScreen } from './rfb-protocol';
6
+ import { RfbAuthError } from './rfb-security';
7
+ /** How long a desktop stays connected once no page looks at it: a page that comes back within it has a picture at once. */
8
+ export declare const DESKTOP_LINGER_MS = 30000;
9
+ /** Control given back to no one after this long without input (docs/design/ta-desktop-remote.md 6.4). */
10
+ export declare const DESKTOP_CONTROL_IDLE_MS: number;
11
+ /**
12
+ * How long a desktop may keep Ta waiting while it connects (the TCP connection, then each step of signing in), the
13
+ * time the user takes to give the password aside: a server that never answers is lost, and says so.
14
+ */
15
+ export declare const DESKTOP_CONNECT_TIMEOUT_MS = 20000;
16
+ /** How many times a desktop that refuses a sign-in is asked again while a page waits for it. */
17
+ export declare const DESKTOP_SIGN_INS = 5;
18
+ /** The desktop refused the password (and account) it was given. */
19
+ export declare class RfbRefusedError extends RfbAuthError {
20
+ }
21
+ /** What a session needs of the service that made it. */
22
+ export interface DesktopSessionHost {
23
+ /** A TCP connection to the desktop's VNC server, through the ExecEnvironment of its machine. */
24
+ connect(): Promise<ExecSocket>;
25
+ /**
26
+ * The password (and an account) to sign in with, kept or asked of whoever is there; undefined when no one
27
+ * answered. `refused`: the desktop refused the last one, and it is asked again.
28
+ */
29
+ credentials(need: {
30
+ username: boolean;
31
+ refused: boolean;
32
+ }): Promise<RfbCredentials | undefined>;
33
+ /** Whether the desktop took the sign-in it was given last: told once signing in ends. */
34
+ signedIn(taken: boolean): void;
35
+ /** The display name of a principal. */
36
+ nameOf(principal: string): string;
37
+ /** The session has no viewer and lingered: the service drops it. */
38
+ idle(): void;
39
+ }
40
+ type PngCursor = {
41
+ hotX: number;
42
+ hotY: number;
43
+ width: number;
44
+ height: number;
45
+ png: string;
46
+ } | null;
47
+ /**
48
+ * One desktop connected (docs/design/ta-desktop-remote.md 5.1, 9): one RFB connection for every page that looks at
49
+ * it, each a DesktopViewer with its own view and frames, and one of them, at most, in control.
50
+ */
51
+ export declare class DesktopSession {
52
+ readonly id: string;
53
+ readonly name: string;
54
+ protected readonly host: DesktopSessionHost;
55
+ readonly viewers: Map<string, DesktopViewer>;
56
+ link: TaDesktopLink;
57
+ error?: string;
58
+ title: string;
59
+ protected controller?: {
60
+ viewerId: string;
61
+ since: number;
62
+ };
63
+ protected client?: RfbClient;
64
+ protected connecting?: Promise<void>;
65
+ protected cursor: PngCursor;
66
+ protected screens: RfbScreen[];
67
+ protected sawScreens: boolean;
68
+ protected sawCursor: boolean;
69
+ protected lingerTimer?: ReturnType<typeof setTimeout>;
70
+ protected idleTimer?: ReturnType<typeof setInterval>;
71
+ /** Where the pointer was put last: where held buttons are let go. */
72
+ protected pointerAt: {
73
+ x: number;
74
+ y: number;
75
+ };
76
+ /** The first pixels came: before them the framebuffer is black, and no tile of it goes. */
77
+ protected painted: boolean;
78
+ connectTimeoutMs: number;
79
+ constructor(id: string, name: string, host: DesktopSessionHost);
80
+ get framebuffer(): {
81
+ width: number;
82
+ height: number;
83
+ };
84
+ /** Connected, with a whole screen to show. */
85
+ get showing(): boolean;
86
+ /** Connects once; a session that was lost connects again when a page comes. */
87
+ start(): Promise<void>;
88
+ add(viewer: DesktopViewer): void;
89
+ remove(viewerId: string): void;
90
+ close(): void;
91
+ /** Frame `want` of a viewer (docs/design/ta-desktop-remote.md 5.4). */
92
+ read(viewer: DesktopViewer, want: number): Promise<TaDesktopFrames>;
93
+ /** Who works it, as a page sees it: `self` for the page of `viewer`. */
94
+ controlFor(viewerId?: string): TaDesktopControl | null;
95
+ watchers(viewerId?: string): TaDesktopWatcher[];
96
+ get controlled(): boolean;
97
+ /** The screens as the protocol says them. */
98
+ screensOf(): TaDesktopScreen[];
99
+ capabilities(): TaDesktopCapabilities;
100
+ /** The viewer takes control: from another page of the same person, or when no one has it. */
101
+ take(viewer: DesktopViewer, may: (holder: DesktopViewer) => boolean): TaDesktopControl | null;
102
+ release(viewer: DesktopViewer): void;
103
+ /** Input of the viewer in control, taken once by its seq. */
104
+ input(viewer: DesktopViewer, batch: {
105
+ seq: number;
106
+ events: TaDesktopInput[];
107
+ }): void;
108
+ /** Text into the clipboard of the desktop, then the keys that paste on its system when asked. */
109
+ paste(viewer: DesktopViewer, text: string, press: boolean, clientMessageId: string): void;
110
+ protected mustControl(viewer: DesktopViewer): void;
111
+ protected live(): RfbClient;
112
+ /** The rectangle of a screen of the framebuffer: the one named, else the primary one. */
113
+ screenOf(id?: string): RfbRect | undefined;
114
+ protected screenRect(id?: string): RfbRect | undefined;
115
+ protected frame(viewer: DesktopViewer, made: {
116
+ seq: number;
117
+ whole: boolean;
118
+ waited: number;
119
+ }): Promise<TaDesktopFrames>;
120
+ /** Connects, asking again while the desktop refuses what it is given and a page still waits for it. */
121
+ protected signIn(): Promise<void>;
122
+ protected connect(refused?: boolean): Promise<void>;
123
+ protected lose(error: Error): void;
124
+ protected tellAll(): void;
125
+ protected checkIdle(): void;
126
+ static cursorPng(cursor: RfbCursor | null): PngCursor;
127
+ }
128
+ export {};
129
+ //# sourceMappingURL=desktop-session.d.ts.map