Skip to content

Commit e627a85

Browse files
committed
replace /ws to 0.2
1 parent 1aa8203 commit e627a85

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

src/main.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,24 @@ async fn routes(
8686
_ => {}
8787
}
8888

89+
let record_config = Arc::new(services::ws_record::WsRecordSetting {
90+
record_callback_url: config.record.callback_url,
91+
});
92+
93+
let ws_setting = Arc::new(services::ws::WsSetting::new(
94+
hello_wav.clone(),
95+
config.config.clone(),
96+
tool_set.clone(),
97+
));
98+
8999
let mut router = Router::new()
90100
// .route("/", get(handler))
91-
.route("/ws/{id}", any(services::mixed_handler))
101+
.route("/v1/ws/{id}", any(services::mixed_handler))
92102
.route("/v1/chat/{id}", any(services::ws::ws_handler))
93103
.route("/v1/record/{id}", any(services::ws_record::ws_handler))
94104
.nest("/downloads", services::file::new_file_service("./record"))
95-
.layer(axum::Extension(Arc::new(services::ws::WsSetting::new(
96-
hello_wav.clone(),
97-
config.config.clone(),
98-
tool_set.clone(),
99-
))))
100-
.layer(axum::Extension(Arc::new(
101-
services::ws_record::WsRecordSetting {
102-
record_callback_url: config.record.callback_url,
103-
},
104-
)));
105+
.layer(axum::Extension(ws_setting.clone()))
106+
.layer(axum::Extension(record_config.clone()));
105107

106108
if let config::AIConfig::Stable { llm, tts, asr } = config.config {
107109
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();
@@ -116,13 +118,20 @@ async fn routes(
116118
});
117119

118120
router = router
119-
.route("/v1/stable_ws/{id}", any(services::ws::stable::ws_handler))
121+
.route("/ws/{id}", any(services::v2_mixed_handler))
122+
.route("/v2/stable_ws/{id}", any(services::ws::stable::ws_handler))
120123
.layer(axum::Extension(Arc::new(
121124
services::ws::stable::StableWsSetting {
122125
sessions: tx,
123126
hello_wav,
124127
},
125-
)));
128+
)))
129+
.layer(axum::Extension(record_config.clone()));
130+
} else {
131+
router = router
132+
.route("/ws/{id}", any(services::mixed_handler))
133+
.layer(axum::Extension(ws_setting.clone()))
134+
.layer(axum::Extension(record_config.clone()));
126135
}
127136

128137
if let Some(real_config) = real_config {

src/services/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,28 @@ pub async fn mixed_handler(
4343
.into_response()
4444
}
4545
}
46+
47+
pub async fn v2_mixed_handler(
48+
Extension(record_setting): Extension<Arc<ws_record::WsRecordSetting>>,
49+
Extension(pool): Extension<Arc<ws::stable::StableWsSetting>>,
50+
ws: WebSocketUpgrade,
51+
Path(id): Path<String>,
52+
Query(params): Query<ConnectQueryParams>,
53+
) -> Response {
54+
if params.record {
55+
ws_record::ws_handler(Extension(record_setting), ws, Path(id))
56+
.await
57+
.into_response()
58+
} else {
59+
ws::stable::ws_handler(
60+
Extension(pool),
61+
ws,
62+
Path(id),
63+
Query(ws::ConnectQueryParams {
64+
reconnect: params.reconnect,
65+
}),
66+
)
67+
.await
68+
.into_response()
69+
}
70+
}

0 commit comments

Comments
 (0)