示例#1
0
void PeerConnection::HandleNewDataChannel(ChunkPtr chunk, uint16_t sid) {
  uint8_t *raw_msg = chunk->Data();
  dc_open_msg open_msg;
  open_msg.chan_type = raw_msg[1];
  open_msg.priority = (raw_msg[2] << 8) + raw_msg[3];
  open_msg.reliability = (raw_msg[4] << 24) + (raw_msg[5] << 16) + (raw_msg[6] << 8) + raw_msg[7];
  open_msg.label_len = (raw_msg[8] << 8) + raw_msg[9];
  open_msg.protocol_len = (raw_msg[10] << 8) + raw_msg[11];

  std::string label(reinterpret_cast<char *>(raw_msg + 12), open_msg.label_len);
  std::string protocol(reinterpret_cast<char *>(raw_msg + 12 + open_msg.label_len), open_msg.protocol_len);

  SPDLOG_DEBUG(logger, "Creating channel with sid: {}, chan_type: {}, label: {}, protocol: {}", sid, open_msg.chan_type, label, protocol);

  // TODO: Support overriding an existing channel
  auto new_channel = std::make_shared<DataChannel>(this, sid, open_msg.chan_type, label, protocol);

  data_channels[sid] = new_channel;

  if (this->new_channel_cb) {
    this->new_channel_cb(new_channel);
  } else {
    logger->warn("No new channel callback, ignoring new channel");
  }
}
示例#2
0
void PeerConnection::HandleStringMessage(ChunkPtr chunk, uint16_t sid) {
  auto cur_channel = GetChannel(sid);
  if (!cur_channel) {
    logger->warn("Received msg on unknown channel: {}", sid);
    return;
  }

  std::string cur_msg(reinterpret_cast<char *>(chunk->Data()), chunk->Length());

  cur_channel->OnStringMsg(cur_msg);
}
示例#3
0
// Matches DataChannel onmessage
void PeerConnection::OnSCTPMsgReceived(ChunkPtr chunk, uint16_t sid, uint32_t ppid) {
  SPDLOG_TRACE(logger, "OnSCTPMsgReceived(): Handling an sctp message");
  if (ppid == PPID_CONTROL) {
    SPDLOG_TRACE(logger, "Control PPID");
    if (chunk->Data()[0] == DC_TYPE_OPEN) {
      SPDLOG_TRACE(logger, "New channel time!");
      HandleNewDataChannel(chunk, sid);
    } else if (chunk->Data()[0] == DC_TYPE_ACK) {
      SPDLOG_TRACE(logger, "DC ACK");
      // HandleDataChannelAck(chunk, sid); XXX: Don't care right now
    } else {
      SPDLOG_TRACE(logger, "Unknown msg_type for ppid control: {}", chunk->Data()[0]);
    }
  } else if ((ppid == PPID_STRING) || (ppid == PPID_STRING_EMPTY)) {
    SPDLOG_TRACE(logger, "String msg");
    HandleStringMessage(chunk, sid);
  } else if ((ppid == PPID_BINARY) || (ppid == PPID_BINARY_EMPTY)) {
    SPDLOG_TRACE(logger, "Binary msg");
    HandleBinaryMessage(chunk, sid);
  } else {
    logger->error("Unknown ppid={}", ppid);
  }
}