<commit_before>var theVideoFileSize = 788493;


describe("Testing if manuallyAddingPeer methods", function(){
   var myStreaming = new OakStreaming();
   var myStreaming2 = new OakStreaming();
   var receivedCallbacks = 0;
   var peersAreConnected = false;
   var theTorrent;
   
   it("can establish a WebTorrent connection between two OakStreaming instances", function(done){
      expect(true).toBe(true); // every Jasmine it has to have an expect expression
            
      myStreaming.forTesting_connectedToNewWebTorrentPeer(function(){
         if(receivedCallbacks === 1){
            peersAreConnected = true;
            done();
         } else {
            receivedCallbacks++;
         }
      });
      myStreaming2.forTesting_connectedToNewWebTorrentPeer(function(){
         if(receivedCallbacks === 1){
            peersAreConnected = true;            
            done();
         } else {
            receivedCallbacks++;
         }
      });      
      myStreaming.createSignalingData(function(signalingData){
         myStreaming2.createSignalingDataResponse(signalingData, function(signalingDataResponse){
            myStreaming.processSignalingResponse(signalingDataResponse);
         });
      });
   });
   
   it("can successfully connect OakStreaming instances for streaming", function(done){
      expect(true).toBe(true); // every Jasmine it has to have an expect expression   
      
      function callback(streamInformationObject){
         myStreaming2.loadVideo(streamInformationObject, done, true);
      }
      
      function streamWhenConnectionEstablished(){
         if(peersAreConnected){
            testTorrent = myStreaming.streamVideo(res, {XHRPath : "/example.mp4"}, callback, 6257923579344);
         } else {
            setTimeout(streamWhenConnectionEstablished, 500);
         }
      }
      
      http.get({
         hostname: 'localhost',
         port: 8080,
         path: '/example.mp4',
         headers: {
            range: 'bytes=' + 0 + '-' + theVideoFileSize-1
         }
      }, function (res){
            streamWhenConnectionEstablished();
      });
   }, 30000);
   
   it("can establish a WebTorrent connection between two OakStreaming instances", function(done){
      
      
   },10000);
}   

function createSignalingData(callback){
   var myPeer = new SimplePeer({initiator: true, tickle: false});
   myPeer.on('signal', function (signalingData){
      signalingData.oakNumber = ++simplePeerCreationCounter;
      connectionsWaitingForSignalingData[simplePeerCreationCounter] = myPeer;
      callback(signalingData);
   });
}

function createSignalingDataResponse(signalingData, callback){
   var oakNumber;
   var myPeer = new SimplePeer({initiator: false, tickle: false});
   myPeer.on('signal', function (answerSignalingData){
      answerSignalingData.oaknumber = oakNumber;
      callback(answerSignalingData);
   });
   oakNumber = answerSignalingData.oakNumber;
   delete answerSignalingData.oakNumber;    
   myPeer.signal(signalingData);
   myPeer.on('connect', function(){
      addSimplePeerInstance(myPeer);
   });
}

function processSignalingResponse(signalingData){
   var oakNumber = signalingData.oakNumber;
   delete signalingData.oakNumber;
   myPeer.on('connect', function (){
      console.log('CONNECT');
      addSimplePeerInstance(myPeer);
      delete connectionsWaitingForSignalingData[oakNumber];    
   });
   myPeer.signal(signalingData);  
}



describe("Testing if streamVideo method", function(){
   var myStreaming = new OakStreaming();
      
   it("creates streamInformationObject correctly",  function(done){ 
      
      function callback (streamInformationObject){
         //console.log("callback from streamVideo is executed");
         //expect(streamInformationObject.magnetURI).toMatch("magnet:?xt=urn:btih:1b5169e27e943cd615b1e10ba98e9e4a0b2086b8&dn=example.mp4&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io");
         expect(streamInformationObject.videoFileSize).toEqual(theVideoFileSize);
         expect(streamInformationObject.XHRPath).toMatch("/example.mp4");
         //jasmine.clock().uninstall();
         done();
      }
      http.get({
         hostname: 'localhost',
         port: 8080,
         path: '/example.mp4',
         headers: {
            range: 'bytes=' + 0 + '-' + theVideoFileSize-1
         }
      }, function (res){
         testTorrent = myStreaming.streamVideo(res, {XHRPath : "/example.mp4"}, callback, 6257923579344);
      });
   }, 30000); 
});
<commit_msg>Wrote two more Jasmine specs for manuallyAddingPeer methods. These two test the methods with three instances instead of two.<commit_after>var theVideoFileSize = 788493;


describe("Testing if manuallyAddingPeer methods", function(){
   var myStreaming1 = new OakStreaming();
   var myStreaming2 = new OakStreaming();
   var myStreaming3 = new OakStreaming();
   
   var twoPeersAreConnected = false;
   var threePeersAreConnected = false;
   var theTorrent;
   
   it("can establish a WebTorrent connection between two OakStreaming instances", function(done){
      var receivedCallbacks = 0;
         
      expect(true).toBe(true); // every Jasmine it has to have an expect expression
            
      myStreaming1.forTesting_connectedToNewWebTorrentPeer(function(){
         if(receivedCallbacks === 1){
            twoPeersAreConnected = true;
            done();
         } else {
            receivedCallbacks++;
         }
      });
      myStreaming2.forTesting_connectedToNewWebTorrentPeer(function(){
         if(receivedCallbacks === 1){
            twoPeersAreConnected = true;            
            done();
         } else {
            receivedCallbacks++;
         }
      });      
      myStreaming1.createSignalingData(function(signalingData){
         myStreaming2.createSignalingDataResponse(signalingData, function(signalingDataResponse){
            myStreaming1.processSignalingResponse(signalingDataResponse);
         });
      });
   }, 5000);
   
   it("can successfully connect two OakStreaming instances for streaming", function(done){
      expect(true).toBe(true); // every Jasmine it has to have an expect expression   
      
      function callback(streamInformationObject){
         myStreaming2.loadVideo(streamInformationObject, done, true);
      }
      
      function streamWhenConnectionEstablished(){
         if(twoPeersAreConnected){
            testTorrent = myStreaming1.streamVideo(res, {}, callback, 6257923579344);
         } else {
            setTimeout(streamWhenConnectionEstablished, 500);
         }
      }
      
      http.get({
         hostname: 'localhost',
         port: 8080,
         path: '/example.mp4',
         headers: {
            range: 'bytes=' + 0 + '-' + theVideoFileSize-1
         }
      }, function (res){
            streamWhenConnectionEstablished();
      });
   }, 30000);
   
   it("can automatically establish a WebTorrent connections between three OakStreaming instances", function(done){
      expect(true).toBe(true); // every Jasmine it has to have an expect expression
      
      var receivedCallbacks = 0;
            
      myStreaming1.forTesting_connectedToNewWebTorrentPeer(function(){
         if(receivedCallbacks === 6){
            threePeersAreConnected = true;
            done();
         } else {
            receivedCallbacks++;
         }
      });
      myStreaming2.forTesting_connectedToNewWebTorrentPeer(function(){
         if(receivedCallbacks === 6){
            threePeersAreConnected = true;            
            done();
         } else {
            receivedCallbacks++;
         }
      });
      myStreaming3.forTesting_connectedToNewWebTorrentPeer(function(){
         if(receivedCallbacks === 6){
            threePeersAreConnected = true;            
            done();
         } else {
            receivedCallbacks++;
         }
      });      
      myStreaming2.createSignalingData(function(signalingData){
         myStreaming3.createSignalingDataResponse(signalingData, function(signalingDataResponse){
            myStreaming2.processSignalingResponse(signalingDataResponse);
         });
      });
      
   },20000);
   
   it("can successfully connect three OakStreaming instances for streaming", function(done){
      expect(true).toBe(true); // every Jasmine it has to have an expect expression   
      var oneStreamingCompleted = false;
      
      function callback(streamInformationObject){
         myStreaming1.loadVideo(streamInformationObject, function(){
            if(oneStreamingCompleted){
               done();
            } else {
               oneStreamingCompleted = true;
            }
         }, true);
         myStreaming2.loadVideo(streamInformationObject,  function(){
            if(oneStreamingCompleted){
               done();
            } else {
               oneStreamingCompleted = true;
            }
         }, true);
      }
      
      function streamWhenConnectionEstablished(res){
         if(threePeersAreConnected){
            myStreaming3.streamVideo(res, {}, callback, 6257923579344);
         } else {
         setTimeout(function (){streamWhenConnectionEstablished(res);}, 500);
         }
      }
      
      http.get({
         hostname: 'localhost',
         port: 8080,
         path: '/example.mp4',
         headers: {
            range: 'bytes=' + 0 + '-' + theVideoFileSize-1
         }
      }, function (res){
            streamWhenConnectionEstablished(res);
      });
   }, 30000);
}   



describe("Testing if streamVideo method", function(){
   var myStreaming = new OakStreaming();
      
   it("creates streamInformationObject correctly",  function(done){ 
      
      function callback (streamInformationObject){
         //console.log("callback from streamVideo is executed");
         //expect(streamInformationObject.magnetURI).toMatch("magnet:?xt=urn:btih:1b5169e27e943cd615b1e10ba98e9e4a0b2086b8&dn=example.mp4&tr=udp%3A%2F%2Fexodus.desync.com%3A6969&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com&tr=wss%3A%2F%2Ftracker.webtorrent.io");
         expect(streamInformationObject.videoFileSize).toEqual(theVideoFileSize);
         expect(streamInformationObject.XHRPath).toMatch("/example.mp4");
         //jasmine.clock().uninstall();
         done();
      }
      http.get({
         hostname: 'localhost',
         port: 8080,
         path: '/example.mp4',
         headers: {
            range: 'bytes=' + 0 + '-' + theVideoFileSize-1
         }
      }, function (res){
         testTorrent = myStreaming.streamVideo(res, {XHRPath : "/example.mp4"}, callback, 6257923579344);
      });
   }, 30000); 
});

{'fraction_non_alphanumeric': 0.10984713828652684, 'fraction_numerical': 0.031283327408460716, 'mean_word_length': 2.6834697217675942, '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': '4187054', 'n_tokens_mistral': 3462, 'n_tokens_neox': 3267, 'n_words': 536}