@@ -29,9 +29,6 @@ internal abstract class AbstractBrowserRefreshServer(string middlewareAssemblyPa
2929{
3030 public const string ServerLogComponentName = "BrowserRefreshServer" ;
3131
32- private static readonly ReadOnlyMemory < byte > s_reloadMessage = Encoding . UTF8 . GetBytes ( "Reload" ) ;
33- private static readonly ReadOnlyMemory < byte > s_waitMessage = Encoding . UTF8 . GetBytes ( "Wait" ) ;
34- private static readonly ReadOnlyMemory < byte > s_pingMessage = Encoding . UTF8 . GetBytes ( """{ "type" : "Ping" }""" ) ;
3532 private static readonly JsonSerializerOptions s_jsonSerializerOptions = new ( JsonSerializerDefaults . Web ) ;
3633
3734 private readonly List < BrowserConnection > _activeConnections = [ ] ;
@@ -233,19 +230,15 @@ public ValueTask SendJsonMessageAsync<TValue>(TValue value, CancellationToken ca
233230 public ValueTask SendReloadMessageAsync ( CancellationToken cancellationToken )
234231 {
235232 logger . Log ( LogEvents . ReloadingBrowser ) ;
236- return SendAsync ( s_reloadMessage , cancellationToken ) ;
233+ return SendAsync ( JsonReloadRequest . Message , cancellationToken ) ;
237234 }
238235
239236 public ValueTask SendWaitMessageAsync ( CancellationToken cancellationToken )
240237 {
241238 logger . Log ( LogEvents . SendingWaitMessage ) ;
242- return SendAsync ( s_waitMessage , cancellationToken ) ;
239+ return SendAsync ( JsonWaitRequest . Message , cancellationToken ) ;
243240 }
244241
245- // obsolete: to be removed
246- public ValueTask SendPingMessageAsync ( CancellationToken cancellationToken )
247- => SendAsync ( s_pingMessage , cancellationToken ) ;
248-
249242 private ValueTask SendAsync ( ReadOnlyMemory < byte > messageBytes , CancellationToken cancellationToken )
250243 => SendAndReceiveAsync ( request : _ => messageBytes , response : null , cancellationToken ) ;
251244
@@ -293,13 +286,13 @@ public async ValueTask SendAndReceiveAsync<TRequest>(
293286 public ValueTask RefreshBrowserAsync ( CancellationToken cancellationToken )
294287 {
295288 logger . Log ( LogEvents . RefreshingBrowser ) ;
296- return SendJsonMessageAsync ( new AspNetCoreHotReloadApplied ( ) , cancellationToken ) ;
289+ return SendAsync ( JsonRefreshBrowserRequest . Message , cancellationToken ) ;
297290 }
298291
299292 public ValueTask ReportCompilationErrorsInBrowserAsync ( ImmutableArray < string > compilationErrors , CancellationToken cancellationToken )
300293 {
301294 logger . Log ( LogEvents . UpdatingDiagnostics ) ;
302- return SendJsonMessageAsync ( new HotReloadDiagnostics { Diagnostics = compilationErrors } , cancellationToken ) ;
295+ return SendJsonMessageAsync ( new JsonReportDiagnosticsRequest { Diagnostics = compilationErrors } , cancellationToken ) ;
303296 }
304297
305298 public async ValueTask UpdateStaticAssetsAsync ( IEnumerable < string > relativeUrls , CancellationToken cancellationToken )
@@ -308,24 +301,37 @@ public async ValueTask UpdateStaticAssetsAsync(IEnumerable<string> relativeUrls,
308301 foreach ( var relativeUrl in relativeUrls )
309302 {
310303 logger . Log ( LogEvents . SendingStaticAssetUpdateRequest , relativeUrl ) ;
311- var message = JsonSerializer . SerializeToUtf8Bytes ( new UpdateStaticFileMessage { Path = relativeUrl } , s_jsonSerializerOptions ) ;
304+ var message = JsonSerializer . SerializeToUtf8Bytes ( new JasonUpdateStaticFileRequest { Path = relativeUrl } , s_jsonSerializerOptions ) ;
312305 await SendAsync ( message , cancellationToken ) ;
313306 }
314307 }
315308
316- private readonly struct AspNetCoreHotReloadApplied
309+ private readonly struct JsonWaitRequest
310+ {
311+ public string Type => "Wait" ;
312+ public static readonly ReadOnlyMemory < byte > Message = JsonSerializer . SerializeToUtf8Bytes ( new JsonWaitRequest ( ) , s_jsonSerializerOptions ) ;
313+ }
314+
315+ private readonly struct JsonReloadRequest
316+ {
317+ public string Type => "Reload" ;
318+ public static readonly ReadOnlyMemory < byte > Message = JsonSerializer . SerializeToUtf8Bytes ( new JsonReloadRequest ( ) , s_jsonSerializerOptions ) ;
319+ }
320+
321+ private readonly struct JsonRefreshBrowserRequest
317322 {
318- public string Type => "AspNetCoreHotReloadApplied" ;
323+ public string Type => "RefreshBrowser" ;
324+ public static readonly ReadOnlyMemory < byte > Message = JsonSerializer . SerializeToUtf8Bytes ( new JsonRefreshBrowserRequest ( ) , s_jsonSerializerOptions ) ;
319325 }
320326
321- private readonly struct HotReloadDiagnostics
327+ private readonly struct JsonReportDiagnosticsRequest
322328 {
323- public string Type => "HotReloadDiagnosticsv1 " ;
329+ public string Type => "ReportDiagnostics " ;
324330
325331 public IEnumerable < string > Diagnostics { get ; init ; }
326332 }
327333
328- private readonly struct UpdateStaticFileMessage
334+ private readonly struct JasonUpdateStaticFileRequest
329335 {
330336 public string Type => "UpdateStaticFile" ;
331337 public string Path { get ; init ; }
0 commit comments