getSocketHost.js 318 B

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