Skip to content

Commit 0c982cb

Browse files
feat: add socket.io client in miniprogram SDK (#7)
1 parent 41d2477 commit 0c982cb

File tree

12 files changed

+187
-58
lines changed

12 files changed

+187
-58
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ lib
1010
yarn-error.log
1111
package-lock.json
1212
.vscode
13+
.DS_Store

WeChat/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export function initialize(options: FPConfig): FeatureProbe | undefined {
4646

4747
/**
4848
* Get the SDK client
49-
*
5049
*/
5150
export function getClient() {
5251
return featureProbeClient;

WeChat/platform.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { IHttpRequest } from "featureprobe-client-sdk-js";
33
import { IPlatForm } from "./types";
44
import StorageProvider from "./localstorage";
55
import pkg from '../package.json';
6+
// eslint-disable-next-line @typescript-eslint/no-var-requires
7+
const io = require("weapp.socket.io");
68

79
const PKG_VERSION = pkg.version;
810
const UA = "MINIPROGRAM/" + PKG_VERSION;
@@ -56,4 +58,5 @@ export const platform: IPlatForm = {
5658
localStorage: new StorageProvider(),
5759
UA: UA,
5860
httpRequest: httpRequest,
61+
socket: io,
5962
};

WeChat/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,10 @@ export interface IPlatForm {
4040
*
4141
*/
4242
httpRequest: IHttpRequest;
43+
44+
/**
45+
* Socket.io client used in Wechat miniprogram
46+
*
47+
*/
48+
socket: any;
4349
}

example/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
miniprogram_npm/

example/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { initialize, FPUser } from "featureprobe-client-sdk-miniprogram";
2+
// import { initialize, FPUser } from "./dist/index";
23

34
App({
45
onLaunch() {

example/pages/index/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// index.js
22
import { getClient } from "featureprobe-client-sdk-miniprogram";
3+
// import { getClient } from "../../dist/index";
34

45
Page({
56
data: {},

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'weapp.socket.io';

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "featureprobe-client-sdk-miniprogram",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"main": "./dist/index.js",
55
"types": "./dist/index.d.ts",
66
"description": "FeatureProbe Client Side SDK for MiniProgram",
@@ -34,7 +34,6 @@
3434
"@rollup/plugin-commonjs": "^22.0.2",
3535
"@rollup/plugin-json": "^4.1.0",
3636
"@rollup/plugin-node-resolve": "^14.1.0",
37-
"@rollup/plugin-typescript": "^8.5.0",
3837
"@types/jest": "^27.0.1",
3938
"@typescript-eslint/eslint-plugin": "^5.38.0",
4039
"@typescript-eslint/parser": "^5.38.0",
@@ -44,19 +43,18 @@
4443
"prettier": "^2.7.1",
4544
"rollup": "^2.79.1",
4645
"rollup-plugin-babel-minify": "^10.0.0",
47-
"rollup-plugin-commonjs": "^10.1.0",
4846
"rollup-plugin-node-polyfills": "^0.2.1",
49-
"rollup-plugin-node-resolve": "^5.2.0",
5047
"rollup-plugin-replace": "^2.2.0",
5148
"rollup-plugin-typescript2": "^0.34.1",
5249
"ts-jest": "^27.0.5",
5350
"typedoc": "^0.23.16",
5451
"typescript": "^4.8.3"
5552
},
5653
"dependencies": {
57-
"featureprobe-client-sdk-js": "^1.2.0",
54+
"featureprobe-client-sdk-js": "^2.1.0",
5855
"js-base64": "^3.7.2",
5956
"tiny-emitter": "^2.1.0",
57+
"weapp.socket.io": "^3.0.0",
6058
"wefetch": "^1.3.6"
6159
}
6260
}

rollup.config.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import typescript from "rollup-plugin-typescript2";
22
import minify from "rollup-plugin-babel-minify";
3-
import resolve from "rollup-plugin-node-resolve";
4-
import commonjs from "rollup-plugin-commonjs";
3+
import resolve from "@rollup/plugin-node-resolve";
4+
import commonjs from "@rollup/plugin-commonjs";
55
import nodePolyfills from "rollup-plugin-node-polyfills";
66
import json from "@rollup/plugin-json";
77
import replace from 'rollup-plugin-replace';
@@ -14,8 +14,9 @@ export default {
1414
format: 'esm',
1515
},
1616
plugins: [
17-
nodePolyfills(),
18-
resolve({}),
17+
resolve({
18+
browser: true,
19+
}),
1920
commonjs({
2021
include: "node_modules/**",
2122
}),
@@ -24,6 +25,7 @@ export default {
2425
json(),
2526
replace({
2627
SDK_VERSION: pkg.version
27-
})
28+
}),
29+
nodePolyfills(),
2830
]
29-
};
31+
};

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"forceConsistentCasingInFileNames": true,
1313
"skipLibCheck": true
1414
},
15-
"include": ["WeChat/**/*"],
15+
"include": ["WeChat/**/*", "index.d.ts"],
1616
}

0 commit comments

Comments
 (0)