npmrun 4 years ago
parent
commit
353139b8c1
  1. 13
      package-lock.json
  2. 3
      package.json
  3. 31
      pages/index/index.vue
  4. 20
      pages/index/socket.js

13
package-lock.json

@ -375,6 +375,13 @@
"integrity": "sha1-KGlFnZqjviRf6P4sofRuLn9U1z8=", "integrity": "sha1-KGlFnZqjviRf6P4sofRuLn9U1z8=",
"requires": { "requires": {
"pako": "~1.0.5" "pako": "~1.0.5"
},
"dependencies": {
"pako": {
"version": "1.0.11",
"resolved": "https://registry.nlark.com/pako/download/pako-1.0.11.tgz?cache=0&sync_timestamp=1627560125189&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fpako%2Fdownload%2Fpako-1.0.11.tgz",
"integrity": "sha1-bJWZ00DVTf05RjgCUqNXBaa5kr8="
}
} }
}, },
"buffer": { "buffer": {
@ -2013,9 +2020,9 @@
"integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M=" "integrity": "sha1-y8ec26+P1CKOE/Yh8rGiN8GyB7M="
}, },
"pako": { "pako": {
"version": "1.0.11", "version": "2.0.4",
"resolved": "https://registry.nlark.com/pako/download/pako-1.0.11.tgz?cache=0&sync_timestamp=1627560125189&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fpako%2Fdownload%2Fpako-1.0.11.tgz", "resolved": "https://registry.nlark.com/pako/download/pako-2.0.4.tgz?cache=0&sync_timestamp=1627560125189&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fpako%2Fdownload%2Fpako-2.0.4.tgz",
"integrity": "sha1-bJWZ00DVTf05RjgCUqNXBaa5kr8=" "integrity": "sha1-bOvEu7C2xzsNW41+hHbisvvqV20="
}, },
"parse-asn1": { "parse-asn1": {
"version": "5.1.6", "version": "5.1.6",

3
package.json

@ -11,6 +11,7 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"hqchart": "^1.1.10351", "hqchart": "^1.1.10351",
"jquery": "^3.6.0" "jquery": "^3.6.0",
"pako": "^2.0.4"
} }
} }

31
pages/index/index.vue

@ -19,6 +19,14 @@
</template> </template>
<script> <script>
import pako from "pako"
function unzip(text) {
return pako.inflate(text, {
to: 'string'
});
}
export default { export default {
data() { data() {
@ -37,20 +45,33 @@
}); });
uni.onSocketOpen(function(res) { uni.onSocketOpen(function(res) {
console.log('WebSocket连接已打开!'); console.log('WebSocket连接已打开!');
//pako.gzip(JSON.stringify({ "req": "topic to req", "id": "id generate by client" }))
uni.sendSocketMessage({
data: JSON.stringify({
"req": "market.btcusdt.kline.1min",
"id": "id10"
})
});
}); });
uni.onSocketError(function(res) { uni.onSocketError(function(res) {
console.log('WebSocket连接打开失败,请检查!'); console.log('WebSocket连接打开失败,请检查!');
}); });
uni.onSocketMessage(function(res) { uni.onSocketMessage(function(res) {
console.log('收到服务器内容:' + res.data); let data = JSON.parse(unzip(res.data));
}); console.log(data);
uni.onSocketClose(function(res) { if(data.ping){
console.log('WebSocket 已关闭!'); //pako.gzip(JSON.stringify({"pong": data.ping}))
uni.sendSocketMessage({
data: JSON.stringify({"pong": data.ping})
});
}
}); });
}, },
beforeDestroy() { beforeDestroy() {
uni.closeSocket(); uni.closeSocket();
uni.onSocketClose(function(res) {
console.log('WebSocket 已关闭!');
});
}, },
onShow() { onShow() {
uni.getSystemInfo({ uni.getSystemInfo({

20
pages/index/socket.js

@ -0,0 +1,20 @@
import pako from "pako"
let bang = {};
bang.isConnect = false;
bang.checkSocket = function checkSocket(){
let time = 0;
function _send(success, fail){
uni.sendSocketMessage({
data: pako.gzip(JSON.stringify({"pong": data.ping})),
success() {
success&&success()
},
fail() {
fail&&fail()
}
});
}
_send()
}
Loading…
Cancel
Save