<commit_before>"use strict";

const wrtc_adapter = require("webrtc-adapter-test")
	, enums = {
		RESPONSE_NONE: Symbol("Miscellaneous Response"),
		RESPONSE_ICE: Symbol("ICE Candidate Response"),
		RESPONSE_SDP_ANSWER: Symbol("SDP Reply Response"),
		RESPONSE_SDP_OFFER: Symbol("SDP Offer Response"),

		MSG_SDP_ANSWER: Symbol("SDP Reply Message"),
		MSG_SDP_OFFER: Symbol("SDP Offer Message"),
		MSG_ICE: Symbol("ICE Candidate Message"),

		CHANNEL_BOUND: Symbol("Channel is bound to resource manager."),
		CHANNEL_CLOSED: Symbol("Channel is closed.")
	};

const defaultConfig = {
	channel: null,
	conn_ttl: 10000,
	rtc_facade: wrtc_adapter,
	rtc_config: { iceServers: [{urls: ["stun:stun.l.google.com:19302", "stun:stun.ekiga.net"] }] }
};

function WebRTCResourceManager(config){
	this._channelRegistry = {};
	this._connectionRegistry = {};

	let _lookupChannel = id => {
		// Takes a string id, and returns the channel matching that id.
		return this._channelRegistry[id];
	},
	_insertChannel = channel => {
		//Place a channel object into the registry based upon its internalID.
		this._channelRegistry[channel.internalID] = channel;
	},
	_newConnection = (id, channel, response) => {
		let conn = new this.config.rtc_facade.RTCPeerConnection(this.config.rtc_config),
			trConn = new TrackedConnection(id, conn);

		_insertConnection(id, trConn);

		conn.onicecandidate = function(evt) {
			if(evt.candidate)
				channel.send(id, enums.MSG_ICE, evt.candidate);
		}

		conn.ondatachannel = function(evt){
			console.log("Received Channel from other partner.")
			trConn.registerDataChannel(evt.channel);
		}

		conn.oniceconnectionstatechange = function(evt) {
			switch(this.iceConnectionState){
				case "closed":
					if (trConn.onclose)
						trConn.onclose(evt);
				case "failed":
				case "disconnected":
					if (trConn.ondisconnect)
						trConn.ondisconnect(evt);
					delete this._connectionRegistry[trConn.id];
					break;
			}		
		}
<commit_msg>Fixing usage of "this"<commit_after>"use strict";

const wrtc_adapter = require("webrtc-adapter-test")
	, enums = {
		RESPONSE_NONE: Symbol("Miscellaneous Response"),
		RESPONSE_ICE: Symbol("ICE Candidate Response"),
		RESPONSE_SDP_ANSWER: Symbol("SDP Reply Response"),
		RESPONSE_SDP_OFFER: Symbol("SDP Offer Response"),

		MSG_SDP_ANSWER: Symbol("SDP Reply Message"),
		MSG_SDP_OFFER: Symbol("SDP Offer Message"),
		MSG_ICE: Symbol("ICE Candidate Message"),

		CHANNEL_BOUND: Symbol("Channel is bound to resource manager."),
		CHANNEL_CLOSED: Symbol("Channel is closed.")
	};

const defaultConfig = {
	channel: null,
	conn_ttl: 10000,
	rtc_facade: wrtc_adapter,
	rtc_config: { iceServers: [{urls: ["stun:stun.l.google.com:19302", "stun:stun.ekiga.net"] }] }
};

function WebRTCResourceManager(config){
	this._channelRegistry = {};
	this._connectionRegistry = {};

	let _lookupChannel = id => {
		// Takes a string id, and returns the channel matching that id.
		return this._channelRegistry[id];
	},
	_insertChannel = channel => {
		//Place a channel object into the registry based upon its internalID.
		this._channelRegistry[channel.internalID] = channel;
	},
	_newConnection = (id, channel, response) => {
		let conn = new this.config.rtc_facade.RTCPeerConnection(this.config.rtc_config),
			trConn = new TrackedConnection(id, conn),
			t = this;

		_insertConnection(id, trConn);

		conn.onicecandidate = function(evt) {
			if(evt.candidate)
				channel.send(id, enums.MSG_ICE, evt.candidate);
		}

		conn.ondatachannel = function(evt){
			console.log("Received Channel from other partner.")
			trConn.registerDataChannel(evt.channel);
		}

		conn.oniceconnectionstatechange = function(evt) {
			switch(this.iceConnectionState){
				case "closed":
					if (trConn.onclose)
						trConn.onclose(evt);
				case "failed":
				case "disconnected":
					if (trConn.ondisconnect)
						trConn.ondisconnect(evt);
					delete t._connectionRegistry[trConn.id];
					break;
			}		
		}

{'fraction_non_alphanumeric': 0.12731422774537154, 'fraction_numerical': 0.00507227998985544, 'mean_word_length': 4.5083798882681565, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 9, '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': '3056686', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1328, 'n_words': 281}