|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information. |
| 2 | + |
| 3 | +namespace Microsoft.VisualStudio.ProjectSystem.HotReload; |
| 4 | + |
| 5 | +/// <summary> |
| 6 | +/// Implements a web socket server which allows connections from js code injected in the response stream by asp.net core middleware. This |
| 7 | +/// enables sending a refresh command to the browser when code changes. |
| 8 | +/// </summary> |
| 9 | +[ProjectSystemContract(ProjectSystemContractScope.ConfiguredProject, ProjectSystemContractProvider.System, Cardinality = ImportCardinality.ExactlyOne)] |
| 10 | +public interface IBrowserRefreshService |
| 11 | +{ |
| 12 | + /// <summary> |
| 13 | + /// Returns true if the current running app has browserLink injected |
| 14 | + /// </summary> |
| 15 | + bool BrowserLinkInjected { get; } |
| 16 | + |
| 17 | + /// <summary> |
| 18 | + /// Starts the server if it hasn't been started yet. |
| 19 | + /// It is safe to call this multiple times. |
| 20 | + /// </summary> |
| 21 | + /// <param name="cancellationToken"></param> |
| 22 | + /// <returns></returns> |
| 23 | + ValueTask StartServerAsync(CancellationToken cancellationToken); |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Configures the launch environment to enable browser refresh. |
| 27 | + /// Must be called after <see cref="StartServerAsync(CancellationToken)"/> is called. |
| 28 | + /// </summary> |
| 29 | + ValueTask ConfigureLaunchEnvironmentAsync(IDictionary<string, string> builder, bool enableHotReload, CancellationToken cancellationToken); |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Sends a message to the browser to that updates were applied. This is preferable to the refresh messages since is knowledgeable about |
| 33 | + /// whether blazor is loaded in the page and will do the right thing. Note that this function throws on failure |
| 34 | + /// </summary> |
| 35 | + ValueTask RefreshBrowserAsync(CancellationToken cancellationToken); |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Sends a ping message to all connected browsers. |
| 39 | + /// It will throw InvalidOperationException if the browser refresh server is not started. |
| 40 | + /// </summary> |
| 41 | + /// <param name="cancellationToken"></param> |
| 42 | + ValueTask SendPingMessageAsync(CancellationToken cancellationToken); |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Sends a reload message to all connected browsers. |
| 46 | + /// It will throw InvalidOperationException if the browser refresh server is not started. |
| 47 | + /// </summary> |
| 48 | + /// <returns></returns> |
| 49 | + ValueTask SendReloadMessageAsync(CancellationToken cancellationToken); |
| 50 | + |
| 51 | + /// <summary> |
| 52 | + /// Sends a wait message to all connected browsers. |
| 53 | + /// It will throw InvalidOperationException if the browser refresh server is not started. |
| 54 | + /// </summary> |
| 55 | + ValueTask SendWaitMessageAsync(CancellationToken cancellationToken); |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Asynchronously updates the static assets referenced by the specified URLs. |
| 59 | + /// </summary> |
| 60 | + /// <remarks>If the operation is canceled via the provided cancellation token, the returned task will be |
| 61 | + /// in a canceled state. The method does not guarantee the order in which assets are updated.</remarks> |
| 62 | + /// <param name="assetUrls">A collection of URLs identifying the static assets to update. Each URL must be a valid, non-empty string.</param> |
| 63 | + /// <param name="cancellationToken">A token that can be used to cancel the update operation.</param> |
| 64 | + /// <returns>A task that represents the asynchronous update operation.</returns> |
| 65 | + ValueTask UpdateStaticAssetsAsync(IEnumerable<string> assetUrls, CancellationToken cancellationToken); |
| 66 | +} |
0 commit comments