‘liusuyi’
2023-08-09 161b9318e345c8a0c9cdc133b33a1c759495f323
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
 
function getSocketClientPath(options) {
  let ClientImplementation;
  let clientImplFound = true;
  switch (typeof options.transportMode.client) {
    case 'string':
      // could be 'sockjs', 'ws', or a path that should be required
      if (options.transportMode.client === 'sockjs') {
        ClientImplementation = require('../../client/clients/SockJSClient');
      } else if (options.transportMode.client === 'ws') {
        ClientImplementation = require('../../client/clients/WebsocketClient');
      } else {
        try {
          // eslint-disable-next-line import/no-dynamic-require
          ClientImplementation = require(options.transportMode.client);
        } catch (e) {
          clientImplFound = false;
        }
      }
      break;
    default:
      clientImplFound = false;
  }
 
  if (!clientImplFound) {
    throw new Error(
      "transportMode.client must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to " +
        'a JS file which exports a class extending BaseClient (webpack-dev-server/client-src/clients/BaseClient) ' +
        'via require.resolve(...)'
    );
  }
 
  return ClientImplementation.getClientPath(options);
}
 
module.exports = getSocketClientPath;