getSocketHost.js 284 B

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