Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef PC_COMPOSITE_DATA_CHANNEL_TRANSPORT_H_ |
| 12 | #define PC_COMPOSITE_DATA_CHANNEL_TRANSPORT_H_ |
| 13 | |
| 14 | #include <vector> |
| 15 | |
Niels Möller | bfcec4c | 2019-09-25 10:00:34 +0200 | [diff] [blame] | 16 | #include "api/transport/data_channel_transport_interface.h" |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 17 | #include "rtc_base/critical_section.h" |
| 18 | |
| 19 | namespace webrtc { |
| 20 | |
| 21 | // Composite implementation of DataChannelTransportInterface. Allows users to |
| 22 | // receive data channel messages over multiple transports and send over one of |
| 23 | // those transports. |
| 24 | class CompositeDataChannelTransport : public DataChannelTransportInterface, |
| 25 | public DataChannelSink { |
| 26 | public: |
| 27 | explicit CompositeDataChannelTransport( |
| 28 | std::vector<DataChannelTransportInterface*> transports); |
Bjorn A Mellem | fc604aa | 2019-09-24 14:59:21 -0700 | [diff] [blame] | 29 | ~CompositeDataChannelTransport() override; |
Bjorn A Mellem | bc3eebc | 2019-09-23 14:53:54 -0700 | [diff] [blame] | 30 | |
| 31 | // Specifies which transport to be used for sending. Must be called before |
| 32 | // sending data. |
| 33 | void SetSendTransport(DataChannelTransportInterface* send_transport); |
| 34 | |
| 35 | // Removes a given transport from the composite, if present. |
| 36 | void RemoveTransport(DataChannelTransportInterface* transport); |
| 37 | |
| 38 | // DataChannelTransportInterface overrides. |
| 39 | RTCError OpenChannel(int channel_id) override; |
| 40 | RTCError SendData(int channel_id, |
| 41 | const SendDataParams& params, |
| 42 | const rtc::CopyOnWriteBuffer& buffer) override; |
| 43 | RTCError CloseChannel(int channel_id) override; |
| 44 | void SetDataSink(DataChannelSink* sink) override; |
| 45 | bool IsReadyToSend() const override; |
| 46 | |
| 47 | // DataChannelSink overrides. |
| 48 | void OnDataReceived(int channel_id, |
| 49 | DataMessageType type, |
| 50 | const rtc::CopyOnWriteBuffer& buffer) override; |
| 51 | void OnChannelClosing(int channel_id) override; |
| 52 | void OnChannelClosed(int channel_id) override; |
| 53 | void OnReadyToSend() override; |
| 54 | |
| 55 | private: |
| 56 | std::vector<DataChannelTransportInterface*> transports_; |
| 57 | DataChannelTransportInterface* send_transport_ = nullptr; |
| 58 | DataChannelSink* sink_ = nullptr; |
| 59 | }; |
| 60 | |
| 61 | } // namespace webrtc |
| 62 | |
| 63 | #endif // PC_COMPOSITE_DATA_CHANNEL_TRANSPORT_H_ |