Skip to content

Commit

Permalink
fix: websocket api does not exist in current openharmony
Browse files Browse the repository at this point in the history
  • Loading branch information
flyfishzy committed Mar 5, 2022
1 parent 844f54e commit 3adab3a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
12 changes: 12 additions & 0 deletions packages/polyfill/extend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import './index.js';

/**
* polyfill for WebSocket
*/
import { WebSocket as _WebSocket } from './web/websocket';
if (!globalThis.WebSocket) {
globalThis.WebSocket = _WebSocket;
WebSocket = _WebSocket;
}

export { WebSocket } from './web/websocket';
1 change: 0 additions & 1 deletion packages/polyfill/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ export { TextDecoder, TextEncoder } from './web/encoding';
export { XMLHttpRequest } from './web/xhr';
export { fetch, Headers, Request, Response } from './web/fetch';
export { crypto } from './web/crypto';
export { WebSocket } from './web/websocket';
export { LocalStorage } from './web/storage';
export { navigator } from './web/navigator';
12 changes: 6 additions & 6 deletions packages/polyfill/node/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as harmonyFS from './fs';
import * as process from 'process/browser'
// import * as process from 'process/browser'

if (!globalThis.fs) {
globalThis.fs = harmonyFS;
}

if (!globalThis.process) {
globalThis.process = process;
globalThis.process = {};
}

if (!globalThis.process.versions) {
Expand All @@ -19,14 +19,14 @@ if (!globalThis.process.versions.node) {

globalThis['eval'] = function (functionBody) {
if (functionBody == 'require') {
return function protoRequire(moduleName){
return function protoRequire(moduleName) {
if (moduleName == 'fs') {
return harmonyFS;
}else{
return __webpack_require__(moduleName)
} else {
// eslint-disable-next-line
return __webpack_require__(moduleName);
}
};
}
return eval(functionBody);
};

5 changes: 2 additions & 3 deletions packages/polyfill/web/encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import util from '@ohos.util';
/**
* since: API 7
*/
const TextDecoder = util.TextDecoder;
const TextEncoder = util.TextEncoder;
const TextDecoder = util?.TextDecoder;
const TextEncoder = util?.TextEncoder;
export { TextDecoder, TextEncoder };

9 changes: 0 additions & 9 deletions packages/polyfill/web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ if (!globalThis.crypto) {
globalThis.crypto = crypto;
}

/**
* polyfill for WebSocket
*/
import { WebSocket as _WebSocket } from './websocket';
if (!globalThis.WebSocket) {
globalThis.WebSocket = _WebSocket;
WebSocket = _WebSocket;
}

/**
* polyfill for Canvas
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/polyfill/web/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import url from '@ohos.url';
/**
* since: API 7
*/
const URL = url.URL;
const URLSearchParams = url.URLSearchParams;
const URL = url?.URL;
const URLSearchParams = url?.URLSearchParams;
export { URL, URLSearchParams };

0 comments on commit 3adab3a

Please sign in to comment.