@vkontakte/media-streaming 1.0.1-dev.e965d10.0 → 1.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vkontakte/media-streaming",
3
- "version": "1.0.1-dev.e965d10.0",
3
+ "version": "1.0.1",
4
4
  "author": "vk.com",
5
5
  "description": "VK WebRTC media streaming module",
6
6
  "homepage": "https://vk.com",
@@ -1,5 +1,5 @@
1
- import type { IMediaConstraints, MediaConstraintsConfig } from "./types";
2
- export declare class MediaConstraints implements IMediaConstraints {
1
+ import type { MediaConstraintsConfig } from "./types";
2
+ export declare class MediaConstraints {
3
3
  protected readonly config: MediaConstraintsConfig;
4
4
  audio: boolean | MediaTrackConstraints;
5
5
  video: boolean | MediaTrackConstraints;
@@ -1,4 +1,4 @@
1
1
  import type { MediaErrorType } from "./constants";
2
- export declare class MediaError extends Error {
2
+ export declare class StreamerMediaError extends Error {
3
3
  constructor(name: string, message: MediaErrorType);
4
4
  }
@@ -1,25 +1,22 @@
1
1
  import type { ScreenShareConfig, WebRTCStreamerConfig } from "./types";
2
2
  export declare class WebRTCStreamer {
3
+ #private;
3
4
  private readonly config;
4
- private messagesQueue;
5
- private ws;
6
- private peerConnection;
7
- private stream;
8
- private screenShareTrack;
9
- private connected;
10
- private destroying;
11
- private cameraId;
12
- private microphoneId;
13
- private muted;
14
5
  private static notDestroying;
15
6
  constructor(config: WebRTCStreamerConfig);
16
7
  private callback;
8
+ get connected(): boolean;
17
9
  init(): Promise<void>;
18
10
  connect(): Promise<void>;
19
11
  switchCamera(deviceId: string): Promise<void>;
20
12
  switchMicrophone(deviceId: string): Promise<void>;
21
13
  enableScreenShare(config: ScreenShareConfig): Promise<void>;
22
14
  disableScreenShare(cameraDeviceId?: string): Promise<void>;
15
+ switchMediaDevices({ cameraId, microphoneId, screenShare }: {
16
+ cameraId?: string | false;
17
+ microphoneId?: string | false;
18
+ screenShare?: ScreenShareConfig | false;
19
+ }): Promise<void>;
23
20
  setMicMuted(muted: boolean): void;
24
21
  setCameraEnabled(enabled: boolean): void;
25
22
  destroy(): void;
@@ -38,6 +35,7 @@ export declare class WebRTCStreamer {
38
35
  private handleInviteMessage;
39
36
  private handleAnswer;
40
37
  private handleCandidate;
38
+ private handleScreenShareConstraintsError;
41
39
  private handleError;
42
40
  private createPeerConnection;
43
41
  private readonly handleRTCIceCandidate;
@@ -48,4 +46,5 @@ export declare class WebRTCStreamer {
48
46
  private closeWSConnection;
49
47
  private parseMessage;
50
48
  private tracerLog;
49
+ private logStat;
51
50
  }
package/types/index.d.ts CHANGED
@@ -1,4 +1,12 @@
1
+ import type { MediaConstraintsConfig } from "./types";
1
2
  export { VERSION } from "./env";
2
- export type { IMediaConstraints, ScreenShareConfig, WebRTCStreamerConfig, WebRTCStreamerCallbacks } from "./types";
3
- export { MediaErrorType, StreamerError } from "./constants";
3
+ export type { MediaConstraintsConfig, ScreenShareConfig, StatisticsData, IStatisticsLogger, WebRTCStreamerConfig, WebRTCStreamerCallbacks } from "./types";
4
+ export { MediaErrorType, StreamerError, PermissionName } from "./constants";
5
+ export declare const MediaUtils: {
6
+ enumerateDevices: () => Promise<{
7
+ cameras: MediaDeviceInfo[];
8
+ microphones: MediaDeviceInfo[];
9
+ }>;
10
+ getUserStream: (config: MediaConstraintsConfig) => Promise<MediaStream>;
11
+ };
4
12
  export { WebRTCStreamer } from "./WebRTCStreamer";
package/types/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ITracer } from "@vkontakte/videoplayer-shared";
2
2
  import type { PermissionName, StreamerError } from "./constants";
3
+ import type { StreamerMediaError } from "./MediaError";
3
4
  export type SafeAny = any;
4
5
  export type RTCMessageType = "INVITE" | "STATUS" | "BYE" | "ERROR" | "EMPTY";
5
6
  export type RTCMessageInviteType = "OFFER" | "CANDIDATE" | "ANSWER" | "BYE";
@@ -37,30 +38,34 @@ export interface ScreenConstraintsConfig {
37
38
  height: number;
38
39
  frameRate?: number;
39
40
  }
40
- export interface IMediaConstraints {
41
- audio: boolean | MediaTrackConstraints;
42
- video: boolean | MediaTrackConstraints;
43
- getNative(): MediaStreamConstraints;
44
- }
45
41
  export interface WebRTCStreamerCallbacks {
42
+ onConnecting?: VoidFunction;
46
43
  onConnected?: VoidFunction;
47
- onDisconnected?: (event: CloseEvent) => void;
44
+ onDisconnected?: (err?: StreamerError) => void;
48
45
  onError?: (err: StreamerError, reason?: string) => void;
49
- onPermissionFailed?: (permissionName: PermissionName, err?: MediaError) => void;
46
+ onPermissionFailed?: (permissionName: PermissionName, err?: StreamerMediaError) => void;
50
47
  onStreamChanged?: (stream: MediaStream | undefined) => void;
51
48
  }
52
49
  export type CallbackArgs<N extends keyof WebRTCStreamerCallbacks> = Parameters<NonNullable<WebRTCStreamerCallbacks[N]>>;
53
50
  export type ScreenShareConfig = ScreenConstraintsConfig & {
54
51
  onEnded?: VoidFunction;
55
52
  };
53
+ type StatDataValue = number | string;
54
+ type StatDataArrValue = StatDataValue[];
55
+ export type StatisticsData = StatDataValue | StatDataArrValue | Record<string, StatDataValue | StatDataArrValue>;
56
+ export interface IStatisticsLogger {
57
+ log: (event: string, data: StatisticsData) => void;
58
+ }
56
59
  export interface WebRTCStreamerConfig {
57
60
  streamKey: string;
58
61
  callbacks: WebRTCStreamerCallbacks;
59
62
  audioOnly?: boolean;
60
63
  lockOrientation?: boolean;
61
- mediaConstraints?: IMediaConstraints;
64
+ mediaConfig?: MediaConstraintsConfig;
62
65
  screenShare?: ScreenShareConfig;
63
66
  serverUrl?: string;
64
67
  stunServers?: RTCIceServer[];
68
+ statisticsLogger?: IStatisticsLogger;
65
69
  tracer?: ITracer;
66
70
  }
71
+ export {};
package/types/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { SafeAny } from "./types";
1
+ import type { MediaConstraintsConfig, SafeAny } from "./types";
2
2
  import type { ScreenConstraints } from "./ScreenConstraints";
3
3
  import type { WebRTCStreamerConfig } from "./types";
4
4
  /**
@@ -10,8 +10,11 @@ import type { WebRTCStreamerConfig } from "./types";
10
10
  * @returns номер major-версии Safari или undefined
11
11
  */
12
12
  export declare const getSafariVersion: (userAgent?: string) => number | undefined;
13
- export declare const enumerateDevices: () => Promise<MediaDeviceInfo[]>;
14
- export declare const getUserMedia: (constraints: MediaStreamConstraints) => Promise<MediaStream>;
13
+ export declare const enumerateDevices: () => Promise<{
14
+ cameras: MediaDeviceInfo[];
15
+ microphones: MediaDeviceInfo[];
16
+ }>;
17
+ export declare const getUserStream: (config: MediaConstraintsConfig) => Promise<MediaStream>;
15
18
  export declare const getDisplayMedia: (constraints: ScreenConstraints) => Promise<MediaStream>;
16
19
  export declare const omitKeys: <T extends Record<string, SafeAny>>(data: T, keys: (keyof T)[]) => Record<string, SafeAny>;
17
20
  export declare const serializeStream: (stream: MediaStream) => Record<string, SafeAny>;