@campoint/vxwebrtc 0.0.2 → 0.0.5

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/.gitlab-ci.yml CHANGED
@@ -1,9 +1,14 @@
1
- image: node:12
1
+ image: node:12-alpine
2
2
 
3
- cache:
4
- key: ${CI_COMMIT_REF_SLUG}
5
- paths:
6
- - node_modules/
3
+ cache: &global_cache
4
+ key:
5
+ files: [ yarn.lock ]
6
+ prefix: node:12-alpine
7
+ paths: [ .yarn/cache ]
8
+ policy: pull
9
+
10
+ before_script:
11
+ - yarn install --ignore-scripts --immutable --immutable-cache --cache-folder .yarn/cache
7
12
 
8
13
  stages:
9
14
  - install
@@ -13,15 +18,18 @@ stages:
13
18
 
14
19
  install:
15
20
  stage: install
21
+ cache:
22
+ - <<: *global_cache
23
+ policy: pull-push
16
24
  script:
17
- - npm ci
25
+ - yarn install --ignore-scripts --immutable --cache-folder .yarn/cache
18
26
 
19
27
  lint:
20
28
  stage: lint
21
29
  needs:
22
30
  - job: install
23
31
  optional: true
24
- script: npm run lint
32
+ script: yarn run lint
25
33
 
26
34
  build:
27
35
  stage: build
@@ -29,7 +37,7 @@ build:
29
37
  paths:
30
38
  - dist
31
39
  script:
32
- - npm run build
40
+ - yarn run build
33
41
 
34
42
  deploy:
35
43
  stage: deploy
@@ -39,4 +47,5 @@ deploy:
39
47
  - tags
40
48
  script:
41
49
  - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
42
- - npm publish --access public
50
+ - npm publish --access public
51
+
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ yarn run style
@@ -0,0 +1 @@
1
+ /src/MungeSdp.ts
package/README.md CHANGED
@@ -1 +1,5 @@
1
- # VXWebRTC
1
+ # VXWebRTC
2
+
3
+ == Install
4
+
5
+ ``yarn install``
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@campoint/vxwebrtc",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "main": "./dist/vxwebrtc.js",
5
5
  "types": "./dist/vxwebrtc.d.ts",
6
6
  "repository": {
@@ -10,6 +10,7 @@
10
10
  "author": "evgeniy@aporia.su",
11
11
  "license": "UNLICENSED",
12
12
  "dependencies": {
13
+ "husky": "^7.0.4",
13
14
  "lodash": "^4.17.21",
14
15
  "webrtc-adapter": "^8.1.1"
15
16
  },
@@ -23,7 +24,8 @@
23
24
  "build:dev": "webpack --config webpack.dev.js",
24
25
  "watch": "webpack --config webpack.dev.js --watch",
25
26
  "lint": "eslint src/ --ext .js,.jsx,.ts,.tsx,.json",
26
- "style": "prettier --write \"{src,test}/**/*.ts\""
27
+ "style": "prettier --write \"{src,test}/**/*.ts\"",
28
+ "postinstall": "husky install"
27
29
  },
28
30
  "prettier": {
29
31
  "singleQuote": true,
@@ -0,0 +1,4 @@
1
+ export enum EnumMediaStreamTrackKind {
2
+ VIDEO = 'video',
3
+ AUDIO = 'audio',
4
+ }
@@ -101,6 +101,37 @@ export class WebRtcOutputConnection extends WebRtcPeerConnection {
101
101
  }
102
102
  }
103
103
 
104
+ public changeTrack(newTrack: MediaStreamTrack): Promise<void> {
105
+ if (!this.wsConnection) {
106
+ throw new Error('No connection open');
107
+ }
108
+
109
+ switch (newTrack.kind) {
110
+ case EnumMediaStreamTrackKind.VIDEO: {
111
+ if (!this.videoSender) {
112
+ throw new Error('No video sender available');
113
+ }
114
+
115
+ return this.videoSender.replaceTrack(newTrack);
116
+ }
117
+
118
+ case EnumMediaStreamTrackKind.AUDIO: {
119
+ if (!this.videoSender) {
120
+ throw new Error('No audio sender available');
121
+ }
122
+
123
+ return this.audioSender.replaceTrack(newTrack);
124
+ }
125
+
126
+ default: {
127
+ const supported = [EnumMediaStreamTrackKind.VIDEO, EnumMediaStreamTrackKind.AUDIO];
128
+ throw new Error(
129
+ `Unknown media track kind ${newTrack.kind}. Supported: ${supported.join(',')}'`
130
+ );
131
+ }
132
+ }
133
+ }
134
+
104
135
  public start() {
105
136
  super.start();
106
137
  if (this.wsConnection) {
@@ -46,4 +46,4 @@ export const browserSupportedAudioCodec = (codecs: string[]) => {
46
46
  }
47
47
 
48
48
  return '';
49
- };
49
+ };
@@ -36,4 +36,4 @@ export const browserSupportedVideoCodec = (codecs: string[]) => {
36
36
  }
37
37
 
38
38
  return '';
39
- };
39
+ };
package/src/vxwebrtc.ts CHANGED
@@ -4,5 +4,11 @@ export { WebRtcOutputConnection, IWebRtcOutputConnection } from './WebRtcOutputC
4
4
  export { TWebRtcH264CodecOptions, TWebRtcVP9CodecOptions } from './Types/CodecsOptions';
5
5
  export { TConstrainULongRange } from './Types/WebRTCStreamConfig';
6
6
 
7
- export {browserSupportedAudioCodec} from './browserSupportedAudioCodec'
8
- export {browserSupportedVideoCodec} from './browserSupportedVideoCodec'
7
+ export {
8
+ browserSupportedAudioCodec,
9
+ EnumAudioCodecs,
10
+ EnumMediaCodecSupported,
11
+ } from './browserSupportedAudioCodec';
12
+ export { browserSupportedVideoCodec, EnumVideoCodecs } from './browserSupportedVideoCodec';
13
+
14
+ export { EnumCodecContentType } from './Types/EnumCodecContentType';
package/webpack.common.js CHANGED
@@ -37,7 +37,8 @@ module.exports = {
37
37
  },
38
38
  output: {
39
39
  filename: '[name].js',
40
- library: 'webRTC',
41
- path: path.resolve(__dirname, 'dist'),
40
+ library: 'vxWebRTC',
41
+ libraryTarget: 'umd',
42
+ path: path.resolve(__dirname, 'dist')
42
43
  }
43
44
  };
@@ -1,2 +0,0 @@
1
- import { MediaInfo } from './Types/CommonConnectionTypes';
2
- export declare function mungeSdpPublish(sdpStr: string, mungeData: MediaInfo): string;
@@ -1,8 +0,0 @@
1
- export interface TWebRtcH264CodecOptions {
2
- 'packetization-mode'?: 0 | 1;
3
- 'profile-level-id'?: string;
4
- 'level-asymmetry-allowed'?: number;
5
- }
6
- export interface TWebRtcVP9CodecOptions {
7
- 'profile-id'?: number;
8
- }
@@ -1,48 +0,0 @@
1
- import { TConstrainULongRange } from './WebRTCStreamConfig';
2
- import { TWebRtcH264CodecOptions, TWebRtcVP9CodecOptions } from './CodecsOptions';
3
- export declare type OnErrorCallback = (e: Error) => void;
4
- export declare type OnStopCallback = () => void;
5
- export interface StreamInfo {
6
- applicationName: string;
7
- streamName: string;
8
- sessionId: string;
9
- }
10
- export interface WebSocketReply {
11
- status: string;
12
- statusDescription: string;
13
- command: string;
14
- streamInfo?: StreamInfo;
15
- sdp?: RTCSessionDescriptionInit;
16
- iceCandidates?: RTCIceCandidateInit[];
17
- direction: string;
18
- }
19
- export declare enum EnumVideoCodec {
20
- H264 = "42e01f"
21
- }
22
- export interface MediaInfo {
23
- audioBitrate: TConstrainULongRange;
24
- audioCodec: string;
25
- videoBitrate: TConstrainULongRange;
26
- videoCodec: string;
27
- videoFrameRate: ConstrainULongRange;
28
- h264CodecOptions: TWebRtcH264CodecOptions;
29
- vp9CodecOptions: TWebRtcVP9CodecOptions;
30
- }
31
- export declare enum EnumWebSocketConnectionStatus {
32
- OK = 200,
33
- NOT_READY = 514
34
- }
35
- export declare enum EnumWebSocketConnectionDirection {
36
- PUBLISH = "publish",
37
- PLAY = "play"
38
- }
39
- export declare enum EnumWebSocketConnectionCommand {
40
- SEND_OFFER = "sendOffer",
41
- GET_OFFER = "getOffer",
42
- SEND_RESPONSE = "sendResponse",
43
- GET_AVAILABLE_STREAM = "getAvailableStreams"
44
- }
45
- export declare enum EnumMediaStreamTrackKind {
46
- AUDIO = "audio",
47
- VIDEO = "video"
48
- }
@@ -1,13 +0,0 @@
1
- export declare enum EnumCodecContentType {
2
- OPUS = "audio/mp4;codecs=\"opus\"",
3
- VORBIS = "audio/ogg;codecs=\"vorbis\"",
4
- H264 = "video/mp4",
5
- VP8 = "video/webm;codecs=\"vp8\"",
6
- VP9 = "video/webm;codecs=\"vp9\"",
7
- WEBM = "video/webm",
8
- HLS = "application/vnd.apple.mpegURL",
9
- H264_AVC = "video/mp4; codecs=\"avc1.42E01E\"",
10
- H264_MP4 = "video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"",
11
- H265_HEC = "video/mp4; codecs=\"hvc1.1.L0.0\"",
12
- H265_HEV = "video/mp4; codecs=\"hev1.1.L0.0\""
13
- }
@@ -1,26 +0,0 @@
1
- export declare abstract class WebRTCStreamConfig {
2
- url: string;
3
- applicationName: string;
4
- streamName: string;
5
- h264CodecOptions: {};
6
- vp9CodecOptions: {};
7
- video: TVideoPermissions;
8
- audio: TAudioPermissions;
9
- }
10
- export declare type TAudioPermissions = {
11
- noiseSuppression?: boolean;
12
- echoCancellation?: boolean;
13
- channelCount?: number;
14
- bitRate: TConstrainULongRange;
15
- };
16
- export declare type TVideoPermissions = {
17
- width: TConstrainULongRange;
18
- height: TConstrainULongRange;
19
- frameRate: TConstrainULongRange;
20
- bitRate: TConstrainULongRange;
21
- };
22
- export declare type TConstrainULongRange = {
23
- min: number;
24
- ideal: number;
25
- max: number;
26
- };
@@ -1,19 +0,0 @@
1
- import WebRtcPeerConnection, { IWebRtcPeerConnectionOptions } from './WebRtcPeerConnection';
2
- export declare class WebRtcInputConnection extends WebRtcPeerConnection {
3
- protected connectionOptions: IWebRtcInputConnection;
4
- private _peerConnectionConfig?;
5
- private _repeaterRetryCount;
6
- private _stream;
7
- constructor(connectionOptions: IWebRtcInputConnection);
8
- protected onRtcDescription(description: RTCSessionDescriptionInit): void;
9
- protected onRemoteTrack(event: RTCTrackEvent): void;
10
- protected onWsOpen(): void;
11
- protected onWsMessage(evt: MessageEvent): void;
12
- getStream(): MediaStream;
13
- start(): void;
14
- }
15
- export interface IWebRtcInputConnection extends IWebRtcPeerConnectionOptions {
16
- videoElement?: HTMLVideoElement;
17
- onTrack?: (string: any) => void;
18
- debounceTime: number;
19
- }
@@ -1,20 +0,0 @@
1
- import { MediaInfo } from './Types/CommonConnectionTypes';
2
- import WebRtcPeerConnection, { IWebRtcPeerConnectionOptions } from './WebRtcPeerConnection';
3
- export declare class WebRtcOutputConnection extends WebRtcPeerConnection {
4
- protected connectionOptions: IWebRtcOutputConnection;
5
- protected wsConnection?: WebSocket;
6
- protected peerConnection?: RTCPeerConnection;
7
- private peerConnectionConfig?;
8
- private videoSender?;
9
- private audioSender?;
10
- constructor(connectionOptions: IWebRtcOutputConnection);
11
- protected onRtcDescription(description: RTCSessionDescriptionInit): void;
12
- protected onWsOpen(): void;
13
- protected onWsMessage(evt: MessageEvent): void;
14
- start(): void;
15
- stop(): void;
16
- }
17
- export interface IWebRtcOutputConnection extends IWebRtcPeerConnectionOptions {
18
- localStream: MediaStream;
19
- mediaInfo: MediaInfo;
20
- }
@@ -1,23 +0,0 @@
1
- import { OnErrorCallback, OnStopCallback, StreamInfo, EnumWebSocketConnectionCommand, EnumWebSocketConnectionDirection } from './Types/CommonConnectionTypes';
2
- declare abstract class WebRtcPeerConnection {
3
- protected connectionOptions: IWebRtcPeerConnectionOptions;
4
- protected wsConnection?: WebSocket;
5
- protected peerConnection?: RTCPeerConnection;
6
- protected abstract onRtcDescription(description: RTCSessionDescriptionInit): void;
7
- protected abstract onWsOpen(): void;
8
- protected abstract onWsMessage(evt: MessageEvent): void;
9
- protected constructor(connectionOptions: IWebRtcPeerConnectionOptions);
10
- protected sendResponse(direction: EnumWebSocketConnectionDirection, command: EnumWebSocketConnectionCommand, description?: RTCSessionDescriptionInit): void;
11
- protected connectToWebSocket(): void;
12
- protected onError(error: Error): void;
13
- start(): void;
14
- stop(): void;
15
- }
16
- export interface IWebRtcPeerConnectionOptions {
17
- wsUrl: string;
18
- streamInfo: StreamInfo;
19
- userData?: object;
20
- onStop: OnStopCallback;
21
- onError: OnErrorCallback;
22
- }
23
- export default WebRtcPeerConnection;
@@ -1,13 +0,0 @@
1
- export declare enum EnumAudioCodecs {
2
- OPUS = "opus",
3
- VORBIS = "vorbis",
4
- PCMU = "pcmu",
5
- PCMA = "pcma"
6
- }
7
- /** @see CanPlayTypeResult */
8
- export declare enum EnumMediaCodecSupported {
9
- UNKNOWN = "",
10
- PROBABLY = "probably",
11
- MAYBE = "maybe"
12
- }
13
- export declare const browserSupportedAudioCodec: (codecs: string[]) => "" | EnumAudioCodecs.OPUS | EnumAudioCodecs.VORBIS;
@@ -1,7 +0,0 @@
1
- import { EnumVideoCodec } from './Types/CommonConnectionTypes';
2
- export declare enum EnumVideoCodecs {
3
- H264 = "h264",
4
- VP9 = "VP9",
5
- VP8 = "VP8"
6
- }
7
- export declare const browserSupportedVideoCodec: (codecs: string[]) => "" | EnumVideoCodec.H264 | EnumVideoCodecs.VP9 | EnumVideoCodecs.VP8;