- (void)peerConnection:(RTCPeerConnection*)peerConnection
didOpenDataChannel:(RTCDataChannel*)dataChannel- (void)channelDidChangeState:(RTCDataChannel*)channel{
NSLog(@"did change state %d",channel.state);
}
if([_rtcChannel sendData:buffer]){
NSLog(@"send msg");//_rtcChannel was created before creating offer
}
didOpenDataChannel will be called?How to send message between peers using RTCDataChannel?--
---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrtc+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/feb9b325-1a77-49e5-aa3b-574d5d814215%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
var data_constraint = {reliable :false};
function createDataChannel(role) { try { sendDChannel = pc.createDataChannel("datachannel_"+room+role, data_constraint); } catch (e) { console.log('error creating data channel ' + e); return; } sendDChannel.onopen = onSendChannelStateChange; sendDChannel.onclose = onSendChannelStateChange; }
- (RTCConfiguration *)peerConnectionConfiguration
{
RTCConfiguration * configuration = [[RTCConfiguration alloc] init];
if (!mICEServers)
{
mICEServers = [NSMutableArray array];
NSArray * iceServers = @[RTCSTUNServerURL]; // RTCSTUNServerURL = @"stun:stun.l.google.com:19302";
[mICEServers addObject:[self defaultSTUNServer:iceServers]];
}
configuration.iceServers = mICEServers;
return configuration;
}
- (RTCMediaConstraints *)peerConnectionMediaConstraints
{
return [[RTCMediaConstraints alloc] initWithMandatoryConstraints:nil optionalConstraints:nil];
}
- (RTCPeerConnection *)createPeerConnectionWithDataChannelLabel:(NSString *)connectionId
{
RTCConfiguration * configuration = [self peerConnectionConfiguration];
RTCMediaConstraints * mediaConstraints = [self peerConnectionMediaConstraints];
RTCPeerConnection * peerConnection = [mPeerFactory peerConnectionWithConfiguration:configuration constraints:mediaConstraints delegate:self];
if (peerConnection)
{
NSLog(@"Create peer connection successfully for %@", connectionId);
RTCDataChannelConfiguration * dataChannelConfiguration = [[RTCDataChannelConfiguration alloc] init];
dataChannelConfiguration.channelId = 10000;
dataChannelConfiguration.isNegotiated = YES;
// connectionId keep the same with js <format : [NSString stringWithFormat:@"datachannel_%@caller", roomName]>
RTCDataChannel *dataChannel = [peerConnection dataChannelForLabel:connectionId configuration:dataChannelConfiguration];
if (dataChannel)
{
dataChannel.delegate = self;
NSLog(@"Data channel status : %@", [dataChannel readyStatus]);
}
else
{
NSLog(@"Create data channel failed for %@", connectionId);
}
}
else
{
NSLog(@"Create peer connection failed for %@", connectionId);
}
return peerConnection;
}
I've seen this kind of question a lot, so I created a question/answer on StackOverflow that tries to explain how the whole data channel negotiation model works: http://stackoverflow.com/questions/43788872/how-are-data-channels-negotiated-between-two-peers-in-webrtc/43788873Does this answer your questions?
On Wed, May 3, 2017 at 7:14 AM, <gaox...@foxmail.com> wrote:
I have already managed to share video and audio between peers however i can't find a way to send message between peers using RTCDataChannel. i guess the problem is that- (void)peerConnection:(RTCPeerConnection*)peerConnection
didOpenDataChannel:(RTCDataChannel*)dataChannel
is never called.what puzzled me is that RTCDataChannel state can changed to kRTCDataChannelStateOpenand sendData return Yes- (void)channelDidChangeState:(RTCDataChannel*)channel{
NSLog(@"did change state %d",channel.state);
}Questions:if([_rtcChannel sendData:buffer]){
NSLog(@"send msg");//_rtcChannel was created before creating offer
}
- When
didOpenDataChannel will be called?How to send message between peers usingRTCDataChannel?
--
---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
var data_constraint = {negotiated : true, id : 10000};
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/d599a3df-d1d9-4ffd-b37d-40818e63b1c2%40googlegroups.com.To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrtc+unsubscribe@googlegroups.com.
I've seen this kind of question a lot, so I created a question/answer on StackOverflow that tries to explain how the whole data channel negotiation model works: http://stackoverflow.com/questions/43788872/how-are-data-channels-negotiated-between-two-peers-in-webrtc/43788873Does this answer your questions?
On Wed, May 3, 2017 at 7:14 AM, <gaox...@foxmail.com> wrote:
I have already managed to share video and audio between peers however i can't find a way to send message between peers using RTCDataChannel. i guess the problem is that- (void)peerConnection:(RTCPeerConnection*)peerConnection
didOpenDataChannel:(RTCDataChannel*)dataChannel
is never called.what puzzled me is that RTCDataChannel state can changed to kRTCDataChannelStateOpenand sendData return Yes- (void)channelDidChangeState:(RTCDataChannel*)channel{
NSLog(@"did change state %d",channel.state);
}Questions:if([_rtcChannel sendData:buffer]){
NSLog(@"send msg");//_rtcChannel was created before creating offer
}
- When
didOpenDataChannel will be called?How to send message between peers usingRTCDataChannel?
--
---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.