OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 } | 79 } |
80 | 80 |
81 - (const webrtc::DataBuffer *)nativeDataBuffer { | 81 - (const webrtc::DataBuffer *)nativeDataBuffer { |
82 return _dataBuffer.get(); | 82 return _dataBuffer.get(); |
83 } | 83 } |
84 | 84 |
85 @end | 85 @end |
86 | 86 |
87 | 87 |
88 @implementation RTCDataChannel { | 88 @implementation RTCDataChannel { |
89 rtc::scoped_refptr<webrtc::DataChannelInterface> _nativDataChannel; | 89 rtc::scoped_refptr<webrtc::DataChannelInterface> _nativeDataChannel; |
90 rtc::scoped_ptr<webrtc::DataChannelDelegateAdapter> _observer; | 90 rtc::scoped_ptr<webrtc::DataChannelDelegateAdapter> _observer; |
91 BOOL _isObserverRegistered; | 91 BOOL _isObserverRegistered; |
92 } | 92 } |
93 | 93 |
94 @synthesize delegate = _delegate; | 94 @synthesize delegate = _delegate; |
95 | 95 |
96 - (void)dealloc { | 96 - (void)dealloc { |
97 // Handles unregistering the observer properly. We need to do this because | 97 // Handles unregistering the observer properly. We need to do this because |
98 // there may still be other references to the underlying data channel. | 98 // there may still be other references to the underlying data channel. |
99 self.delegate = nil; | 99 self.delegate = nil; |
100 } | 100 } |
101 | 101 |
102 - (NSString *)label { | 102 - (NSString *)label { |
103 return [NSString stringForStdString:_nativDataChannel->label()]; | 103 return [NSString stringForStdString:_nativeDataChannel->label()]; |
| 104 } |
| 105 |
| 106 - (BOOL)isReliable { |
| 107 return _nativeDataChannel->reliable(); |
104 } | 108 } |
105 | 109 |
106 - (BOOL)isOrdered { | 110 - (BOOL)isOrdered { |
107 return _nativDataChannel->ordered(); | 111 return _nativeDataChannel->ordered(); |
| 112 } |
| 113 |
| 114 - (NSUInteger)maxRetransmitTime { |
| 115 return self.maxPacketLifeTime; |
108 } | 116 } |
109 | 117 |
110 - (uint16_t)maxPacketLifeTime { | 118 - (uint16_t)maxPacketLifeTime { |
111 return _nativDataChannel->maxRetransmitTime(); | 119 return _nativeDataChannel->maxRetransmitTime(); |
112 } | 120 } |
113 | 121 |
114 - (uint16_t)maxRetransmits { | 122 - (uint16_t)maxRetransmits { |
115 return _nativDataChannel->maxRetransmits(); | 123 return _nativeDataChannel->maxRetransmits(); |
116 } | 124 } |
117 | 125 |
118 - (NSString *)protocol { | 126 - (NSString *)protocol { |
119 return [NSString stringForStdString:_nativDataChannel->protocol()]; | 127 return [NSString stringForStdString:_nativeDataChannel->protocol()]; |
120 } | 128 } |
121 | 129 |
122 - (BOOL)isNegotiated { | 130 - (BOOL)isNegotiated { |
123 return _nativDataChannel->negotiated(); | 131 return _nativeDataChannel->negotiated(); |
| 132 } |
| 133 |
| 134 - (NSInteger)streamId { |
| 135 return self.channelId; |
124 } | 136 } |
125 | 137 |
126 - (int)channelId { | 138 - (int)channelId { |
127 return _nativDataChannel->id(); | 139 return _nativeDataChannel->id(); |
128 } | 140 } |
129 | 141 |
130 - (RTCDataChannelState)readyState { | 142 - (RTCDataChannelState)readyState { |
131 return [[self class] dataChannelStateForNativeState: | 143 return [[self class] dataChannelStateForNativeState: |
132 _nativDataChannel->state()]; | 144 _nativeDataChannel->state()]; |
133 } | 145 } |
134 | 146 |
135 - (uint64_t)bufferedAmount { | 147 - (uint64_t)bufferedAmount { |
136 return _nativDataChannel->buffered_amount(); | 148 return _nativeDataChannel->buffered_amount(); |
137 } | 149 } |
138 | 150 |
139 - (void)setDelegate:(id<RTCDataChannelDelegate>)delegate { | 151 - (void)setDelegate:(id<RTCDataChannelDelegate>)delegate { |
140 if (_delegate == delegate) { | 152 if (_delegate == delegate) { |
141 return; | 153 return; |
142 } | 154 } |
143 if (_isObserverRegistered) { | 155 if (_isObserverRegistered) { |
144 _nativDataChannel->UnregisterObserver(); | 156 _nativeDataChannel->UnregisterObserver(); |
145 _isObserverRegistered = NO; | 157 _isObserverRegistered = NO; |
146 } | 158 } |
147 _delegate = delegate; | 159 _delegate = delegate; |
148 if (_delegate) { | 160 if (_delegate) { |
149 _nativDataChannel->RegisterObserver(_observer.get()); | 161 _nativeDataChannel->RegisterObserver(_observer.get()); |
150 _isObserverRegistered = YES; | 162 _isObserverRegistered = YES; |
151 } | 163 } |
152 } | 164 } |
153 | 165 |
154 - (void)close { | 166 - (void)close { |
155 _nativDataChannel->Close(); | 167 _nativeDataChannel->Close(); |
156 } | 168 } |
157 | 169 |
158 - (BOOL)sendData:(RTCDataBuffer *)data { | 170 - (BOOL)sendData:(RTCDataBuffer *)data { |
159 return _nativDataChannel->Send(*data.nativeDataBuffer); | 171 return _nativeDataChannel->Send(*data.nativeDataBuffer); |
160 } | 172 } |
161 | 173 |
162 - (NSString *)description { | 174 - (NSString *)description { |
163 return [NSString stringWithFormat:@"RTCDataChannel:\n%ld\n%@\n%@", | 175 return [NSString stringWithFormat:@"RTCDataChannel:\n%ld\n%@\n%@", |
164 (long)self.channelId, | 176 (long)self.channelId, |
165 self.label, | 177 self.label, |
166 [[self class] | 178 [[self class] |
167 stringForState:self.readyState]]; | 179 stringForState:self.readyState]]; |
168 } | 180 } |
169 | 181 |
170 #pragma mark - Private | 182 #pragma mark - Private |
171 | 183 |
172 - (instancetype)initWithNativeDataChannel: | 184 - (instancetype)initWithNativeDataChannel: |
173 (rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel { | 185 (rtc::scoped_refptr<webrtc::DataChannelInterface>)nativeDataChannel { |
174 NSParameterAssert(nativeDataChannel); | 186 NSParameterAssert(nativeDataChannel); |
175 if (self = [super init]) { | 187 if (self = [super init]) { |
176 _nativDataChannel = nativeDataChannel; | 188 _nativeDataChannel = nativeDataChannel; |
177 _observer.reset(new webrtc::DataChannelDelegateAdapter(self)); | 189 _observer.reset(new webrtc::DataChannelDelegateAdapter(self)); |
178 } | 190 } |
179 return self; | 191 return self; |
180 } | 192 } |
181 | 193 |
182 + (webrtc::DataChannelInterface::DataState) | 194 + (webrtc::DataChannelInterface::DataState) |
183 nativeDataChannelStateForState:(RTCDataChannelState)state { | 195 nativeDataChannelStateForState:(RTCDataChannelState)state { |
184 switch (state) { | 196 switch (state) { |
185 case RTCDataChannelStateConnecting: | 197 case RTCDataChannelStateConnecting: |
186 return webrtc::DataChannelInterface::DataState::kConnecting; | 198 return webrtc::DataChannelInterface::DataState::kConnecting; |
(...skipping 27 matching lines...) Expand all Loading... |
214 case RTCDataChannelStateOpen: | 226 case RTCDataChannelStateOpen: |
215 return @"Open"; | 227 return @"Open"; |
216 case RTCDataChannelStateClosing: | 228 case RTCDataChannelStateClosing: |
217 return @"Closing"; | 229 return @"Closing"; |
218 case RTCDataChannelStateClosed: | 230 case RTCDataChannelStateClosed: |
219 return @"Closed"; | 231 return @"Closed"; |
220 } | 232 } |
221 } | 233 } |
222 | 234 |
223 @end | 235 @end |
OLD | NEW |