mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 03:10:04 +08:00
确保attachServer会被触发
This commit is contained in:
parent
f53879cff1
commit
f98546a64c
@ -30,6 +30,7 @@
|
|||||||
#include "Common/config.h"
|
#include "Common/config.h"
|
||||||
#include "Rtsp/Rtsp.h"
|
#include "Rtsp/Rtsp.h"
|
||||||
#include "Network/TcpSession.h"
|
#include "Network/TcpSession.h"
|
||||||
|
#include "Network/TcpServer.h"
|
||||||
#include "Rtmp/RtmpMediaSource.h"
|
#include "Rtmp/RtmpMediaSource.h"
|
||||||
#include "Rtmp/FlvMuxer.h"
|
#include "Rtmp/FlvMuxer.h"
|
||||||
#include "HttpRequestSplitter.h"
|
#include "HttpRequestSplitter.h"
|
||||||
@ -152,6 +153,11 @@ public:
|
|||||||
_session->onManager();
|
_session->onManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void attachServer(const TcpServer &server) override{
|
||||||
|
HttpSession::attachServer(server);
|
||||||
|
_weakServer = const_cast<TcpServer &>(server).shared_from_this();
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* 开始收到一个webSocket数据包
|
* 开始收到一个webSocket数据包
|
||||||
@ -160,9 +166,19 @@ protected:
|
|||||||
void onWebSocketDecodeHeader(const WebSocketHeader &packet) override{
|
void onWebSocketDecodeHeader(const WebSocketHeader &packet) override{
|
||||||
//新包,原来的包残余数据清空掉
|
//新包,原来的包残余数据清空掉
|
||||||
_remian_data.clear();
|
_remian_data.clear();
|
||||||
if(_firstPacket){
|
|
||||||
|
if(!_firstPacket){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//这是个WebSocket会话而不是普通的Http会话
|
||||||
_firstPacket = false;
|
_firstPacket = false;
|
||||||
_session = std::make_shared<SessionImp>(nullptr,_sock);
|
_session = std::make_shared<SessionImp>(nullptr,_sock);
|
||||||
|
|
||||||
|
auto strongServer = _weakServer.lock();
|
||||||
|
if(strongServer){
|
||||||
|
_session->attachServer(*strongServer);
|
||||||
|
}
|
||||||
|
|
||||||
//此处截取数据并进行websocket协议打包
|
//此处截取数据并进行websocket协议打包
|
||||||
weak_ptr<WebSocketSession> weakSelf = dynamic_pointer_cast<WebSocketSession>(shared_from_this());
|
weak_ptr<WebSocketSession> weakSelf = dynamic_pointer_cast<WebSocketSession>(shared_from_this());
|
||||||
_session->setOnBeforeSendCB([weakSelf](const Buffer::Ptr &buf){
|
_session->setOnBeforeSendCB([weakSelf](const Buffer::Ptr &buf){
|
||||||
@ -175,7 +191,7 @@ protected:
|
|||||||
}
|
}
|
||||||
return buf->size();
|
return buf->size();
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -276,6 +292,7 @@ private:
|
|||||||
std::shared_ptr<SessionImp> _session;
|
std::shared_ptr<SessionImp> _session;
|
||||||
string _remian_data;
|
string _remian_data;
|
||||||
bool _firstPacket = true;
|
bool _firstPacket = true;
|
||||||
|
weak_ptr<TcpServer> _weakServer;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user