I want to create an data channel. But I'm having some difficulties to implement this. I have added the code that runs on the "caller side":
func initWebRTC() {
RTCInitializeSSL()
peerConnectionFactory = RTCPeerConnectionFactory()
let mandatoryConstraints = ["OfferToReceiveAudio": "true", "OfferToReceiveVideo": "false"]
let optionalConstraints = [ "DtlsSrtpKeyAgreement": "true", "RtpDataChannels" : "true"]
mediaConstraints = RTCMediaConstraints.init(mandatoryConstraints: mandatoryConstraints, optionalConstraints: optionalConstraints)
}
func prepareNewConnection() -> RTCPeerConnection {
var icsServers: [RTCIceServer] = []
icsServers.append(RTCIceServer(urlStrings: ["stun:stun.l.google.com:19302"], username:"",credential: ""))
let rtcConfig: RTCConfiguration = RTCConfiguration()
rtcConfig.tcpCandidatePolicy = RTCTcpCandidatePolicy.disabled
rtcConfig.bundlePolicy = RTCBundlePolicy.maxBundle
rtcConfig.rtcpMuxPolicy = RTCRtcpMuxPolicy.require
rtcConfig.iceServers = icsServers;
peerConnection = peerConnectionFactory.peerConnection(with: rtcConfig, constraints: mediaConstraints, delegate: self)
peerConnection.add(mediaStream);
let tt = RTCDataChannelConfiguration();
tt.isOrdered = false;
tt.isNegotiated = false
self.dataChannel = peerConnection.dataChannel(forLabel: "datachannel", configuration: tt)
self.dataChannel.delegate = self
print("create datachannel")
return peerConnection;
}
I create the data channel before the offer as said by many people. This method (see next code) is called several times. The channel state is going from 2 to 3.
public func dataChannelDidChangeState(_ dataChannel: RTCDataChannel){
print("channel.state \(dataChannel.readyState.rawValue)");
}
But what do I need to do at the receiving side? Because nothing happens there? Do I need to bind the data channel to the receiver side? If so, how can I do that?
--
---
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/49256f78-032b-4098-8626-186c7d4a82bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
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/ff11a4ce-069b-493b-ad3c-472cff79a98c%40googlegroups.com.
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/628bc7e6-f5c9-42af-aca1-5787f7287a3b%40googlegroups.com.
var pc_constraints = {"optional": [{RtpDataChannels: true}]}; var data_constraint = {reliable :false};
function doCall() { createDataChannel("caller"); pc.createOffer(setLocalAndSendMessage, failureCallback, null); };
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 = 65535;
// dataChannelConfiguration.isNegotiated = YES;
// connectionId : datachannel_+room+role
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;
}