@@ -348,7 +348,8 @@ where
348
348
/// use. This runtime is accessible to all handlers invoked by the router.
349
349
///
350
350
/// Tasks spawned by the router will be spawned on the provided runtime,
351
- /// and automatically cancelled when the returned `axum::Router` is dropped.
351
+ /// and automatically cancelled when the returned [`axum::Router`] is
352
+ /// dropped.
352
353
#[ cfg( feature = "axum" ) ]
353
354
pub fn into_axum_with_handle (
354
355
self ,
@@ -375,6 +376,47 @@ impl Router<()> {
375
376
connect. serve ( self ) . await
376
377
}
377
378
379
+ /// Create an [`AxumWsCfg`] from this router. This is a convenience method
380
+ /// for `AxumWsCfg::new(self.clone())`.
381
+ ///
382
+ /// [`AxumWsCfg`]: crate::pubsub::AxumWsCfg
383
+ #[ cfg( all( feature = "axum" , feature = "pubsub" ) ) ]
384
+ pub fn to_axum_cfg ( & self ) -> crate :: pubsub:: AxumWsCfg {
385
+ crate :: pubsub:: AxumWsCfg :: new ( self . clone ( ) )
386
+ }
387
+
388
+ /// Create an [`axum::Router`] from this router, serving this router via
389
+ /// HTTP `POST` requests at `post_route` and via WebSocket at `ws_route`.
390
+ #[ cfg( all( feature = "axum" , feature = "pubsub" ) ) ]
391
+ pub fn into_axum_with_ws ( self , post_route : & str , ws_route : & str ) -> axum:: Router < ( ) > {
392
+ let cfg = self . to_axum_cfg ( ) ;
393
+
394
+ self . into_axum ( post_route)
395
+ . with_state ( ( ) )
396
+ . route ( ws_route, axum:: routing:: any ( crate :: pubsub:: ajj_websocket) )
397
+ . with_state ( cfg)
398
+ }
399
+
400
+ /// Create an [`axum::Router`] from this router, serving this router via
401
+ /// HTTP `POST` requests at `post_route` and via WebSocket at `ws_route`.
402
+ /// This convenience method allows users to specify a runtime handle for the
403
+ /// router to use. See [`Router::into_axum_with_handle`] for more
404
+ /// information.
405
+ #[ cfg( all( feature = "axum" , feature = "pubsub" ) ) ]
406
+ pub fn into_axum_with_ws_and_handle (
407
+ self ,
408
+ post_route : & str ,
409
+ ws_route : & str ,
410
+ handle : tokio:: runtime:: Handle ,
411
+ ) -> axum:: Router < ( ) > {
412
+ let cfg = self . to_axum_cfg ( ) ;
413
+
414
+ self . into_axum_with_handle ( post_route, handle)
415
+ . with_state ( ( ) )
416
+ . route ( ws_route, axum:: routing:: any ( crate :: pubsub:: ajj_websocket) )
417
+ . with_state ( cfg)
418
+ }
419
+
378
420
/// Call a method on the router.
379
421
pub fn handle_request ( & self , args : HandlerArgs ) -> RouteFuture {
380
422
self . call_with_state ( args, ( ) )
0 commit comments