11 lines
		
	
	
		
			318 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			11 lines
		
	
	
		
			318 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
"use strict";
 | 
						|
 | 
						|
function getSocketHost(url) {
 | 
						|
  // get the host domain
 | 
						|
  const regex = /^(?:https?:\/\/|\/\/)?(?:[^@\n]+@)?(?:www\.)?([^\n]+)/i;
 | 
						|
  const host = regex.exec(url)[1];
 | 
						|
  const socketProtocol = /^http:\/\//i.test(url) ? 'ws' : 'wss';
 | 
						|
  return `${socketProtocol}://${host}`;
 | 
						|
}
 | 
						|
 | 
						|
module.exports = getSocketHost; |