Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rename WcmeError to WebrtcCoreError #65

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: rename WcmeError to WebrtcCoreError
  • Loading branch information
Bryce Tham committed Dec 11, 2023
commit c75cddbcd6f3d7087dc8adc91aa10323c36a5b0f
51 changes: 15 additions & 36 deletions src/device/device-management.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,14 @@
import { WebrtcCoreError, WebrtcCoreErrorTypes } from '../errors';
import * as media from '../media';
import { LocalCameraStream } from '../media/local-camera-stream';
import { LocalDisplayStream } from '../media/local-display-stream';
import { LocalMicrophoneStream } from '../media/local-microphone-stream';
import { LocalSystemAudioStream } from '../media/local-system-audio-stream';
import { VideoContentHint } from '../media/local-video-stream';

export enum ErrorTypes {
DEVICE_PERMISSION_DENIED = 'DEVICE_PERMISSION_DENIED',
CREATE_STREAM_FAILED = 'CREATE_CAMERA_STREAM',
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Constructor<T> = new (...args: any[]) => T;

/**
* Represents a WCME error, which contains error type and error message.
*/
export class WcmeError {
type: string;

message: string;

/**
* Creates new error.
*
* @param type - Error type.
* @param message - Error message.
*/
constructor(type: ErrorTypes, message = '') {
this.type = type;
this.message = message;
}
}

export type AudioDeviceConstraints = Pick<
MediaTrackConstraints,
| 'autoGainControl'
Expand Down Expand Up @@ -68,8 +44,8 @@ export async function createCameraStream<T extends LocalCameraStream>(
try {
stream = await media.getUserMedia({ video: { ...constraints } });
} catch (error) {
throw new WcmeError(
ErrorTypes.CREATE_STREAM_FAILED,
throw new WebrtcCoreError(
WebrtcCoreErrorTypes.CREATE_STREAM_FAILED,
`Failed to create camera stream: ${error}`
);
}
Expand All @@ -91,8 +67,8 @@ export async function createMicrophoneStream<T extends LocalMicrophoneStream>(
try {
stream = await media.getUserMedia({ audio: { ...constraints } });
} catch (error) {
throw new WcmeError(
ErrorTypes.CREATE_STREAM_FAILED,
throw new WebrtcCoreError(
WebrtcCoreErrorTypes.CREATE_STREAM_FAILED,
`Failed to create microphone stream: ${error}`
);
}
Expand Down Expand Up @@ -124,8 +100,8 @@ export async function createCameraAndMicrophoneStreams<
audio: { ...constraints?.audio },
});
} catch (error) {
throw new WcmeError(
ErrorTypes.CREATE_STREAM_FAILED,
throw new WebrtcCoreError(
WebrtcCoreErrorTypes.CREATE_STREAM_FAILED,
`Failed to create camera and microphone streams: ${error}`
);
}
Expand Down Expand Up @@ -153,8 +129,8 @@ export async function createDisplayStream<T extends LocalDisplayStream>(
try {
stream = await media.getDisplayMedia({ video: true });
} catch (error) {
throw new WcmeError(
ErrorTypes.CREATE_STREAM_FAILED,
throw new WebrtcCoreError(
WebrtcCoreErrorTypes.CREATE_STREAM_FAILED,
`Failed to create display stream: ${error}`
);
}
Expand Down Expand Up @@ -187,8 +163,8 @@ export async function createDisplayStreamWithAudio<
try {
stream = await media.getDisplayMedia({ video: true, audio: true });
} catch (error) {
throw new WcmeError(
ErrorTypes.CREATE_STREAM_FAILED,
throw new WebrtcCoreError(
WebrtcCoreErrorTypes.CREATE_STREAM_FAILED,
`Failed to create display and system audio streams: ${error}`
);
}
Expand Down Expand Up @@ -221,7 +197,10 @@ export async function getDevices(deviceKind?: media.DeviceKind): Promise<MediaDe
media.enumerateDevices
);
} catch (error) {
throw new WcmeError(ErrorTypes.DEVICE_PERMISSION_DENIED, 'Failed to ensure device permissions');
throw new WebrtcCoreError(
WebrtcCoreErrorTypes.DEVICE_PERMISSION_DENIED,
'Failed to ensure device permissions'
);
}

return devices.filter((v: MediaDeviceInfo) => (deviceKind ? v.kind === deviceKind : true));
Expand Down
24 changes: 24 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export enum WebrtcCoreErrorTypes {
DEVICE_PERMISSION_DENIED = 'DEVICE_PERMISSION_DENIED',
CREATE_STREAM_FAILED = 'CREATE_STREAM_FAILED',
}

/**
* Represents a WebRTC core error, which contains error type and error message.
*/
export class WebrtcCoreError {
type: string;

message: string;

/**
* Creates new error.
*
* @param type - Error type.
* @param message - Error message.
*/
constructor(type: WebrtcCoreErrorTypes, message = '') {
this.type = type;
this.message = message;
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as media from './media';

export * from './device/device-management';
export * from './errors';
export * from './media/local-audio-stream';
export * from './media/local-camera-stream';
export * from './media/local-display-stream';
Expand Down