@4players/odin-common 2.17.4 → 2.19.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.
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VideoCodec = void 0;
4
- const sdp_transform_1 = require("sdp-transform");
5
4
  const result_1 = require("./result");
6
5
  const validCodecs = ['VP8', 'VP9', 'AV1', 'H264'];
7
6
  class VideoCodec {
@@ -14,22 +13,19 @@ class VideoCodec {
14
13
  return validCodecs.includes(this.codec);
15
14
  }
16
15
  isSupported() {
17
- var _a, _b, _c;
18
16
  if (typeof RTCRtpReceiver === 'undefined' ||
19
17
  typeof RTCRtpReceiver.getCapabilities === 'undefined') {
20
- return false;
18
+ return null;
21
19
  }
22
20
  const expectedMimeType = (0, result_1.unwrapOr)(this.getMimeType(), '').toLowerCase();
23
21
  const expectedFmtpLine = new Set((0, result_1.unwrapOr)(this.getSdpFmtpLine(), '')
24
22
  .split(';')
25
23
  .map((arg) => arg.trim().toLowerCase()));
26
- return ((_c = (_b = (_a = RTCRtpReceiver.getCapabilities('video')) === null || _a === void 0 ? void 0 : _a.codecs) === null || _b === void 0 ? void 0 : _b.some((c) => {
27
- var _a;
24
+ return (RTCRtpReceiver.getCapabilities('video')?.codecs?.find((c) => {
28
25
  const actualMimeType = c.mimeType.toLowerCase();
29
- const actualFmtpLine = new Set(((_a = c.sdpFmtpLine) !== null && _a !== void 0 ? _a : '')
26
+ const actualFmtpLine = new Set((c.sdpFmtpLine ?? '')
30
27
  .split(';')
31
28
  .map((arg) => arg.trim().toLowerCase()));
32
- console.log(actualMimeType, actualFmtpLine);
33
29
  if (expectedMimeType !== actualMimeType)
34
30
  return false;
35
31
  if (expectedFmtpLine.size !== actualFmtpLine.size)
@@ -39,36 +35,7 @@ class VideoCodec {
39
35
  return false;
40
36
  }
41
37
  return true;
42
- })) !== null && _c !== void 0 ? _c : false);
43
- }
44
- filterSdp(description) {
45
- if (!this.isValid()) {
46
- return description;
47
- }
48
- const sdp = (0, sdp_transform_1.parse)(description);
49
- const payload = (0, result_1.unwrap)(this.getPayloadType());
50
- const config = (0, result_1.unwrap)(this.getSdpFmtpLine());
51
- sdp.media = sdp.media.map((media) => {
52
- if (media.type !== 'video') {
53
- return media;
54
- }
55
- media.payloads = '';
56
- media.rtp = [];
57
- media.fmtp = [];
58
- media.rtcpFb = [];
59
- media.payloads = String(payload);
60
- media.rtp.push({ payload, codec: this.codec, rate: this.clockRate });
61
- if (config.length) {
62
- media.fmtp.push({ payload, config });
63
- }
64
- media.rtcpFb.push({ payload, type: 'goog-remb' });
65
- media.rtcpFb.push({ payload, type: 'transport-cc' });
66
- media.rtcpFb.push({ payload, type: 'ccm', subtype: 'fir' });
67
- media.rtcpFb.push({ payload, type: 'nack' });
68
- media.rtcpFb.push({ payload, type: 'nack', subtype: 'pli' });
69
- return media;
70
- });
71
- return (0, sdp_transform_1.write)(sdp);
38
+ }) ?? null);
72
39
  }
73
40
  getPayloadType() {
74
41
  switch (this.codec) {
@@ -83,14 +83,14 @@ function debug(msg, ...args) {
83
83
  }
84
84
  class Logger {
85
85
  constructor(level, name, options) {
86
- this.name = name !== null && name !== void 0 ? name : LOG_DEFAULT_ID;
86
+ this.name = name ?? LOG_DEFAULT_ID;
87
87
  if ((0, validation_1.isNumber)(level)) {
88
88
  this._Level = (0, result_1.unwrap)(getLevelByName((0, result_1.unwrap)(getLevelName(level))));
89
89
  }
90
90
  else {
91
91
  this._Level = (0, result_1.unwrap)(getLevelByName(level));
92
92
  }
93
- this._Handlers = (options === null || options === void 0 ? void 0 : options.handlers) || [new LogHandler(level)];
93
+ this._Handlers = options?.handlers || [new LogHandler(level)];
94
94
  LOG_COLLECTION.set(this.name, this);
95
95
  }
96
96
  get level() {
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.Selector = void 0;
13
4
  class Selector {
@@ -15,17 +6,13 @@ class Selector {
15
6
  this._Generators = _Generators;
16
7
  this._Futures = _Generators.map(Selector.addIndex);
17
8
  }
18
- next() {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- const [result, index] = yield Promise.race(this._Futures);
21
- this._Futures[index] = Selector.addIndex(this._Generators[index], index);
22
- return result;
23
- });
9
+ async next() {
10
+ const [result, index] = await Promise.race(this._Futures);
11
+ this._Futures[index] = Selector.addIndex(this._Generators[index], index);
12
+ return result;
24
13
  }
25
- static addIndex(generator, index) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- return [yield generator(), index];
28
- });
14
+ static async addIndex(generator, index) {
15
+ return [await generator(), index];
29
16
  }
30
17
  }
31
18
  exports.Selector = Selector;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.Strand = void 0;
13
4
  class Strand {
@@ -18,32 +9,30 @@ class Strand {
18
9
  }
19
10
  enqueue(task) {
20
11
  return new Promise((resolve, reject) => {
21
- const wrapped = () => __awaiter(this, void 0, void 0, function* () {
12
+ const wrapped = async () => {
22
13
  try {
23
- const result = yield task(...this._Values);
14
+ const result = await task(...this._Values);
24
15
  resolve(result);
25
16
  }
26
17
  catch (error) {
27
18
  reject(error);
28
19
  }
29
- });
20
+ };
30
21
  this._Tasks.push(wrapped);
31
22
  if (!this._Running) {
32
23
  this.execute();
33
24
  }
34
25
  });
35
26
  }
36
- execute() {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- this._Running = true;
39
- while (true) {
40
- const task = this._Tasks.shift();
41
- if (task === undefined)
42
- break;
43
- yield task();
44
- }
45
- this._Running = false;
46
- });
27
+ async execute() {
28
+ this._Running = true;
29
+ while (true) {
30
+ const task = this._Tasks.shift();
31
+ if (task === undefined)
32
+ break;
33
+ await task();
34
+ }
35
+ this._Running = false;
47
36
  }
48
37
  }
49
38
  exports.Strand = Strand;
package/lib/esm/index.js CHANGED
@@ -1,5 +1,4 @@
1
- import * as zod_1 from 'zod';
2
- export { zod_1 as zod };
1
+ export * as zod from 'zod';
3
2
  export * from './schema/serialization';
4
3
  export * from './schema/token';
5
4
  export * from './schema/room';
@@ -1,5 +1,4 @@
1
- import { parse, write } from 'sdp-transform';
2
- import { failure, success, unwrap, unwrapOr } from './result';
1
+ import { failure, success, unwrapOr } from './result';
3
2
  const validCodecs = ['VP8', 'VP9', 'AV1', 'H264'];
4
3
  export class VideoCodec {
5
4
  constructor(codec) {
@@ -11,22 +10,19 @@ export class VideoCodec {
11
10
  return validCodecs.includes(this.codec);
12
11
  }
13
12
  isSupported() {
14
- var _a, _b, _c;
15
13
  if (typeof RTCRtpReceiver === 'undefined' ||
16
14
  typeof RTCRtpReceiver.getCapabilities === 'undefined') {
17
- return false;
15
+ return null;
18
16
  }
19
17
  const expectedMimeType = unwrapOr(this.getMimeType(), '').toLowerCase();
20
18
  const expectedFmtpLine = new Set(unwrapOr(this.getSdpFmtpLine(), '')
21
19
  .split(';')
22
20
  .map((arg) => arg.trim().toLowerCase()));
23
- return ((_c = (_b = (_a = RTCRtpReceiver.getCapabilities('video')) === null || _a === void 0 ? void 0 : _a.codecs) === null || _b === void 0 ? void 0 : _b.some((c) => {
24
- var _a;
21
+ return (RTCRtpReceiver.getCapabilities('video')?.codecs?.find((c) => {
25
22
  const actualMimeType = c.mimeType.toLowerCase();
26
- const actualFmtpLine = new Set(((_a = c.sdpFmtpLine) !== null && _a !== void 0 ? _a : '')
23
+ const actualFmtpLine = new Set((c.sdpFmtpLine ?? '')
27
24
  .split(';')
28
25
  .map((arg) => arg.trim().toLowerCase()));
29
- console.log(actualMimeType, actualFmtpLine);
30
26
  if (expectedMimeType !== actualMimeType)
31
27
  return false;
32
28
  if (expectedFmtpLine.size !== actualFmtpLine.size)
@@ -36,36 +32,7 @@ export class VideoCodec {
36
32
  return false;
37
33
  }
38
34
  return true;
39
- })) !== null && _c !== void 0 ? _c : false);
40
- }
41
- filterSdp(description) {
42
- if (!this.isValid()) {
43
- return description;
44
- }
45
- const sdp = parse(description);
46
- const payload = unwrap(this.getPayloadType());
47
- const config = unwrap(this.getSdpFmtpLine());
48
- sdp.media = sdp.media.map((media) => {
49
- if (media.type !== 'video') {
50
- return media;
51
- }
52
- media.payloads = '';
53
- media.rtp = [];
54
- media.fmtp = [];
55
- media.rtcpFb = [];
56
- media.payloads = String(payload);
57
- media.rtp.push({ payload, codec: this.codec, rate: this.clockRate });
58
- if (config.length) {
59
- media.fmtp.push({ payload, config });
60
- }
61
- media.rtcpFb.push({ payload, type: 'goog-remb' });
62
- media.rtcpFb.push({ payload, type: 'transport-cc' });
63
- media.rtcpFb.push({ payload, type: 'ccm', subtype: 'fir' });
64
- media.rtcpFb.push({ payload, type: 'nack' });
65
- media.rtcpFb.push({ payload, type: 'nack', subtype: 'pli' });
66
- return media;
67
- });
68
- return write(sdp);
35
+ }) ?? null);
69
36
  }
70
37
  getPayloadType() {
71
38
  switch (this.codec) {
@@ -73,14 +73,14 @@ export function debug(msg, ...args) {
73
73
  }
74
74
  export class Logger {
75
75
  constructor(level, name, options) {
76
- this.name = name !== null && name !== void 0 ? name : LOG_DEFAULT_ID;
76
+ this.name = name ?? LOG_DEFAULT_ID;
77
77
  if (isNumber(level)) {
78
78
  this._Level = unwrap(getLevelByName(unwrap(getLevelName(level))));
79
79
  }
80
80
  else {
81
81
  this._Level = unwrap(getLevelByName(level));
82
82
  }
83
- this._Handlers = (options === null || options === void 0 ? void 0 : options.handlers) || [new LogHandler(level)];
83
+ this._Handlers = options?.handlers || [new LogHandler(level)];
84
84
  LOG_COLLECTION.set(this.name, this);
85
85
  }
86
86
  get level() {
@@ -1,27 +1,14 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class Selector {
11
2
  constructor(_Generators) {
12
3
  this._Generators = _Generators;
13
4
  this._Futures = _Generators.map(Selector.addIndex);
14
5
  }
15
- next() {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const [result, index] = yield Promise.race(this._Futures);
18
- this._Futures[index] = Selector.addIndex(this._Generators[index], index);
19
- return result;
20
- });
6
+ async next() {
7
+ const [result, index] = await Promise.race(this._Futures);
8
+ this._Futures[index] = Selector.addIndex(this._Generators[index], index);
9
+ return result;
21
10
  }
22
- static addIndex(generator, index) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- return [yield generator(), index];
25
- });
11
+ static async addIndex(generator, index) {
12
+ return [await generator(), index];
26
13
  }
27
14
  }
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  export class Strand {
11
2
  constructor(...values) {
12
3
  this._Tasks = [];
@@ -15,31 +6,29 @@ export class Strand {
15
6
  }
16
7
  enqueue(task) {
17
8
  return new Promise((resolve, reject) => {
18
- const wrapped = () => __awaiter(this, void 0, void 0, function* () {
9
+ const wrapped = async () => {
19
10
  try {
20
- const result = yield task(...this._Values);
11
+ const result = await task(...this._Values);
21
12
  resolve(result);
22
13
  }
23
14
  catch (error) {
24
15
  reject(error);
25
16
  }
26
- });
17
+ };
27
18
  this._Tasks.push(wrapped);
28
19
  if (!this._Running) {
29
20
  this.execute();
30
21
  }
31
22
  });
32
23
  }
33
- execute() {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- this._Running = true;
36
- while (true) {
37
- const task = this._Tasks.shift();
38
- if (task === undefined)
39
- break;
40
- yield task();
41
- }
42
- this._Running = false;
43
- });
24
+ async execute() {
25
+ this._Running = true;
26
+ while (true) {
27
+ const task = this._Tasks.shift();
28
+ if (task === undefined)
29
+ break;
30
+ await task();
31
+ }
32
+ this._Running = false;
44
33
  }
45
34
  }
@@ -15,7 +15,7 @@ export declare namespace Backend {
15
15
  joinRoom(parameters: JoinRoomParameters): Room;
16
16
  createAudioPlayback(parameters: CreateAudioPlaybackParameters): Promise<AudioPlayback>;
17
17
  createAudioCapture(parameters: CreateAudioCaptureParameters): Promise<AudioCapture>;
18
- createVideoCapture(ms: MediaStream, customType?: string): Promise<VideoCapture>;
18
+ createVideoCapture(ms: MediaStream, options?: DeviceOptions): Promise<VideoCapture>;
19
19
  createVideoPlayback(parameters: CreateVideoPlaybackParameters): Promise<VideoPlayback>;
20
20
  enumerateDevices(): Promise<Array<Device>>;
21
21
  setOutputVolume(volume: Volume): void;
@@ -148,4 +148,8 @@ export declare namespace Backend {
148
148
  configure(settings: CipherSettings): void;
149
149
  getPeerStatus(peerId: number): PeerCipherStatus;
150
150
  }
151
+ type DeviceOptions = {
152
+ codec?: 'H264' | 'VP8' | 'VP9';
153
+ customType?: string;
154
+ };
151
155
  }
@@ -7,8 +7,7 @@ export declare class VideoCodec {
7
7
  readonly clockRate = 90000;
8
8
  constructor(codec: Codec);
9
9
  isValid(): boolean;
10
- isSupported(): boolean;
11
- filterSdp(description: string): string;
10
+ isSupported(): RTCRtpCodec | null;
12
11
  getPayloadType(): Result<number>;
13
12
  getMimeType(): Result<string>;
14
13
  getSdpFmtpLine(): Result<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4players/odin-common",
3
- "version": "2.17.4",
3
+ "version": "2.19.0",
4
4
  "description": "A collection of commonly used type definitions and utility functions across ODIN web projects",
5
5
  "author": "Josho Bleicker <josho.bleicker@4players.io> (https://www.4players.io)",
6
6
  "homepage": "https://www.4players.io",