@celljs/ta-host 4.16.0 → 4.18.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.
- package/esm/node/app-commands.d.ts +111 -0
- package/esm/node/app-commands.js +646 -0
- package/esm/node/credentials.d.ts +12 -0
- package/esm/node/credentials.js +35 -0
- package/esm/node/delegate-extension.d.ts +11 -0
- package/esm/node/delegate-extension.js +33 -0
- package/esm/node/directory-relocator.d.ts +49 -0
- package/esm/node/directory-relocator.js +267 -0
- package/esm/node/extension-providers.d.ts +16 -1
- package/esm/node/extension-providers.js +23 -3
- package/esm/node/index.d.ts +8 -0
- package/esm/node/index.js +8 -0
- package/esm/node/keep-awake.d.ts +8 -1
- package/esm/node/keep-awake.js +24 -3
- package/esm/node/message-page.d.ts +6 -1
- package/esm/node/message-page.js +50 -2
- package/esm/node/package-hosts.d.ts +8 -0
- package/esm/node/package-hosts.js +41 -0
- package/esm/node/package-webhooks.d.ts +26 -0
- package/esm/node/package-webhooks.js +101 -0
- package/esm/node/page-book.d.ts +48 -0
- package/esm/node/page-book.js +117 -0
- package/esm/node/relay-bridge.d.ts +2 -0
- package/esm/node/relay-bridge.js +35 -1
- package/esm/node/rooms-bridge.d.ts +13 -1
- package/esm/node/rooms-bridge.js +29 -0
- package/esm/node/screen-share/desktop-picture.d.ts +51 -0
- package/esm/node/screen-share/desktop-picture.js +133 -0
- package/esm/node/screen-share/desktop-session.d.ts +128 -0
- package/esm/node/screen-share/desktop-session.js +437 -0
- package/esm/node/screen-share/desktop-targets.d.ts +24 -0
- package/esm/node/screen-share/desktop-targets.js +80 -0
- package/esm/node/screen-share/desktop-viewer.d.ts +146 -0
- package/esm/node/screen-share/desktop-viewer.js +339 -0
- package/esm/node/screen-share/index.d.ts +8 -0
- package/esm/node/screen-share/index.js +9 -0
- package/esm/node/screen-share/rfb-client.d.ts +54 -0
- package/esm/node/screen-share/rfb-client.js +179 -0
- package/esm/node/screen-share/rfb-des.d.ts +11 -0
- package/esm/node/screen-share/rfb-des.js +143 -0
- package/esm/node/screen-share/rfb-encodings.d.ts +71 -0
- package/esm/node/screen-share/rfb-encodings.js +288 -0
- package/esm/node/screen-share/rfb-framebuffer.d.ts +16 -0
- package/esm/node/screen-share/rfb-framebuffer.js +53 -0
- package/esm/node/screen-share/rfb-protocol.d.ts +90 -0
- package/esm/node/screen-share/rfb-protocol.js +36 -0
- package/esm/node/screen-share/rfb-reader.d.ts +34 -0
- package/esm/node/screen-share/rfb-reader.js +110 -0
- package/esm/node/screen-share/rfb-security.d.ts +30 -0
- package/esm/node/screen-share/rfb-security.js +136 -0
- package/esm/node/screen-share/rfb-test-server.d.ts +37 -0
- package/esm/node/screen-share/rfb-test-server.js +116 -0
- package/esm/node/screen-share/screen-share-server-impl.d.ts +37 -0
- package/esm/node/screen-share/screen-share-server-impl.js +76 -0
- package/esm/node/screen-share/screen-shares.d.ts +123 -0
- package/esm/node/screen-share/screen-shares.js +463 -0
- package/esm/node/session-info-util.d.ts +10 -9
- package/esm/node/session-info-util.js +16 -68
- package/esm/node/settings-store.d.ts +1 -1
- package/esm/node/settings-store.js +7 -4
- package/esm/node/sign-in/access-store.d.ts +1 -1
- package/esm/node/sign-in/access-store.js +4 -1
- package/esm/node/sign-in/index.d.ts +2 -0
- package/esm/node/sign-in/index.js +2 -0
- package/esm/node/sign-in/polled-sign-in.d.ts +50 -0
- package/esm/node/sign-in/polled-sign-in.js +83 -0
- package/esm/node/sign-in/sign-in-devices.d.ts +55 -0
- package/esm/node/sign-in/sign-in-devices.js +113 -0
- package/esm/node/sign-in/sign-in-flow.d.ts +38 -4
- package/esm/node/sign-in/sign-in-flow.js +79 -4
- package/esm/node/sign-in/sign-in-pages.d.ts +8 -0
- package/esm/node/sign-in/sign-in-pages.js +137 -8
- package/esm/node/sign-in/sign-in-provider.d.ts +6 -0
- package/esm/node/sign-in/sign-in-provider.js +15 -0
- package/esm/node/sources-extension.d.ts +10 -0
- package/esm/node/sources-extension.js +18 -0
- package/esm/node/ta-server-impl.d.ts +5 -1
- package/esm/node/ta-server-impl.js +25 -3
- package/esm/node/ta-session-factory.d.ts +13 -1
- package/esm/node/ta-session-factory.js +41 -4
- package/esm/node/ta-session.d.ts +2 -0
- package/esm/node/ta-session.js +1 -0
- package/esm/node/team/team-calls.js +49 -0
- package/esm/node/voice-bridge.d.ts +70 -0
- package/esm/node/voice-bridge.js +280 -0
- package/esm/node/voices-file.d.ts +38 -0
- package/esm/node/voices-file.js +100 -0
- package/esm/node/working-directory.d.ts +8 -2
- package/esm/node/working-directory.js +7 -0
- package/lib/node/app-commands.d.ts +112 -0
- package/lib/node/app-commands.js +650 -0
- package/lib/node/credentials.d.ts +13 -0
- package/lib/node/credentials.js +38 -0
- package/lib/node/delegate-extension.d.ts +12 -0
- package/lib/node/delegate-extension.js +37 -0
- package/lib/node/directory-relocator.d.ts +50 -0
- package/lib/node/directory-relocator.js +270 -0
- package/lib/node/extension-providers.d.ts +16 -1
- package/lib/node/extension-providers.js +23 -3
- package/lib/node/index.d.ts +8 -0
- package/lib/node/index.js +8 -0
- package/lib/node/keep-awake.d.ts +8 -1
- package/lib/node/keep-awake.js +24 -3
- package/lib/node/message-page.d.ts +6 -1
- package/lib/node/message-page.js +50 -2
- package/lib/node/package-hosts.d.ts +8 -0
- package/lib/node/package-hosts.js +41 -0
- package/lib/node/package-webhooks.d.ts +27 -0
- package/lib/node/package-webhooks.js +104 -0
- package/lib/node/page-book.d.ts +49 -0
- package/lib/node/page-book.js +120 -0
- package/lib/node/relay-bridge.d.ts +2 -0
- package/lib/node/relay-bridge.js +34 -0
- package/lib/node/rooms-bridge.d.ts +13 -1
- package/lib/node/rooms-bridge.js +29 -0
- package/lib/node/screen-share/desktop-picture.d.ts +52 -0
- package/lib/node/screen-share/desktop-picture.js +136 -0
- package/lib/node/screen-share/desktop-session.d.ts +129 -0
- package/lib/node/screen-share/desktop-session.js +442 -0
- package/lib/node/screen-share/desktop-targets.d.ts +25 -0
- package/lib/node/screen-share/desktop-targets.js +84 -0
- package/lib/node/screen-share/desktop-viewer.d.ts +147 -0
- package/lib/node/screen-share/desktop-viewer.js +343 -0
- package/lib/node/screen-share/index.d.ts +9 -0
- package/lib/node/screen-share/index.js +25 -0
- package/lib/node/screen-share/rfb-client.d.ts +55 -0
- package/lib/node/screen-share/rfb-client.js +183 -0
- package/lib/node/screen-share/rfb-des.d.ts +12 -0
- package/lib/node/screen-share/rfb-des.js +146 -0
- package/lib/node/screen-share/rfb-encodings.d.ts +72 -0
- package/lib/node/screen-share/rfb-encodings.js +295 -0
- package/lib/node/screen-share/rfb-framebuffer.d.ts +17 -0
- package/lib/node/screen-share/rfb-framebuffer.js +57 -0
- package/lib/node/screen-share/rfb-protocol.d.ts +91 -0
- package/lib/node/screen-share/rfb-protocol.js +39 -0
- package/lib/node/screen-share/rfb-reader.d.ts +35 -0
- package/lib/node/screen-share/rfb-reader.js +115 -0
- package/lib/node/screen-share/rfb-security.d.ts +31 -0
- package/lib/node/screen-share/rfb-security.js +141 -0
- package/lib/node/screen-share/rfb-test-server.d.ts +38 -0
- package/lib/node/screen-share/rfb-test-server.js +120 -0
- package/lib/node/screen-share/screen-share-server-impl.d.ts +38 -0
- package/lib/node/screen-share/screen-share-server-impl.js +79 -0
- package/lib/node/screen-share/screen-shares.d.ts +124 -0
- package/lib/node/screen-share/screen-shares.js +464 -0
- package/lib/node/session-info-util.d.ts +10 -9
- package/lib/node/session-info-util.js +15 -67
- package/lib/node/settings-store.d.ts +1 -1
- package/lib/node/settings-store.js +6 -3
- package/lib/node/sign-in/access-store.d.ts +1 -1
- package/lib/node/sign-in/access-store.js +4 -1
- package/lib/node/sign-in/index.d.ts +2 -0
- package/lib/node/sign-in/index.js +2 -0
- package/lib/node/sign-in/polled-sign-in.d.ts +51 -0
- package/lib/node/sign-in/polled-sign-in.js +87 -0
- package/lib/node/sign-in/sign-in-devices.d.ts +56 -0
- package/lib/node/sign-in/sign-in-devices.js +117 -0
- package/lib/node/sign-in/sign-in-flow.d.ts +38 -4
- package/lib/node/sign-in/sign-in-flow.js +80 -5
- package/lib/node/sign-in/sign-in-pages.d.ts +8 -0
- package/lib/node/sign-in/sign-in-pages.js +136 -7
- package/lib/node/sign-in/sign-in-provider.d.ts +6 -0
- package/lib/node/sign-in/sign-in-provider.js +15 -0
- package/lib/node/sources-extension.d.ts +11 -0
- package/lib/node/sources-extension.js +22 -0
- package/lib/node/ta-server-impl.d.ts +5 -1
- package/lib/node/ta-server-impl.js +24 -2
- package/lib/node/ta-session-factory.d.ts +13 -1
- package/lib/node/ta-session-factory.js +40 -3
- package/lib/node/ta-session.d.ts +2 -0
- package/lib/node/ta-session.js +1 -0
- package/lib/node/team/team-calls.js +49 -0
- package/lib/node/voice-bridge.d.ts +71 -0
- package/lib/node/voice-bridge.js +281 -0
- package/lib/node/voices-file.d.ts +39 -0
- package/lib/node/voices-file.js +104 -0
- package/lib/node/working-directory.d.ts +8 -2
- package/lib/node/working-directory.js +7 -0
- package/package.json +14 -10
package/esm/node/rooms-bridge.js
CHANGED
|
@@ -32,6 +32,7 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
|
|
|
32
32
|
listRooms: async () => this.hubs.list(),
|
|
33
33
|
createRoom: input => this.hubs.create(input),
|
|
34
34
|
invite: (room, options) => this.hubs.invite(room, options !== null && options !== void 0 ? options : {}),
|
|
35
|
+
configureRoom: async (room, options) => this.hubs.configure(room, options !== null && options !== void 0 ? options : {}),
|
|
35
36
|
join: link => this.hubs.join(link),
|
|
36
37
|
listRequests: () => this.hubs.requests(),
|
|
37
38
|
answer: (room, ask, accept) => this.hubs.answer(room, ask, accept),
|
|
@@ -44,6 +45,12 @@ let RoomsBridge = RoomsBridge_1 = class RoomsBridge {
|
|
|
44
45
|
friendLink: renew => this.hubs.friendLink(renew === true),
|
|
45
46
|
addFriend: link => this.hubs.addFriend(link),
|
|
46
47
|
offerFriend: (room, member) => this.hubs.offerFriend(room, member),
|
|
48
|
+
inviteFriends: (room, friends) => this.hubs.inviteFriends(room, friends),
|
|
49
|
+
listGroupInvites: () => this.hubs.groupInvites(),
|
|
50
|
+
answerGroupInvite: (room, accept) => this.hubs.answerGroupInvite(room, accept),
|
|
51
|
+
sendToFriends: (friends, item) => this.hubs.sendToFriends(friends, item),
|
|
52
|
+
listFriendShares: () => this.hubs.friendShares(),
|
|
53
|
+
answerFriendShare: async (id, keep) => this.hubs.answerFriendShare(id, keep),
|
|
47
54
|
listFriendRequests: async () => this.hubs.friendRequests(),
|
|
48
55
|
answerFriend: (id, accept) => this.hubs.answerFriend(id, accept),
|
|
49
56
|
removeFriend: id => this.hubs.removeFriend(id),
|
|
@@ -149,6 +156,9 @@ let TaRoomServerImpl = class TaRoomServerImpl {
|
|
|
149
156
|
removeMember(room, member) {
|
|
150
157
|
return TaErrors.guard(() => this.rooms.removeMember(room, member));
|
|
151
158
|
}
|
|
159
|
+
configureRoom(room, options) {
|
|
160
|
+
return TaErrors.guard(() => this.rooms.configureRoom(room, { members: options === null || options === void 0 ? void 0 : options.members }));
|
|
161
|
+
}
|
|
152
162
|
leave(room) {
|
|
153
163
|
return TaErrors.guard(() => this.rooms.leave(room));
|
|
154
164
|
}
|
|
@@ -173,6 +183,25 @@ let TaRoomServerImpl = class TaRoomServerImpl {
|
|
|
173
183
|
offerFriend(room, member) {
|
|
174
184
|
return TaErrors.guard(() => this.rooms.offerFriend(room, member));
|
|
175
185
|
}
|
|
186
|
+
inviteFriends(room, friends) {
|
|
187
|
+
return TaErrors.guard(() => this.rooms.inviteFriends(room, Array.isArray(friends) ? friends.map(String) : []));
|
|
188
|
+
}
|
|
189
|
+
listGroupInvites() {
|
|
190
|
+
return TaErrors.guard(() => this.rooms.listGroupInvites());
|
|
191
|
+
}
|
|
192
|
+
answerGroupInvite(room, accept) {
|
|
193
|
+
return TaErrors.guard(() => this.rooms.answerGroupInvite(room, accept === true));
|
|
194
|
+
}
|
|
195
|
+
sendToFriends(friends, item) {
|
|
196
|
+
const ids = Array.isArray(friends) ? friends.map(String) : [];
|
|
197
|
+
return 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 : '') }); });
|
|
198
|
+
}
|
|
199
|
+
listFriendShares() {
|
|
200
|
+
return TaErrors.guard(() => this.rooms.listFriendShares());
|
|
201
|
+
}
|
|
202
|
+
answerFriendShare(id, keep) {
|
|
203
|
+
return TaErrors.guard(() => this.rooms.answerFriendShare(String(id), keep === true));
|
|
204
|
+
}
|
|
176
205
|
listFriendRequests() {
|
|
177
206
|
return TaErrors.guard(() => this.rooms.listFriendRequests());
|
|
178
207
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { RfbFramebuffer } from './rfb-framebuffer.js';
|
|
2
|
+
import type { RfbRect } from './rfb-protocol.js';
|
|
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
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { JpegEncoder } from '../jpeg-encoder.js';
|
|
2
|
+
/** The side of a tile of a view, in its pixels: each changed tile goes as a JPEG of its own. */
|
|
3
|
+
export const DESKTOP_TILE = 128;
|
|
4
|
+
/** The most a view may be on a side, whatever a page asks. */
|
|
5
|
+
export const DESKTOP_MAX_VIEW = 4096;
|
|
6
|
+
/** Work done between two turns of the event loop while tiles are encoded: sessions and terminals go on meanwhile. */
|
|
7
|
+
const SLICE_MS = 8;
|
|
8
|
+
export var DesktopPicture;
|
|
9
|
+
(function (DesktopPicture) {
|
|
10
|
+
/**
|
|
11
|
+
* The view a page asked for, made safe: a part inside the framebuffer (all of it by default), drawn in at most as
|
|
12
|
+
* many pixels as it has (the page scales up itself) and at most DESKTOP_MAX_VIEW, keeping its proportions.
|
|
13
|
+
*/
|
|
14
|
+
function fit(framebuffer, asked) {
|
|
15
|
+
var _a;
|
|
16
|
+
const rect = clampRect((_a = asked.rect) !== null && _a !== void 0 ? _a : { x: 0, y: 0, w: framebuffer.width, h: framebuffer.height }, framebuffer);
|
|
17
|
+
const wanted = Math.max(1, Math.round(Number(asked.width) || rect.w));
|
|
18
|
+
const scale = Math.min(1, wanted / rect.w, Math.max(1, Math.round(Number(asked.height) || rect.h)) / rect.h, DESKTOP_MAX_VIEW / rect.w, DESKTOP_MAX_VIEW / rect.h);
|
|
19
|
+
return { rect, width: Math.max(1, Math.round(rect.w * scale)), height: Math.max(1, Math.round(rect.h * scale)) };
|
|
20
|
+
}
|
|
21
|
+
DesktopPicture.fit = fit;
|
|
22
|
+
function clampRect(rect, framebuffer) {
|
|
23
|
+
const x = Math.max(0, Math.min(framebuffer.width - 1, Math.floor(Number(rect.x) || 0)));
|
|
24
|
+
const y = Math.max(0, Math.min(framebuffer.height - 1, Math.floor(Number(rect.y) || 0)));
|
|
25
|
+
const w = Math.max(1, Math.min(framebuffer.width - x, Math.ceil(Number(rect.w) || framebuffer.width)));
|
|
26
|
+
const h = Math.max(1, Math.min(framebuffer.height - y, Math.ceil(Number(rect.h) || framebuffer.height)));
|
|
27
|
+
return { x, y, w, h };
|
|
28
|
+
}
|
|
29
|
+
/** The tiles of a view (columns, rows). */
|
|
30
|
+
function grid(view) {
|
|
31
|
+
return { columns: Math.ceil(view.width / DESKTOP_TILE), rows: Math.ceil(view.height / DESKTOP_TILE) };
|
|
32
|
+
}
|
|
33
|
+
DesktopPicture.grid = grid;
|
|
34
|
+
/** The tiles a changed part of the framebuffer touches, as indices of the grid of the view. */
|
|
35
|
+
function touched(view, changed) {
|
|
36
|
+
const { rect } = view;
|
|
37
|
+
const left = Math.max(changed.x, rect.x);
|
|
38
|
+
const top = Math.max(changed.y, rect.y);
|
|
39
|
+
const right = Math.min(changed.x + changed.w, rect.x + rect.w);
|
|
40
|
+
const bottom = Math.min(changed.y + changed.h, rect.y + rect.h);
|
|
41
|
+
if (right <= left || bottom <= top) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
const sx = view.width / rect.w;
|
|
45
|
+
const sy = view.height / rect.h;
|
|
46
|
+
const { columns, rows } = grid(view);
|
|
47
|
+
const c0 = Math.max(0, Math.floor(((left - rect.x) * sx) / DESKTOP_TILE));
|
|
48
|
+
const c1 = Math.min(columns - 1, Math.floor(((right - rect.x) * sx - 1e-6) / DESKTOP_TILE));
|
|
49
|
+
const r0 = Math.max(0, Math.floor(((top - rect.y) * sy) / DESKTOP_TILE));
|
|
50
|
+
const r1 = Math.min(rows - 1, Math.floor(((bottom - rect.y) * sy - 1e-6) / DESKTOP_TILE));
|
|
51
|
+
const out = [];
|
|
52
|
+
for (let row = r0; row <= r1; row++) {
|
|
53
|
+
for (let column = c0; column <= c1; column++) {
|
|
54
|
+
out.push(row * columns + column);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
DesktopPicture.touched = touched;
|
|
60
|
+
/**
|
|
61
|
+
* The pixels of a tile of the view, RGBA: each the average of the pixels of the framebuffer it covers (at most 4
|
|
62
|
+
* by 4 of them, evenly spread), so that text scaled down stays readable rather than broken up.
|
|
63
|
+
*/
|
|
64
|
+
function sample(framebuffer, view, tile) {
|
|
65
|
+
const out = new Uint8Array(tile.w * tile.h * 4);
|
|
66
|
+
const { rect } = view;
|
|
67
|
+
const sx = rect.w / view.width;
|
|
68
|
+
const sy = rect.h / view.height;
|
|
69
|
+
const source = framebuffer.rgba;
|
|
70
|
+
const stride = framebuffer.width;
|
|
71
|
+
let at = 0;
|
|
72
|
+
for (let y = 0; y < tile.h; y++) {
|
|
73
|
+
const y0 = rect.y + Math.floor((tile.y + y) * sy);
|
|
74
|
+
const y1 = Math.max(y0 + 1, Math.min(rect.y + rect.h, rect.y + Math.floor((tile.y + y + 1) * sy)));
|
|
75
|
+
const stepY = Math.max(1, Math.floor((y1 - y0) / 4));
|
|
76
|
+
for (let x = 0; x < tile.w; x++) {
|
|
77
|
+
const x0 = rect.x + Math.floor((tile.x + x) * sx);
|
|
78
|
+
const x1 = Math.max(x0 + 1, Math.min(rect.x + rect.w, rect.x + Math.floor((tile.x + x + 1) * sx)));
|
|
79
|
+
const stepX = Math.max(1, Math.floor((x1 - x0) / 4));
|
|
80
|
+
let r = 0;
|
|
81
|
+
let g = 0;
|
|
82
|
+
let b = 0;
|
|
83
|
+
let count = 0;
|
|
84
|
+
for (let py = y0; py < y1; py += stepY) {
|
|
85
|
+
let index = (py * stride + x0) * 4;
|
|
86
|
+
for (let px = x0; px < x1; px += stepX, index += stepX * 4) {
|
|
87
|
+
r += source[index];
|
|
88
|
+
g += source[index + 1];
|
|
89
|
+
b += source[index + 2];
|
|
90
|
+
count++;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
out[at++] = r / count;
|
|
94
|
+
out[at++] = g / count;
|
|
95
|
+
out[at++] = b / count;
|
|
96
|
+
out[at++] = 255;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
DesktopPicture.sample = sample;
|
|
102
|
+
/** The rectangle of a tile of the grid, in the pixels of the view. */
|
|
103
|
+
function tileRect(view, index) {
|
|
104
|
+
const { columns } = grid(view);
|
|
105
|
+
const x = (index % columns) * DESKTOP_TILE;
|
|
106
|
+
const y = Math.floor(index / columns) * DESKTOP_TILE;
|
|
107
|
+
return { x, y, w: Math.min(DESKTOP_TILE, view.width - x), h: Math.min(DESKTOP_TILE, view.height - y) };
|
|
108
|
+
}
|
|
109
|
+
DesktopPicture.tileRect = tileRect;
|
|
110
|
+
/**
|
|
111
|
+
* The tiles as JPEGs, in base64. Encoding a whole screen takes about 90 ms of a core, so it yields to the event loop
|
|
112
|
+
* every SLICE_MS; `still` says whether the view is still the one asked for, and stops when it is not.
|
|
113
|
+
*/
|
|
114
|
+
async function encode(framebuffer, view, tiles, quality, still = () => true) {
|
|
115
|
+
const out = [];
|
|
116
|
+
let slice = performance.now();
|
|
117
|
+
for (const index of tiles) {
|
|
118
|
+
if (performance.now() - slice > SLICE_MS) {
|
|
119
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
120
|
+
slice = performance.now();
|
|
121
|
+
if (!still()) {
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const rect = tileRect(view, index);
|
|
126
|
+
const jpeg = JpegEncoder.encode(sample(framebuffer, view, rect), rect.w, rect.h, quality);
|
|
127
|
+
out.push({ ...rect, jpeg: Buffer.from(jpeg).toString('base64') });
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
DesktopPicture.encode = encode;
|
|
132
|
+
})(DesktopPicture || (DesktopPicture = {}));
|
|
133
|
+
//# sourceMappingURL=desktop-picture.js.map
|
|
@@ -0,0 +1,128 @@
|
|
|
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.js';
|
|
4
|
+
import { RfbClient } from './rfb-client.js';
|
|
5
|
+
import type { RfbCredentials, RfbCursor, RfbRect, RfbScreen } from './rfb-protocol.js';
|
|
6
|
+
import { RfbAuthError } from './rfb-security.js';
|
|
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 {};
|