@pexip/media 17.2.0 → 17.4.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.
@@ -0,0 +1,29 @@
1
+ export var LogLevels;
2
+ (function (LogLevels) {
3
+ LogLevels[LogLevels["trace"] = 10] = "trace";
4
+ LogLevels[LogLevels["debug"] = 20] = "debug";
5
+ LogLevels[LogLevels["info"] = 30] = "info";
6
+ LogLevels[LogLevels["warn"] = 40] = "warn";
7
+ LogLevels[LogLevels["error"] = 50] = "error";
8
+ LogLevels[LogLevels["fatal"] = 60] = "fatal";
9
+ // eslint-disable-next-line @typescript-eslint/prefer-literal-enum-member -- needs infinity
10
+ LogLevels[LogLevels["silent"] = Number.MAX_SAFE_INTEGER] = "silent";
11
+ })(LogLevels || (LogLevels = {}));
12
+ /**
13
+ * Create a logger with console API, and map fatal to error, skipping trace
14
+ * and silent, and there is no redaction
15
+ */
16
+ export function createConsoleLogger() {
17
+ return Object.freeze({
18
+ /* eslint-disable no-console -- set logger to console */
19
+ fatal: (meta, message) => console.error(message, meta),
20
+ error: (meta, message) => console.error(message, meta),
21
+ warn: (meta, message) => console.warn(message, meta),
22
+ info: (meta, message) => console.info(message, meta),
23
+ debug: (meta, message) => console.debug(message, meta),
24
+ trace() { }, // Noop
25
+ silent() { }, // Noop
26
+ redact() { }, // Noop
27
+ /* eslint-enable no-console -- set logger to console */
28
+ });
29
+ }
@@ -0,0 +1,3 @@
1
+ import type { DisplayMediaOptions } from '@pexip/media-control';
2
+ export declare const createGetDisplayMedia: (getDefaultConstraints: () => DisplayMediaOptions, getDisplayMedia?: MediaDevices['getDisplayMedia']) => (constraints?: DisplayMediaOptions) => Promise<MediaStream | undefined>;
3
+ export type GetDisplayMedia = ReturnType<typeof createGetDisplayMedia>;
@@ -0,0 +1,31 @@
1
+ import { limitSharingMonitorInterface, stopMediaStream, } from '@pexip/media-control';
2
+ import { cancellablePromise } from '@pexip/utils';
3
+ export const createGetDisplayMedia = (getDefaultConstraints, getDisplayMedia = constraints => navigator.mediaDevices.getDisplayMedia(constraints)) => {
4
+ const props = {
5
+ requesting: false,
6
+ };
7
+ return async (constraints) => {
8
+ const [getCancelableDisplayMedia, cancel] = cancellablePromise(getDisplayMedia, stream => {
9
+ stopMediaStream(stream);
10
+ });
11
+ if (props.requesting) {
12
+ // Cancel the previous request which has not been finished
13
+ cancel();
14
+ }
15
+ try {
16
+ props.requesting = true;
17
+ const mergedConstraints = {
18
+ ...getDefaultConstraints(),
19
+ ...constraints,
20
+ };
21
+ const stream = await getCancelableDisplayMedia(mergedConstraints);
22
+ if (!stream) {
23
+ return;
24
+ }
25
+ return limitSharingMonitorInterface(mergedConstraints, stream);
26
+ }
27
+ finally {
28
+ props.requesting = false;
29
+ }
30
+ };
31
+ };