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

feat: add generics to device management #61

Merged
merged 1 commit into from
Jul 28, 2023

Conversation

brycetham
Copy link
Contributor

This PR adds generics to device management create*Stream functions in order to support using custom stream classes in these methods. It also adds a new API, createCameraAndMicrophoneStreams, to create both a camera stream and a microphone stream with a single getUserMedia call.

As part of this change, I've also slightly modified the ErrorTypes to have a generic CREATE_STREAM_FAILED error so it can be used in all cases in which getUserMedia or getDisplayMedia fail.

This completes SPARK-448441 and SPARK-448443.

@brycetham brycetham requested a review from arun3528 July 28, 2023 13:28
}

// 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.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do this in a later PR, but I think it's kind of weird that we're referencing WCME here, and naming the error class WcmeError, especially since WCME doesn't actually call any of the device management APIs.

let stream: MediaStream;
try {
stream = await media.getUserMedia({ audio: { ...constraints } });
} catch (error) {
throw new WcmeError(
ErrorTypes.CREATE_MICROPHONE_STREAM_FAILED,
`Failed to create microphone stream ${error}`
ErrorTypes.CREATE_STREAM_FAILED,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not now but would be nicer to have error codes associated later , so that we know what the cause of failure else anyone using this lib need to figureout what does all getuser media error corresponds to

>(
cameraStreamConstructor: Constructor<T>,
microphoneStreamConstructor: Constructor<U>,
constraints?: { video?: VideoDeviceConstraints; audio?: AudioDeviceConstraints }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@brycetham brycetham merged commit adf048e into main Jul 28, 2023
1 check passed
@brycetham brycetham deleted the btham/device_management_generics branch July 28, 2023 19:19
bbaldino pushed a commit that referenced this pull request Jul 28, 2023
# [2.1.0](v2.0.0...v2.1.0) (2023-07-28)

### Features

* add generics to device management ([#61](#61)) ([adf048e](adf048e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants