PassRefPtr<RTCDataChannel> RTCPeerConnection::createDataChannel(String label, const Dictionary& options, ExceptionState& exceptionState) { if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) return nullptr; blink::WebRTCDataChannelInit init; options.get("ordered", init.ordered); options.get("negotiated", init.negotiated); unsigned short value = 0; if (options.get("id", value)) init.id = value; if (options.get("maxRetransmits", value)) init.maxRetransmits = value; if (options.get("maxRetransmitTime", value)) init.maxRetransmitTime = value; String protocolString; options.get("protocol", protocolString); init.protocol = protocolString; RefPtr<RTCDataChannel> channel = RTCDataChannel::create(executionContext(), m_peerHandler.get(), label, init, exceptionState); if (exceptionState.hadException()) return nullptr; m_dataChannels.append(channel); return channel.release(); }
void RTCPeerConnection::close(ExceptionState& exceptionState) { if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) return; m_peerHandler->stop(); changeIceConnectionState(ICEConnectionStateClosed); changeIceGatheringState(ICEGatheringStateComplete); changeSignalingState(SignalingStateClosed); }
void RTCPeerConnection::setRemoteDescription(RTCSessionDescription* sessionDescription, PassOwnPtr<VoidCallback> successCallback, PassOwnPtr<RTCErrorCallback> errorCallback, ExceptionState& exceptionState) { if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) return; if (!sessionDescription) { exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::argumentNullOrIncorrectType(1, "RTCSessionDescription")); return; } RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext(), this, successCallback, errorCallback); m_peerHandler->setRemoteDescription(request.release(), sessionDescription->webSessionDescription()); }
void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, ExceptionState& exceptionState) { if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) return; if (!iceCandidate) { exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::argumentNullOrIncorrectType(1, "RTCIceCandidate")); return; } bool valid = m_peerHandler->addICECandidate(iceCandidate->webCandidate()); if (!valid) exceptionState.throwDOMException(SyntaxError, "The ICE candidate could not be added."); }
void RTCPeerConnection::createAnswer(PassOwnPtr<RTCSessionDescriptionCallback> successCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& mediaConstraints, ExceptionState& exceptionState) { if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) return; ASSERT(successCallback); blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstraints, exceptionState); if (exceptionState.hadException()) return; RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestImpl::create(executionContext(), successCallback, errorCallback); m_peerHandler->createAnswer(request.release(), constraints); }
void RTCPeerConnection::updateIce(const Dictionary& rtcConfiguration, const Dictionary& mediaConstraints, ExceptionState& exceptionState) { if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) return; RefPtr<RTCConfiguration> configuration = parseConfiguration(rtcConfiguration, exceptionState); if (exceptionState.hadException()) return; blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstraints, exceptionState); if (exceptionState.hadException()) return; bool valid = m_peerHandler->updateICE(configuration.release(), constraints); if (!valid) exceptionState.throwDOMException(SyntaxError, "Could not update the ICE Agent with the given configuration."); }
void RTCPeerConnection::createAnswer(PassOwnPtr<RTCSessionDescriptionCallback> successCallback, PassOwnPtr<RTCErrorCallback> errorCallback, const Dictionary& mediaConstraints, ExceptionState& exceptionState) { if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) return; if (!successCallback) { exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::argumentNullOrIncorrectType(1, "RTCSessionDescriptionCallback")); return; } blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstraints, exceptionState); if (exceptionState.hadException()) return; RefPtr<RTCSessionDescriptionRequest> request = RTCSessionDescriptionRequestImpl::create(executionContext(), successCallback, errorCallback); m_peerHandler->createAnswer(request.release(), constraints); }
void RTCPeerConnection::addIceCandidate(RTCIceCandidate* iceCandidate, PassOwnPtr<VoidCallback> successCallback, PassOwnPtr<RTCErrorCallback> errorCallback, ExceptionState& exceptionState) { if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) return; if (!iceCandidate) { exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::argumentNullOrIncorrectType(1, "RTCIceCandidate")); return; } ASSERT(successCallback); ASSERT(errorCallback); RefPtr<RTCVoidRequest> request = RTCVoidRequestImpl::create(executionContext(), successCallback, errorCallback); bool implemented = m_peerHandler->addICECandidate(request.release(), iceCandidate->webCandidate()); if (!implemented) exceptionState.throwDOMException(NotSupportedError, "This method is not yet implemented."); }
void RTCPeerConnection::removeStream(MediaStream* stream, ExceptionState& exceptionState) { if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) return; if (!stream) { exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::argumentNullOrIncorrectType(1, "MediaStream")); return; } size_t pos = m_localStreams.find(stream); if (pos == kNotFound) return; m_localStreams.remove(pos); m_peerHandler->removeStream(stream->descriptor()); }
RTCDTMFSender* RTCPeerConnection::createDTMFSender(MediaStreamTrack* track, ExceptionState& exceptionState) { if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) return nullptr; if (!track) { exceptionState.throwTypeError(ExceptionMessages::argumentNullOrIncorrectType(1, "MediaStreamTrack")); return nullptr; } if (!hasLocalStreamWithTrackId(track->id())) { exceptionState.throwDOMException(SyntaxError, "No local stream is available for the track provided."); return nullptr; } RTCDTMFSender* dtmfSender = RTCDTMFSender::create(executionContext(), m_peerHandler.get(), track, exceptionState); if (exceptionState.hadException()) return nullptr; return dtmfSender; }
void RTCPeerConnection::addStream(MediaStream* stream, const Dictionary& mediaConstraints, ExceptionState& exceptionState) { if (throwExceptionIfSignalingStateClosed(m_signalingState, exceptionState)) return; if (!stream) { exceptionState.throwDOMException(TypeMismatchError, ExceptionMessages::argumentNullOrIncorrectType(1, "MediaStream")); return; } if (m_localStreams.contains(stream)) return; blink::WebMediaConstraints constraints = MediaConstraintsImpl::create(mediaConstraints, exceptionState); if (exceptionState.hadException()) return; m_localStreams.append(stream); bool valid = m_peerHandler->addStream(stream->descriptor(), constraints); if (!valid) exceptionState.throwDOMException(SyntaxError, "Unable to add the provided stream."); }