@@ -25,9 +25,13 @@ public partial class Player
2525 [ EditorRequired ]
2626 public PlayerOptions ? Options { get ; set ; }
2727
28- private string ? ClassString => CssBuilder . Default ( "bb-video-player" )
29- . AddClassFromAttributes ( AdditionalAttributes )
30- . Build ( ) ;
28+ /// <summary>
29+ /// Gets or sets the client event callback. Default is null.
30+ /// </summary>
31+ [ Parameter ]
32+ public Func < string , Task > ? OnEvent { get ; set ; }
33+
34+ private string ? EventString => OnEvent == null ? "true" : null ;
3135
3236 /// <summary>
3337 /// <inheritdoc/>
@@ -39,7 +43,7 @@ protected override async Task InvokeInitAsync()
3943 {
4044 Options . Language ??= CultureInfo . CurrentUICulture . Name ;
4145 }
42- await InvokeVoidAsync ( "init" , Id , Interop , "" , Options ) ;
46+ await InvokeVoidAsync ( "init" , Id , Interop , nameof ( TriggerEvent ) , Options ) ;
4347 }
4448
4549 /// <summary>
@@ -48,4 +52,18 @@ protected override async Task InvokeInitAsync()
4852 /// <param name="option"></param>
4953 /// <returns></returns>
5054 public Task Reload ( PlayerOptions option ) => InvokeVoidAsync ( "reload" , Id , option ) ;
55+
56+ /// <summary>
57+ /// Trigger <see cref="OnEvent"/> event callback. Triggered by JSInterop.
58+ /// </summary>
59+ /// <param name="eventName"></param>
60+ /// <returns></returns>
61+ [ JSInvokable ]
62+ public async Task TriggerEvent ( string eventName )
63+ {
64+ if ( OnEvent != null )
65+ {
66+ await OnEvent ( eventName ) ;
67+ }
68+ }
5169}
0 commit comments