Commit ba38a958 by 修福龙

Merge remote-tracking branch 'origin/master'

parents e4b4948f 360778c1
android @ 24e88792
Subproject commit ea22824f4000883940b000f1e1854893e7463f1e
Subproject commit 24e88792277dde5f5560c1ae701ffbdcb9e47969
......@@ -10,6 +10,7 @@ import router from './router';
import models from './models';
import dva from './utils/dva';
import Restart from './utils/Restart';
import Installer from './utils/Installer';
import {counterInterval} from './utils/authInterval';
import {host} from './utils/config';
......@@ -88,6 +89,31 @@ class App extends React.Component {
dispatch({type: 'admin/version'});
});
}
if (!window.socket.hasListeners('installApp')) {
window.socket.on('installApp', ({url}) => {
if (!url) {
Toast.show('下载链接不能为空');
return;
}
const match = url.match(/http(s*):\/\/.+\/(.+)/);
if (!match) {
Toast.show('下载链接错误');
return;
}
const file = match[2];
Installer.download(url, file).then(apk => {
if (apk) {
Installer.install(apk);
}
});
});
}
if (!window.socket.hasListeners('uninstallApp')) {
window.socket.on('uninstallApp', ({pkg}) => {
// packageName eg: com.vsu.package
Installer.uninstall(pkg);
});
}
};
refresh = async () => {
......
import AsyncStorage from '@react-native-community/async-storage';
import axios from 'axios';
import * as api from '../services/admin';
import SocketIO from '../utils/socketio';
export default {
namespace: 'admin',
......@@ -21,11 +20,9 @@ export default {
};
} else {
// 使用原生SocketIO
window.socket.disconnect();
window.socket = new SocketIO(
`${axios.defaults.baseURL}/socket.io/?token=${window.auth.token}`,
);
window.socket.connect();
window.socket = window.socket.initialize({
query: `token=${window.auth.token}`,
});
}
}
AsyncStorage.setItem('auth', JSON.stringify(auth));
......
......@@ -272,7 +272,7 @@ class FacePage extends Component {
authinfo = async () => {
const rawdata = await WxFacepay.rawdata();
const {data} = await this.props.dispatch({
type: 'goods/wxauthinfo',
type: 'goods/faceinfo',
rawdata,
});
return data;
......@@ -286,13 +286,19 @@ class FacePage extends Component {
const tipText = '正在人脸识别,请看向屏幕,靠中间站稳';
Speech.speak(tipText);
this.setState({tip: tipText});
const auth = (await this.authinfo()) || {};
if (auth.return_code === 'SUCCESS') {
let auth = (await this.authinfo()) || {};
if (
auth.return_code === 'SUCCESS' ||
(auth.code === 1 && auth.data.bizCode === '0000')
) {
if (auth.data) {
auth = auth.data;
}
const params = {
appid: auth.appid,
mch_id: auth.mch_id,
appid: auth.appid || auth.subAppId,
mch_id: auth.mch_id || auth.subMchId,
store_id: this.storeKey,
authinfo: auth.authinfo,
authinfo: auth.authinfo || auth.authInfo,
face_authtype: 'FACEID-ONCE',
ask_unionid: 1,
};
......@@ -309,6 +315,9 @@ class FacePage extends Component {
if (!res.openid) {
return;
} // 没识别到人脸不开门
if (res.sub_openid) {
res.openid = res.sub_openid;
}
const ret = await this.props.dispatch({
type: 'store/wxdoor',
openid: res.openid,
......
import {NativeModules} from 'react-native';
export default NativeModules.Installer;
import {DeviceEventEmitter, NativeModules, Platform} from 'react-native';
import {debounce} from 'throttle-debounce';
let SocketIO = NativeModules.SocketIO;
......@@ -17,10 +16,7 @@ class Socket {
this.handlers = {};
this.onAnyHandler = null;
this.deviceEventSubscription = DeviceEventEmitter.addListener(
'socketEvent',
this._handleEvent.bind(this),
);
DeviceEventEmitter.addListener('socketEvent', this._handleEvent.bind(this));
// Set default handlers
this.defaultHandlers = {
......@@ -37,15 +33,11 @@ class Socket {
};
// Set initial configuration
this.host = host;
this.config = config;
this.sockets.initialize(host, config);
}
debounceHandler = debounce(1000, true, event => {
console.warn(event.name);
const res = event.hasOwnProperty('items') ? event.items[0] : {};
this.handlers[event.name](res);
});
_handleEvent(event) {
if (this.defaultHandlers.hasOwnProperty(event.name)) {
this.defaultHandlers[event.name](event);
......@@ -63,10 +55,27 @@ class Socket {
return this.handlers.hasOwnProperty(eventName);
}
initialize(config) {
config = {...this.config, ...config};
this.disconnect();
DeviceEventEmitter.removeAllListeners('socketEvent');
const socket = new Socket(this.host, config);
Object.keys(this.handlers).map(event => {
const handler = this.handlers[event];
socket.on(event, handler);
});
socket.connect();
return socket;
}
getId() {
return this.sockets.getId();
}
updateQuery(query) {
return this.sockets.updateQuery(query);
}
connect() {
this.sockets.connect();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment