[MM-55152] Add new Desktop API endpoints, improve preload script, some clean-up (#2900)
* Add constants for app info, add to API * Migrate history button * Converted calls API over to context bridge, removed some unnecessary logging * Convert to TS, add types for web app to consume * Fix tests, prune * Fix lint * More changes to support the legacy API * Force legacy code off, add support for unreads/mentions/expired through the API * Fix issues with cross-tab login, removed need for log in/log out signalling * Fixed test, typos * Change package name for types * Add some other stuff to the types * PR feedback * More feedback * Use npm package * Change types and API to provide off listeners * Version number * Lock * Fix typo * Add sessionID for calls
This commit is contained in:
67
api-types/index.ts
Normal file
67
api-types/index.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
export type DesktopSourcesOptions = {
|
||||
types: Array<'screen' | 'window'>;
|
||||
thumbnailSize?: {height: number; width: number};
|
||||
fetchWindowIcons?: boolean;
|
||||
};
|
||||
export type DesktopCaptureSource = {
|
||||
id: string;
|
||||
name: string;
|
||||
thumbnailURL: string;
|
||||
};
|
||||
|
||||
export type DesktopAPI = {
|
||||
|
||||
// Initialization
|
||||
isDev: () => Promise<boolean>;
|
||||
getAppInfo: () => Promise<{name: string; version: string}>;
|
||||
reactAppInitialized: () => void;
|
||||
|
||||
// Session
|
||||
setSessionExpired: (isExpired: boolean) => void;
|
||||
onUserActivityUpdate: (listener: (
|
||||
userIsActive: boolean,
|
||||
idleTime: number,
|
||||
isSystemEvent: boolean,
|
||||
) => void) => () => void;
|
||||
|
||||
// Unreads/mentions/notifications
|
||||
sendNotification: (title: string, body: string, channelId: string, teamId: string, url: string, silent: boolean, soundName: string) => void;
|
||||
onNotificationClicked: (listener: (channelId: string, teamId: string, url: string) => void) => () => void;
|
||||
setUnreadsAndMentions: (isUnread: boolean, mentionCount: number) => void;
|
||||
|
||||
// Navigation
|
||||
requestBrowserHistoryStatus: () => Promise<{canGoBack: boolean; canGoForward: boolean}>;
|
||||
onBrowserHistoryStatusUpdated: (listener: (canGoBack: boolean, canGoForward: boolean) => void) => () => void;
|
||||
onBrowserHistoryPush: (listener: (pathName: string) => void) => () => void;
|
||||
sendBrowserHistoryPush: (path: string) => void;
|
||||
|
||||
// Calls widget
|
||||
openLinkFromCallsWidget: (url: string) => void;
|
||||
openScreenShareModal: () => void;
|
||||
onScreenShared: (listener: (sourceID: string, withAudio: boolean) => void) => () => void;
|
||||
callsWidgetConnected: (callID: string, sessionID: string) => void;
|
||||
onJoinCallRequest: (listener: (callID: string) => void) => () => void;
|
||||
resizeCallsWidget: (width: number, height: number) => void;
|
||||
focusPopout: () => void;
|
||||
leaveCall: () => void;
|
||||
sendCallsError: (err: string, callID?: string, errMsg?: string) => void;
|
||||
|
||||
// Calls plugin
|
||||
getDesktopSources: (opts: DesktopSourcesOptions) => Promise<DesktopCaptureSource[]>;
|
||||
onOpenScreenShareModal: (listener: () => void) => () => void;
|
||||
shareScreen: (sourceID: string, withAudi: boolean) => void;
|
||||
joinCall: (opts: {
|
||||
callID: string;
|
||||
title: string;
|
||||
rootID: string;
|
||||
channelURL: string;
|
||||
}) => Promise<{callID: string; sessionID: string}>;
|
||||
sendJoinCallRequest: (callId: string) => void;
|
||||
onCallsError: (listener: (err: string, callID?: string, errMsg?: string) => void) => () => void;
|
||||
|
||||
// Utility
|
||||
unregister: (channel: string) => void;
|
||||
}
|
57
api-types/lib/index.d.ts
vendored
Normal file
57
api-types/lib/index.d.ts
vendored
Normal file
@@ -0,0 +1,57 @@
|
||||
export declare type DesktopSourcesOptions = {
|
||||
types: Array<'screen' | 'window'>;
|
||||
thumbnailSize?: {
|
||||
height: number;
|
||||
width: number;
|
||||
};
|
||||
fetchWindowIcons?: boolean;
|
||||
};
|
||||
export declare type DesktopCaptureSource = {
|
||||
id: string;
|
||||
name: string;
|
||||
thumbnailURL: string;
|
||||
};
|
||||
export declare type DesktopAPI = {
|
||||
isDev: () => Promise<boolean>;
|
||||
getAppInfo: () => Promise<{
|
||||
name: string;
|
||||
version: string;
|
||||
}>;
|
||||
reactAppInitialized: () => void;
|
||||
setSessionExpired: (isExpired: boolean) => void;
|
||||
onUserActivityUpdate: (listener: (userIsActive: boolean, idleTime: number, isSystemEvent: boolean) => void) => () => void;
|
||||
sendNotification: (title: string, body: string, channelId: string, teamId: string, url: string, silent: boolean, soundName: string) => void;
|
||||
onNotificationClicked: (listener: (channelId: string, teamId: string, url: string) => void) => () => void;
|
||||
setUnreadsAndMentions: (isUnread: boolean, mentionCount: number) => void;
|
||||
requestBrowserHistoryStatus: () => Promise<{
|
||||
canGoBack: boolean;
|
||||
canGoForward: boolean;
|
||||
}>;
|
||||
onBrowserHistoryStatusUpdated: (listener: (canGoBack: boolean, canGoForward: boolean) => void) => () => void;
|
||||
onBrowserHistoryPush: (listener: (pathName: string) => void) => () => void;
|
||||
sendBrowserHistoryPush: (path: string) => void;
|
||||
openLinkFromCallsWidget: (url: string) => void;
|
||||
openScreenShareModal: () => void;
|
||||
onScreenShared: (listener: (sourceID: string, withAudio: boolean) => void) => () => void;
|
||||
callsWidgetConnected: (callID: string, sessionID: string) => void;
|
||||
onJoinCallRequest: (listener: (callID: string) => void) => () => void;
|
||||
resizeCallsWidget: (width: number, height: number) => void;
|
||||
focusPopout: () => void;
|
||||
leaveCall: () => void;
|
||||
sendCallsError: (err: string, callID?: string, errMsg?: string) => void;
|
||||
getDesktopSources: (opts: DesktopSourcesOptions) => Promise<DesktopCaptureSource[]>;
|
||||
onOpenScreenShareModal: (listener: () => void) => () => void;
|
||||
shareScreen: (sourceID: string, withAudi: boolean) => void;
|
||||
joinCall: (opts: {
|
||||
callID: string;
|
||||
title: string;
|
||||
rootID: string;
|
||||
channelURL: string;
|
||||
}) => Promise<{
|
||||
callID: string;
|
||||
sessionID: string;
|
||||
}>;
|
||||
sendJoinCallRequest: (callId: string) => void;
|
||||
onCallsError: (listener: (err: string, callID?: string, errMsg?: string) => void) => () => void;
|
||||
unregister: (channel: string) => void;
|
||||
};
|
4
api-types/lib/index.js
Normal file
4
api-types/lib/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
"use strict";
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
21
api-types/package-lock.json
generated
Normal file
21
api-types/package-lock.json
generated
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "@mattermost/desktop-api",
|
||||
"version": "5.7.0-2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@mattermost/desktop-api",
|
||||
"version": "5.7.0-2",
|
||||
"license": "MIT",
|
||||
"peerDependencies": {
|
||||
"typescript": "^4.3"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
api-types/package.json
Normal file
33
api-types/package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "@mattermost/desktop-api",
|
||||
"version": "5.7.0-2",
|
||||
"description": "Shared types for the Desktop App API provided to the Web App",
|
||||
"keywords": [
|
||||
"mattermost"
|
||||
],
|
||||
"homepage": "https://github.com/mattermost/desktop",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "github:mattermost/desktop",
|
||||
"directory": "api-types"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^4.3"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"typescript": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc --build --verbose",
|
||||
"run": "tsc --watch --preserveWatchOutput",
|
||||
"clean": "rm -rf tsconfig.tsbuildinfo ./lib"
|
||||
}
|
||||
}
|
20
api-types/tsconfig.json
Normal file
20
api-types/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"moduleResolution": "node",
|
||||
"target": "es6",
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"jsx": "react",
|
||||
"outDir": "./lib",
|
||||
"rootDir": ".",
|
||||
"composite": true
|
||||
},
|
||||
"include": [
|
||||
"./index.ts"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user