<commit_before>function defaultOnerror(error) {
	if(error) console.error(error);
}

function noop(){};


function WebRtcPeer(mode, localVideo, remoteVideo, onsdpoffer, onerror, videoStream) {

	Object.defineProperty(this, 'pc', { writable: true});

	this.localVideo = localVideo;
	this.remoteVideo = remoteVideo;
	this.onerror = onerror || defaultOnerror;
	this.stream = videoStream;
	this.mode = mode;
	this.onsdpoffer = onsdpoffer || noop;
}

WebRtcPeer.prototype.start = function() {

	var self = this;

	if (!this.pc) {
		this.pc = new RTCPeerConnection(this.server, this.options);
	}

	var pc = this.pc;

	if (this.stream && this.localVideo) {
		this.localVideo.src = URL.createObjectURL(this.stream);
		this.localVideo.muted = true;
	}

	if (this.stream) {
		pc.addStream(this.stream);
	}

	this.constraints =  {
			mandatory: {
				OfferToReceiveAudio: (this.remoteVideo !== undefined),
				OfferToReceiveVideo: (this.remoteVideo !== undefined)
			}
	};

	pc.createOffer(function(offer) {
		console.log('Created SDP offer');
		pc.setLocalDescription(offer, function() {
			console.log('Local description set');
		}, self.onerror);

	}, this.onerror, this.constraints);

	pc.onicecandidate = function (e) {
		// candidate exists in e.candidate
		if (e.candidate) return;

		var offerSdp = pc.localDescription.sdp;
		console.log('ICE negotiation completed');

		self.onsdpoffer(offerSdp, self);
//		self.emit('sdpoffer', offerSdp);
	};

}

WebRtcPeer.prototype.dispose = function() {
	console.log('Disposing WebRtcPeer');
	//FIXME This is not yet implemented in firefox
	//if (this.stream) this.pc.removeStream(this.stream);
	this.pc.close();
	if(this.localVideo) this.localVideo.src = null;

	if(this.stream)
	{
		this.stream.getAudioTracks().forEach(function(track)
		{
			track.stop()
		})
		this.stream.getVideoTracks().forEach(function(track)
		{
			track.stop()
		})
	}
};

WebRtcPeer.prototype.userMediaConstraints = {
		audio : true,
		video : {
			mandatory: {
				maxWidth: 640,
				maxFrameRate : 15,
				minFrameRate: 15
			}<commit_msg>Setting empty string for video tag src field on dispose<commit_after>function defaultOnerror(error) {
	if(error) console.error(error);
}

function noop(){};


function WebRtcPeer(mode, localVideo, remoteVideo, onsdpoffer, onerror, videoStream) {

	Object.defineProperty(this, 'pc', { writable: true});

	this.localVideo = localVideo;
	this.remoteVideo = remoteVideo;
	this.onerror = onerror || defaultOnerror;
	this.stream = videoStream;
	this.mode = mode;
	this.onsdpoffer = onsdpoffer || noop;
}

WebRtcPeer.prototype.start = function() {

	var self = this;

	if (!this.pc) {
		this.pc = new RTCPeerConnection(this.server, this.options);
	}

	var pc = this.pc;

	if (this.stream && this.localVideo) {
		this.localVideo.src = URL.createObjectURL(this.stream);
		this.localVideo.muted = true;
	}

	if (this.stream) {
		pc.addStream(this.stream);
	}

	this.constraints =  {
			mandatory: {
				OfferToReceiveAudio: (this.remoteVideo !== undefined),
				OfferToReceiveVideo: (this.remoteVideo !== undefined)
			}
	};

	pc.createOffer(function(offer) {
		console.log('Created SDP offer');
		pc.setLocalDescription(offer, function() {
			console.log('Local description set');
		}, self.onerror);

	}, this.onerror, this.constraints);

	pc.onicecandidate = function (e) {
		// candidate exists in e.candidate
		if (e.candidate) return;

		var offerSdp = pc.localDescription.sdp;
		console.log('ICE negotiation completed');

		self.onsdpoffer(offerSdp, self);
//		self.emit('sdpoffer', offerSdp);
	};

}

WebRtcPeer.prototype.dispose = function() {
	console.log('Disposing WebRtcPeer');
	//FIXME This is not yet implemented in firefox
	//if (this.stream) this.pc.removeStream(this.stream);
	this.pc.close();
	if(this.localVideo) this.localVideo.src = '';

	if(this.stream)
	{
		this.stream.getAudioTracks().forEach(function(track)
		{
			track.stop()
		})
		this.stream.getVideoTracks().forEach(function(track)
		{
			track.stop()
		})
	}
};

WebRtcPeer.prototype.userMediaConstraints = {
		audio : true,
		video : {
			mandatory: {
				maxWidth: 640,
				maxFrameRate : 15,
				minFrameRate: 15
			}
{'fraction_non_alphanumeric': 0.14513018322082932, 'fraction_numerical': 0.0033751205400192863, 'mean_word_length': 4.109605911330049, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6371155', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1443, 'n_words': 268}