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

refactor(plugin-meetings): update tsconfig for plugin-meetings #3663

Open
wants to merge 12 commits into
base: next
Choose a base branch
from

Conversation

antsukanova
Copy link
Contributor

@antsukanova antsukanova commented Jun 25, 2024

COMPLETES WEBEX-390013

This pull request addresses

The plugin-meetings previously had weak tsconfig rules. The purpose of this PR is to improve the tsconfig rules to help identify issues faster with the data across this plugin. I am looking forward to working together with you to enhance the SDK code.

Any suggestions are welcome.

In this PR, I do not intend to fix all the types, but rather enable better handling of types.

by making the following changes

I would like to explain some of my refactoring ideas here:

  • I have used the correct types wherever possible, and I have used unknown for types that I am not certain about. In cases where there is an object, you may see Record<string, any>, and there were a couple of instances with any that were difficult to fix easily because they required changes in the codebase.

  • Additionally, I have added a global.d.ts file to mock types from other plugins. The idea is to assist TypeScript in working correctly for now, and once these plugins are changed, these declarations should be deleted along with the file.

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios where tested

  • automated tests for plugin-meetings

I certified that

  • I have read and followed contributing guidelines

  • I discussed changes with code owners prior to submitting this pull request

  • I have not skipped any automated checks

  • All existing and new tests passed

  • I have updated the documentation accordingly


Make sure to have followed the contributing guidelines before submitting.

@antsukanova antsukanova self-assigned this Jun 25, 2024
@antsukanova antsukanova marked this pull request as ready for review June 25, 2024 13:32
@antsukanova antsukanova requested review from a team as code owners June 25, 2024 13:32
@Shreyas281299 Shreyas281299 added the validated If the pull request is validated for automation. label Jun 25, 2024
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-3663.d3m3l2kee0btzx.amplifyapp.com

@@ -479,7 +496,7 @@ const Breakouts = WebexPlugin.extend({
locusUrl: this.locusUrl,
},
})
.catch((err) => {
.catch((err: unknown) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to set unknown everywhere in this PR, but there are cases where err is explicitly an object. With object handling, the only way to handle it is to set it to any due to the lack of error handlers for errors (see screenshot). In the future, it would be great to create a proper Error type structure and align it accordingly.
Screenshot 2024-06-25 at 17 43 09

@@ -25,7 +25,7 @@ export default class BreakoutRequest extends StatelessWebexPlugin {
}: {
url: string;
message: string;
options?: object;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally, it would be to avoid object, as it's less flexible than Record<string, any> in short. Here is some discussion about that: https://stackoverflow.com/a/66575880

if (this.queue.length === 0) {
return null;
}

return this.queue.shift();
return this.queue.shift() ?? null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Array<ItemType>.shift(): ItemType | undefined, so add here null to align logic

* @returns {undefined}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onDeltaAction(action: string, locus) {}
Copy link
Contributor Author

@antsukanova antsukanova Jun 25, 2024

Choose a reason for hiding this comment

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

Just added the proper type, and this won't be needed.

SelfUtils.getBreakoutSessions = (self) => self?.controls?.breakout?.sessions;
SelfUtils.getBreakout = (self) => self?.controls?.breakout;
SelfUtils.getInterpretation = (self) => self?.controls?.interpretation;
SelfUtils.getBreakoutSessions = (self: Record<string, any>) => self?.controls?.breakout?.sessions;
Copy link
Contributor Author

@antsukanova antsukanova Jun 25, 2024

Choose a reason for hiding this comment

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

Btw, I already have a branch that I will add to review later for updating with the proper types of locus utils.

@@ -222,15 +222,16 @@ Media.createMediaConnection = (
audio: audioStream?.outputStream?.getTracks()[0],
video: videoStream?.outputStream?.getTracks()[0],
screenShareVideo: shareVideoStream?.outputStream?.getTracks()[0],
// @ts-ignore
screenShareAudio: shareAudioStream?.outputStream?.getTracks()[0], // TODO: add type for screenShareAudio in internal-media-core SPARK-446923
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this issue, I have to add @ts-ignore because otherwise, types will not match. I see there is already a TODO for this issue, so I hope it will be fixed soon.

Comment on lines +227 to +228
const maxFps = mediaRequest.codecInfo?.maxFps || CODEC_DEFAULTS.h264.maxFps;
const maxFs = mediaRequest.codecInfo?.maxFs || CODEC_DEFAULTS.h264.maxFs;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From types it seems that both maxFps and maxFs can be undefined, so I added here default value too

Copy link
Collaborator

Choose a reason for hiding this comment

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

the comment explains why in practice maxFs cannot be undefined, but it doesn't hurt to have the fallback

@@ -1161,7 +1161,8 @@ export class RemoteMediaManager extends EventsScope {
remoteMedia.stop();

delete this.media.video.memberPanes[paneId];
delete this.currentLayout.memberVideoPanes?.[paneId];
// TODO: to delete memberVideoPanes using paneId it needs to be a number
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put todo here because types for paneId does not match and need to be changed properly

Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks like a real bug, the paneId is always a string and memberVideoPanes is an array of MemberVideoPane, so instead of this delete we should be finding the pane by paneId in the memberVideoPanes and removing it, something like this:
this.currentLayout.memberVideoPanes = this.currentLayout.memberVideoPanes.filter((pane) => pane.id !== paneId))

also the check if (newPane.id in this.currentLayout.memberVideoPanes) inside addMemberVideoPane() seems wrong too. Can you raise a jira for this, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -70,7 +70,7 @@ export class ClusterReachability {
* @returns {Number} Milliseconds
*/
private getElapsedTime() {
return Math.round(performance.now() - this.startTimestamp);
return Math.round(performance.now() - (this.startTimestamp || 0));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this.startTimestamp wasn't initiated, so the type tells me that it can be undefined. I put a fallback to make types not complain about that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

this function should probably throw if it's called before this.startTimestamp is set, as this should never happen

private getUnreachableClusters(): Array<{name: string; protocol: string}> {
const unreachableList = [];
private getUnreachableClusters(): {name: string; protocol: string}[] {
const unreachableList: {name: string; protocol: string}[] = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to align types, I used the more commonly used type definition for arrays [] everywhere I could and suggest preferring one style for the entire codebase.

Copy link
Collaborator

Choose a reason for hiding this comment

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

can this be enforced automatically with eslint? otherwise it will keep coming up

BTW, personally I prefer to use the Array<> syntax if the elements of the array have a long complicated type like an object with multiple properties, because it's easier to miss the [] at the end when reading it, but I don't mind which syntax we enforce.

@@ -1,6 +1,41 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"module": "es2020",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I combined rules from the calling plugin and also added some useful type rules from WCME. I'm open to discussing any details about these rules, as I might have missed some crucial points that are necessary for the SDK. I appreciate your effort in asking about this.

@@ -71,9 +71,14 @@
"@webex/common": "workspace:*",
"@webex/internal-plugin-calendar": "workspace:*",
"@webex/internal-plugin-device": "workspace:*",
"@webex/internal-plugin-dss": "workspace:*",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why these plugins weren't included before, but this is the reason why I have an issue with the test-style falling. If you know specific reasons for not including it, please let me know, and we can try to find other ways to fix that. Thanks!


export = AmpCollection;
}
declare module 'javascript-state-machine' {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe for javascript-state-machine we could use https://www.npmjs.com/package/@types/javascript-state-machine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, good point. I will add it. It's worth doing now.

supportHDV?: boolean;
canShareWhiteBoard?: boolean;
enforceVirtualBackground?: boolean;
canInviteNewParticipants?: boolean | null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

for all these fields - they already have the ?: in the type declaration so they can be undefined, so maybe instead of adding | null it would be better to just initialise them to undefined in the constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marcin-bazyl Good point, yes. I saw a couple of files that just define it like that. I wasn't sure if it was okay to change, so I've made a soft fix. I will update this approach then. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
validated If the pull request is validated for automation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants