-
Notifications
You must be signed in to change notification settings - Fork 355
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
base: next
Are you sure you want to change the base?
Conversation
This pull request is automatically being deployed by Amplify Hosting (learn more). |
01fa594
to
e9a1a00
Compare
@@ -479,7 +496,7 @@ const Breakouts = WebexPlugin.extend({ | |||
locusUrl: this.locusUrl, | |||
}, | |||
}) | |||
.catch((err) => { | |||
.catch((err: unknown) => { |
There was a problem hiding this comment.
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.
@@ -25,7 +25,7 @@ export default class BreakoutRequest extends StatelessWebexPlugin { | |||
}: { | |||
url: string; | |||
message: string; | |||
options?: object; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) {} |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
const maxFps = mediaRequest.codecInfo?.maxFps || CODEC_DEFAULTS.h264.maxFps; | ||
const maxFs = mediaRequest.codecInfo?.maxFs || CODEC_DEFAULTS.h264.maxFs; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcin-bazyl sure
@@ -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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}[] = []; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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:*", |
There was a problem hiding this comment.
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' { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
COMPLETES WEBEX-390013
This pull request addresses
The
plugin-meetings
previously had weaktsconfig
rules. The purpose of this PR is to improve thetsconfig
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 seeRecord<string, any>
, and there were a couple of instances withany
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
The following scenarios where tested
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.