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

Optimize code size for VideoPlayer and WebView. #18231

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

dumganhar
Copy link
Contributor

Re: #18222

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

@dumganhar dumganhar requested a review from minggo January 21, 2025 15:04
Copy link

github-actions bot commented Jan 21, 2025

👍 Package size ⤵ -274 bytes, old: 5227657, new: 5227383

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -59031,16 +59031,8 @@
         onEnable(): void;
         onDisable(): void;
         onDestroy(): void;
         update(dt: number): void;
-        onMetaLoaded(): void;
-        onReadyToPlay(): void;
-        onPlaying(): void;
-        onPaused(): void;
-        onStopped(): void;
-        onCompleted(): void;
-        onError(): void;
-        onClicked(): void;
         /**
          * @en
          * Play the clip.<br>
          * Restart if already playing.<br>
@@ -59160,11 +59152,8 @@
          * @param {String} str
          */
         evaluateJS(str: string): void;
         __preload(): void;
-        onLoading(): void;
-        onLoaded(): void;
-        onError(...args: any[any]): void;
         onEnable(): void;
         onDisable(): void;
         onDestroy(): void;
         update(dt: number): void;

@minggo
Copy link
Contributor

minggo commented Jan 22, 2025

It seems this PR changes some interfaces.

@dumganhar
Copy link
Contributor Author

dumganhar commented Jan 22, 2025

No one will use those interfaces, you could just review those files.

this._impl.componentEventList.set(VideoPlayerEventType.META_LOADED, this.onMetaLoaded.bind(this));
this._impl.componentEventList.set(VideoPlayerEventType.READY_TO_PLAY, this.onReadyToPlay.bind(this));
this._impl.componentEventList.set(VideoPlayerEventType.PLAYING, this.onPlaying.bind(this));
this._impl.componentEventList.set(VideoPlayerEventType.PAUSED, this.onPaused.bind(this));
this._impl.componentEventList.set(VideoPlayerEventType.STOPPED, this.onStopped.bind(this));
this._impl.componentEventList.set(VideoPlayerEventType.COMPLETED, this.onCompleted.bind(this));
this._impl.componentEventList.set(VideoPlayerEventType.ERROR, this.onError.bind(this));
this._impl.componentEventList.set(VideoPlayerEventType.CLICKED, this.onClicked.bind(this));

They're callbacks set to internal module and triggered by internal module. Imagine when will a developer invoke those methods since they should be triggered internally.

I guess it was just the person who developed WebView/VideoPlayer forgot or doesn't know to add a private keyword for private methods in a class.

Anyway, this is just what I found while reviewing code.

If some one invokes those methods directly, they're doing wrong things.

# Conflicts:
#	cocos/video/video-player.ts
#	cocos/web-view/web-view.ts
@dumganhar
Copy link
Contributor Author

dumganhar commented Jan 23, 2025

And if developer wants to listen on these callbacks, they could use event subscription which is supported currently.

private onMetaLoaded (): void {
    ComponentEventHandler.emitEvents(this.videoPlayerEvent, this, VideoPlayerEventType.META_LOADED);
    this.node.emit('meta-loaded', this);
}

private onReadyToPlay (): void {
    if (this._playOnAwake && !this.isPlaying) { this.play(); }
    ComponentEventHandler.emitEvents(this.videoPlayerEvent, this, VideoPlayerEventType.READY_TO_PLAY);
    this.node.emit(VideoPlayerEventType.READY_TO_PLAY, this);
}
videoComp.node.on(VideoPlayerEventType.READY_TO_PLAY, () => {
    // balabala
});

@minggo minggo merged commit 01040a3 into cocos:v3.8.6 Jan 23, 2025
12 checks passed
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