open-im-sdk-wasm+3.8.0.patch 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. diff --git a/node_modules/open-im-sdk-wasm/lib/index.es.js b/node_modules/open-im-sdk-wasm/lib/index.es.js
  2. index 64c4047..3400689 100644
  3. --- a/node_modules/open-im-sdk-wasm/lib/index.es.js
  4. +++ b/node_modules/open-im-sdk-wasm/lib/index.es.js
  5. @@ -472,38 +472,32 @@ function supportsModuleWorkers() {
  6. }
  7. }
  8. function initWorker() {
  9. - if (typeof window === 'undefined') {
  10. - return;
  11. - }
  12. - // use for webpack 4
  13. - // const IMWorker = require('worker-loader!./worker.js');
  14. - // worker = new IMWorker.default();
  15. - // use for webpack5+ or vite
  16. - const isViteEnvironment = import.meta.url.includes('.vite/deps');
  17. - const isNuxtEnvironment = import.meta.url.includes('_nuxt/node_modules');
  18. - const isSupportModuleWorker = supportsModuleWorkers();
  19. - let workerUrl = isSupportModuleWorker
  20. - ? new URL('worker.js', import.meta.url)
  21. - : new URL('worker-legacy.js', import.meta.url);
  22. - if (isViteEnvironment) {
  23. - workerUrl = workerUrl.href.replace('.vite/deps', 'open-im-sdk-wasm/lib');
  24. - }
  25. - if (isNuxtEnvironment) {
  26. - workerUrl = workerUrl.href.replace('.cache/vite/client/deps', 'open-im-sdk-wasm/lib');
  27. - }
  28. - worker = new Worker(workerUrl, {
  29. - type: isSupportModuleWorker ? 'module' : 'classic',
  30. - });
  31. - // This is only required because Safari doesn't support nested
  32. - // workers. This installs a handler that will proxy creating web
  33. - // workers through the main thread
  34. - initBackend(worker);
  35. - rpc = new RPC({
  36. - event: new RPCMessageEvent({
  37. - currentEndpoint: worker,
  38. - targetEndpoint: worker,
  39. - }),
  40. - });
  41. + if (typeof window === 'undefined') {
  42. + return;
  43. + }
  44. + // use for webpack 4
  45. + const IMWorker = require('worker-loader!./worker.js');
  46. + worker = new IMWorker.default();
  47. + // use for webpack5+ or vite
  48. + // const isViteEnvironment = import.meta.url.includes('.vite/deps');
  49. + // const isSupportModuleWorker = supportsModuleWorkers();
  50. + // const getWorkerUrl = (url) => url.href.replace('.vite/deps', 'open-im-sdk-wasm/lib');
  51. + // const workerUrl = isSupportModuleWorker
  52. + // ? new URL('worker.js', import.meta.url)
  53. + // : new URL('worker-legacy.js', import.meta.url);
  54. + // worker = new Worker(isViteEnvironment ? getWorkerUrl(workerUrl) : workerUrl, {
  55. + // type: isSupportModuleWorker ? 'module' : 'classic',
  56. + // });
  57. + // This is only required because Safari doesn't support nested
  58. + // workers. This installs a handler that will proxy creating web
  59. + // workers through the main thread
  60. + initBackend(worker);
  61. + rpc = new RPC({
  62. + event: new RPCMessageEvent({
  63. + currentEndpoint: worker,
  64. + targetEndpoint: worker,
  65. + }),
  66. + });
  67. }
  68. function resetWorker() {
  69. if (rpc) {
  70. diff --git a/node_modules/open-im-sdk-wasm/lib/index.js b/node_modules/open-im-sdk-wasm/lib/index.js
  71. index cd572cc..e0e7ea5 100644
  72. --- a/node_modules/open-im-sdk-wasm/lib/index.js
  73. +++ b/node_modules/open-im-sdk-wasm/lib/index.js
  74. @@ -476,48 +476,32 @@ function supportsModuleWorkers() {
  75. }
  76. }
  77. function initWorker() {
  78. - if (typeof window === 'undefined') {
  79. - return;
  80. - }
  81. - // use for webpack 4
  82. - // const IMWorker = require('worker-loader!./worker.js');
  83. - // worker = new IMWorker.default();
  84. - // use for webpack5+ or vite
  85. - const isViteEnvironment = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.js', document.baseURI).href)).includes('.vite/deps');
  86. - const isNuxtEnvironment = (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.js', document.baseURI).href)).includes('_nuxt/node_modules');
  87. - const isSupportModuleWorker = supportsModuleWorkers();
  88. - let workerUrl = isSupportModuleWorker
  89. - ? new URL('worker.js', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.js', document.baseURI).href)))
  90. - : new URL('worker-legacy.js', (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.js', document.baseURI).href)));
  91. - if (isViteEnvironment) {
  92. - workerUrl = workerUrl.href.replace('.vite/deps', 'open-im-sdk-wasm/lib');
  93. - }
  94. - if (isNuxtEnvironment) {
  95. - workerUrl = workerUrl.href.replace('.cache/vite/client/deps', 'open-im-sdk-wasm/lib');
  96. - }
  97. - worker = new Worker(workerUrl, {
  98. - type: isSupportModuleWorker ? 'module' : 'classic',
  99. - });
  100. - // This is only required because Safari doesn't support nested
  101. - // workers. This installs a handler that will proxy creating web
  102. - // workers through the main thread
  103. - initBackend(worker);
  104. - rpc = new RPC({
  105. - event: new RPCMessageEvent({
  106. - currentEndpoint: worker,
  107. - targetEndpoint: worker,
  108. - }),
  109. - });
  110. -}
  111. -function resetWorker() {
  112. - if (rpc) {
  113. - rpc.destroy();
  114. - rpc = undefined;
  115. - }
  116. - if (worker) {
  117. - worker.terminate();
  118. - worker = undefined;
  119. - }
  120. + if (typeof window === 'undefined') {
  121. + return;
  122. + }
  123. + // use for webpack 4
  124. + const IMWorker = require('worker-loader!./worker.js');
  125. + worker = new IMWorker.default();
  126. + // use for webpack5+ or vite
  127. + // const isViteEnvironment = import.meta.url.includes('.vite/deps');
  128. + // const isSupportModuleWorker = supportsModuleWorkers();
  129. + // const getWorkerUrl = (url) => url.href.replace('.vite/deps', 'open-im-sdk-wasm/lib');
  130. + // const workerUrl = isSupportModuleWorker
  131. + // ? new URL('worker.js', import.meta.url)
  132. + // : new URL('worker-legacy.js', import.meta.url);
  133. + // worker = new Worker(isViteEnvironment ? getWorkerUrl(workerUrl) : workerUrl, {
  134. + // type: isSupportModuleWorker ? 'module' : 'classic',
  135. + // });
  136. + // This is only required because Safari doesn't support nested
  137. + // workers. This installs a handler that will proxy creating web
  138. + // workers through the main thread
  139. + initBackend(worker);
  140. + rpc = new RPC({
  141. + event: new RPCMessageEvent({
  142. + currentEndpoint: worker,
  143. + targetEndpoint: worker,
  144. + }),
  145. + });
  146. }
  147. initWorker();
  148. function catchErrorHandle(error) {