@vkontakte/media-streaming 1.0.1-dev.2e8c6c4.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/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@vkontakte/media-streaming",
3
+ "version": "1.0.1-dev.2e8c6c4.0",
4
+ "author": "vk.com",
5
+ "description": "VK WebRTC media streaming module",
6
+ "homepage": "https://vk.com",
7
+ "license": "GPL-3.0",
8
+ "main": "media-streaming.cjs",
9
+ "module": "media-streaming.esm.js",
10
+ "types": "types/index.d.ts",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./types/index.d.ts",
15
+ "import": "./media-streaming.esm.js",
16
+ "require": "./media-streaming.cjs"
17
+ }
18
+ },
19
+ "files": [
20
+ "media-streaming.esm.js",
21
+ "media-streaming.cjs",
22
+ "types/**/*.d.ts"
23
+ ],
24
+ "dependencies": {
25
+ "@vkontakte/videoplayer-shared": "^1.0.97"
26
+ }
27
+ }
@@ -0,0 +1,8 @@
1
+ import type { MediaConstraintsConfig } from "./types";
2
+ export declare class MediaConstraints {
3
+ protected readonly config: MediaConstraintsConfig;
4
+ audio: boolean | MediaTrackConstraints;
5
+ video: boolean | MediaTrackConstraints;
6
+ constructor(config: MediaConstraintsConfig);
7
+ getNative(): MediaStreamConstraints;
8
+ }
@@ -0,0 +1,4 @@
1
+ import type { MediaErrorType } from "./constants";
2
+ export declare class StreamerMediaError extends Error {
3
+ constructor(name: string, message: MediaErrorType);
4
+ }
@@ -0,0 +1,5 @@
1
+ import { MediaConstraints } from "./MediaConstraints";
2
+ import type { ScreenConstraintsConfig } from "./types";
3
+ export declare class ScreenConstraints extends MediaConstraints {
4
+ constructor({ width, height, frameRate }: ScreenConstraintsConfig);
5
+ }
@@ -0,0 +1,50 @@
1
+ import type { ScreenShareConfig, WebRTCStreamerConfig } from "./types";
2
+ export declare class WebRTCStreamer {
3
+ #private;
4
+ private readonly config;
5
+ private static notDestroying;
6
+ constructor(config: WebRTCStreamerConfig);
7
+ private callback;
8
+ get connected(): boolean;
9
+ init(): Promise<void>;
10
+ connect(): Promise<void>;
11
+ switchCamera(deviceId: string): Promise<void>;
12
+ switchMicrophone(deviceId: string): Promise<void>;
13
+ enableScreenShare(config: ScreenShareConfig): Promise<void>;
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>;
20
+ setMicMuted(muted: boolean): void;
21
+ setCameraEnabled(enabled: boolean): void;
22
+ destroy(): void;
23
+ private disconnect;
24
+ private replaceStream;
25
+ private replaceTracksInPeerConnection;
26
+ private get socketOpened();
27
+ private createScreenShareStream;
28
+ private openSocket;
29
+ private readonly handleWSOpen;
30
+ private readonly handleWSMessage;
31
+ private readonly handleWSClose;
32
+ private send;
33
+ private sendMessageFromQueue;
34
+ private handleStatusMessage;
35
+ private handleInviteMessage;
36
+ private handleAnswer;
37
+ private handleCandidate;
38
+ private handleScreenShareConstraintsError;
39
+ private handleError;
40
+ private createPeerConnection;
41
+ private readonly handleRTCIceCandidate;
42
+ private readonly handleRTCSignalingStateChange;
43
+ private readonly handleRTCIceConnectionStateChange;
44
+ private setDescription;
45
+ private closePeerConnection;
46
+ private closeWSConnection;
47
+ private parseMessage;
48
+ private tracerLog;
49
+ private logStat;
50
+ }
@@ -0,0 +1,31 @@
1
+ export declare const DEFAULT_STUN_SERVERS: RTCIceServer[];
2
+ export declare const DEFAULT_WS_SERVER = "wss://ovsu.mycdn.me/publish";
3
+ export declare const WS_CLOSE_CODE = 1e3;
4
+ export declare const DEFAULT_FRAME_RATE = 15;
5
+ export declare const SCREEN_SHARE_CONTENT_TEXTHINT = "text";
6
+ export declare enum PermissionName {
7
+ DISPLAY_MEDIA = "display_media",
8
+ USER_MEDIA = "user_media"
9
+ }
10
+ export declare enum MediaErrorType {
11
+ UNKNOWN = "unknown",
12
+ ACCESS = "access",
13
+ PERMISSION = "permission",
14
+ DEVICES_NOT_FOUND = "devices_not_found",
15
+ DEVICES_NOT_SUPPORTED = "devices_not_supported"
16
+ }
17
+ export declare enum StreamerError {
18
+ SOCKET = "socket",
19
+ CONNECTION = "connection",
20
+ NO_STREAM_DATA = "no_stream_data",
21
+ PEERCONNECTION = "peerconnection",
22
+ CONSTRAINTS = "constraints"
23
+ }
24
+ export declare enum StreamerEvent {
25
+ ERROR = "error",
26
+ PERMISSION = "permission",
27
+ CONNECT = "connect",
28
+ DISCONNECT = "disconnect",
29
+ CONNECTING = "connecting",
30
+ DESTROY = "destroy"
31
+ }
package/types/env.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const VERSION: string;
@@ -0,0 +1,12 @@
1
+ import type { MediaConstraintsConfig } from "./types";
2
+ export { VERSION } from "./env";
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
+ };
12
+ export { WebRTCStreamer } from "./WebRTCStreamer";
@@ -0,0 +1,71 @@
1
+ import type { ITracer } from "@vkontakte/videoplayer-shared";
2
+ import type { PermissionName, StreamerError } from "./constants";
3
+ import type { StreamerMediaError } from "./MediaError";
4
+ export type SafeAny = any;
5
+ export type RTCMessageType = "INVITE" | "STATUS" | "BYE" | "ERROR" | "EMPTY";
6
+ export type RTCMessageInviteType = "OFFER" | "CANDIDATE" | "ANSWER" | "BYE";
7
+ export interface RTCMessage {
8
+ type: RTCMessageType;
9
+ inviteType?: RTCMessageInviteType;
10
+ streamKey?: string;
11
+ sdp?: string;
12
+ status?: string;
13
+ message?: string;
14
+ text?: string;
15
+ candidate?: RTCIceCandidateInit;
16
+ promoCall?: boolean;
17
+ }
18
+ export interface WSIncomingMessage {
19
+ data: string;
20
+ }
21
+ export interface MediaDeviceConfig {
22
+ deviceId?: string;
23
+ }
24
+ export interface VideoMediaConfig extends MediaDeviceConfig {
25
+ minWidth?: number;
26
+ maxWidth?: number;
27
+ minHeight?: number;
28
+ maxHeight?: number;
29
+ aspectRatio?: number;
30
+ facingMode?: "user" | "environment";
31
+ }
32
+ export interface MediaConstraintsConfig {
33
+ audio: boolean | MediaDeviceConfig;
34
+ video: boolean | VideoMediaConfig;
35
+ }
36
+ export interface ScreenConstraintsConfig {
37
+ width: number;
38
+ height: number;
39
+ frameRate?: number;
40
+ }
41
+ export interface WebRTCStreamerCallbacks {
42
+ onConnecting?: VoidFunction;
43
+ onConnected?: VoidFunction;
44
+ onDisconnected?: (event: CloseEvent) => void;
45
+ onError?: (err: StreamerError, reason?: string) => void;
46
+ onPermissionFailed?: (permissionName: PermissionName, err?: StreamerMediaError) => void;
47
+ onStreamChanged?: (stream: MediaStream | undefined) => void;
48
+ }
49
+ export type CallbackArgs<N extends keyof WebRTCStreamerCallbacks> = Parameters<NonNullable<WebRTCStreamerCallbacks[N]>>;
50
+ export type ScreenShareConfig = ScreenConstraintsConfig & {
51
+ onEnded?: VoidFunction;
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
+ }
59
+ export interface WebRTCStreamerConfig {
60
+ streamKey: string;
61
+ callbacks: WebRTCStreamerCallbacks;
62
+ audioOnly?: boolean;
63
+ lockOrientation?: boolean;
64
+ mediaConfig?: MediaConstraintsConfig;
65
+ screenShare?: ScreenShareConfig;
66
+ serverUrl?: string;
67
+ stunServers?: RTCIceServer[];
68
+ statisticsLogger?: IStatisticsLogger;
69
+ tracer?: ITracer;
70
+ }
71
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { MediaConstraintsConfig, SafeAny } from "./types";
2
+ import type { ScreenConstraints } from "./ScreenConstraints";
3
+ import type { WebRTCStreamerConfig } from "./types";
4
+ /**
5
+ * Определяет версию Safari по userAgent.
6
+ * Возвращает major-версию как число, либо undefined если браузер не Safari
7
+ * или версию не удалось определить.
8
+ *
9
+ * @param userAgent — строка user-agent (по умолчанию navigator.userAgent)
10
+ * @returns номер major-версии Safari или undefined
11
+ */
12
+ export declare const getSafariVersion: (userAgent?: string) => number | undefined;
13
+ export declare const enumerateDevices: () => Promise<{
14
+ cameras: MediaDeviceInfo[];
15
+ microphones: MediaDeviceInfo[];
16
+ }>;
17
+ export declare const getUserStream: (config: MediaConstraintsConfig) => Promise<MediaStream>;
18
+ export declare const getDisplayMedia: (constraints: ScreenConstraints) => Promise<MediaStream>;
19
+ export declare const omitKeys: <T extends Record<string, SafeAny>>(data: T, keys: (keyof T)[]) => Record<string, SafeAny>;
20
+ export declare const serializeStream: (stream: MediaStream) => Record<string, SafeAny>;
21
+ export declare const serializeConfig: (cfg: WebRTCStreamerConfig) => Record<string, SafeAny>;
22
+ export declare const serializeMediaDevices: (devices: MediaDeviceInfo[]) => Record<string, SafeAny>[];