websocket服务器支持在创建器中指定消息类型

通过该修改可以更灵活的指定同端口下不同websocket服务的消息类型
This commit is contained in:
xia-chu
2023-10-23 20:58:12 +08:00
parent ebde21a314
commit a871fc1882
2 changed files with 8 additions and 5 deletions

View File

@@ -81,9 +81,11 @@ public:
*/
struct EchoSessionCreator {
//返回的Session必须派生于SendInterceptor可以返回null(拒绝连接)
Session::Ptr operator()(const Parser &header, const HttpSession &parent, const Socket::Ptr &pSock) {
Session::Ptr operator()(const Parser &header, const HttpSession &parent, const Socket::Ptr &pSock, mediakit::WebSocketHeader::Type &type) {
// return nullptr;
if (header.url() == "/") {
// 可以指定传输方式
// type = mediakit::WebSocketHeader::BINARY;
return std::make_shared<SessionTypeImp<EchoSession> >(header, parent, pSock);
}
return std::make_shared<SessionTypeImp<EchoSessionWithUrl> >(header, parent, pSock);