Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

index.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Module dependencies.
  3. */
  4. var url = require('./url');
  5. var parser = require('socket.io-parser');
  6. var Manager = require('./manager');
  7. var debug = require('debug')('socket.io-client');
  8. /**
  9. * Module exports.
  10. */
  11. module.exports = exports = lookup;
  12. /**
  13. * Managers cache.
  14. */
  15. var cache = exports.managers = {};
  16. /**
  17. * Looks up an existing `Manager` for multiplexing.
  18. * If the user summons:
  19. *
  20. * `io('http://localhost/a');`
  21. * `io('http://localhost/b');`
  22. *
  23. * We reuse the existing instance based on same scheme/port/host,
  24. * and we initialize sockets for each namespace.
  25. *
  26. * @api public
  27. */
  28. function lookup (uri, opts) {
  29. if (typeof uri === 'object') {
  30. opts = uri;
  31. uri = undefined;
  32. }
  33. opts = opts || {};
  34. var parsed = url(uri);
  35. var source = parsed.source;
  36. var id = parsed.id;
  37. var path = parsed.path;
  38. var sameNamespace = cache[id] && path in cache[id].nsps;
  39. var newConnection = opts.forceNew || opts['force new connection'] ||
  40. false === opts.multiplex || sameNamespace;
  41. var io;
  42. if (newConnection) {
  43. debug('ignoring socket cache for %s', source);
  44. io = Manager(source, opts);
  45. } else {
  46. if (!cache[id]) {
  47. debug('new io instance for %s', source);
  48. cache[id] = Manager(source, opts);
  49. }
  50. io = cache[id];
  51. }
  52. if (parsed.query && !opts.query) {
  53. opts.query = parsed.query;
  54. }
  55. return io.socket(parsed.path, opts);
  56. }
  57. /**
  58. * Protocol version.
  59. *
  60. * @api public
  61. */
  62. exports.protocol = parser.protocol;
  63. /**
  64. * `connect`.
  65. *
  66. * @param {String} uri
  67. * @api public
  68. */
  69. exports.connect = lookup;
  70. /**
  71. * Expose constructors for standalone build.
  72. *
  73. * @api public
  74. */
  75. exports.Manager = require('./manager');
  76. exports.Socket = require('./socket');