| 130 | } |
| 131 | |
| 132 | int CChannelIce::SetDataChannel(std::shared_ptr<rtc::DataChannel> dc) |
| 133 | { |
| 134 | //qDebug(m_Log) << "onDataChannel: DataCannel label:" << dc->label().c_str(); |
| 135 | Q_ASSERT(dc); |
| 136 | if(!dc) return -1; |
| 137 | |
| 138 | m_dataChannel = dc; |
| 139 | |
| 140 | dc->onOpen([this]() { |
| 141 | qInfo(m_Log) << "Open data channel user:" << GetUser() |
| 142 | << ";peer:" << GetPeerUser() |
| 143 | << ";channelId:" << GetChannelId() |
| 144 | << ";label:" << m_dataChannel->label().c_str(); |
| 145 | if(QIODevice::open(QIODevice::ReadWrite)) |
| 146 | emit sigConnected(); |
| 147 | else |
| 148 | qInfo(m_Log) << "Open Device fail:user:" << GetUser() |
| 149 | << ";peer:" << GetPeerUser() |
| 150 | << ";channelId:" << GetChannelId() |
| 151 | << ";label:" << m_dataChannel->label().c_str(); |
| 152 | }); |
| 153 | |
| 154 | dc->onClosed([this]() { |
| 155 | qInfo(m_Log) << "Close data channel user:" << GetUser() |
| 156 | << ";peer:" << GetPeerUser() |
| 157 | << ";channelId:" << GetChannelId() |
| 158 | << ";label:" << m_dataChannel->label().c_str(); |
| 159 | emit sigDisconnected(); |
| 160 | }); |
| 161 | |
| 162 | dc->onError([this](std::string error){ |
| 163 | qInfo(m_Log) << "Data channel error:" << error.c_str(); |
| 164 | emit sigError(-1, error.c_str()); |
| 165 | }); |
| 166 | |
| 167 | dc->onMessage([dc, this](std::variant<rtc::binary, std::string> data) { |
| 168 | /* |
| 169 | if (std::holds_alternative<std::string>(data)) |
| 170 | qDebug(m_Log) << "From remote data:" |
| 171 | << std::get<std::string>(data).c_str(); |
| 172 | else |
| 173 | qDebug(m_Log) << "From remote Received, size=" |
| 174 | << std::get<rtc::binary>(data).size(); //*/ |
| 175 | m_MutexData.lock(); |
| 176 | rtc::binary d = std::get<rtc::binary>(data); |
| 177 | m_data.append((char*)d.data(), d.size()); |
| 178 | m_MutexData.unlock(); |
| 179 | emit this->readyRead(); |
| 180 | }); |
| 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | int CChannelIce::CreateDataChannel(bool bDataChannel) |
| 186 | { |