UNPKG

280 BJavaScriptView Raw
1module.exports = function getSocketHost (url) {
2 // get the host domain
3 var regex = /^(?:https?:\/\/|\/\/)?(?:[^@\n]+@)?(?:www\.)?([^\n]+)/i
4 var host = regex.exec(url)[1]
5 var socketProtocol = /^http:\/\//i.test(url) ? 'ws' : 'wss'
6
7 return `${socketProtocol}://${host}`
8}