|
|
@@ -89,6 +89,9 @@ var heartConfig = { |
|
|
|
pageChangeInterval:10, |
|
|
|
} |
|
|
|
|
|
|
|
var requestFailedCount = 0; |
|
|
|
var versionInfo = ''; |
|
|
|
|
|
|
|
export default class MyPage extends Component { |
|
|
|
constructor(props) { |
|
|
|
super(props); |
|
|
@@ -122,8 +125,10 @@ codePushUpdate() { |
|
|
|
CodePush.getUpdateMetadata(CodePush.UpdateState.RUNNING) |
|
|
|
.then((metadata: LocalPackage) => { |
|
|
|
this.setState({ versionInfo: metadata ? metadata.appVersion +'b'+NativeModules.BuildConfig.versionCode+"-" + metadata.label : "Unknown"}); |
|
|
|
versionInfo = this.state.versionInfo; |
|
|
|
}, (error: any) => { |
|
|
|
this.setState({ versionInfo: "Unknown"}); |
|
|
|
versionInfo = this.state.versionInfo; |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
@@ -186,9 +191,10 @@ codePushStatusDidChange(syncStatus) { |
|
|
|
} |
|
|
|
|
|
|
|
hbRequest() { |
|
|
|
return HttpUtils.post(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/heartbeat?deviceId=' |
|
|
|
+encodeURIComponent(this.state.macAddress), |
|
|
|
{version:this.state.versionInfo}) |
|
|
|
return HttpUtils.post(NativeModules.BuildConfig.apiHost |
|
|
|
+ 'api/wxDeviceScreenAd/heartbeat?deviceId=' |
|
|
|
+ encodeURIComponent(this.state.macAddress), |
|
|
|
{version:this.state.versionInfo}) |
|
|
|
.then(result => { |
|
|
|
if (result.code == 200) { |
|
|
|
let config = JSON.parse(result.data.config); |
|
|
@@ -223,7 +229,8 @@ codePushStatusDidChange(syncStatus) { |
|
|
|
|
|
|
|
}) |
|
|
|
.catch(error => { |
|
|
|
this.setState({ errorMessage : error.message}); |
|
|
|
requestFailedCount++ |
|
|
|
this.setState({ versionInfo: versionInfo+`[${requestFailedCount}]`}); |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
@@ -232,9 +239,12 @@ codePushStatusDidChange(syncStatus) { |
|
|
|
this.setState({errorMessage : errMsg}); |
|
|
|
} |
|
|
|
|
|
|
|
getAdDataList() { |
|
|
|
return HttpUtils.get(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/list?deviceId='+encodeURIComponent(this.state.macAddress)+'&pageNum=1&pageSize=1000') |
|
|
|
.then((result) => { |
|
|
|
getAdDataList(first) { |
|
|
|
HttpUtils.get(NativeModules.BuildConfig.apiHost |
|
|
|
+ 'api/wxDeviceScreenAd/list?deviceId=' |
|
|
|
+ encodeURIComponent(this.state.macAddress) |
|
|
|
+ '&pageNum=1&pageSize=1000') |
|
|
|
.then(result => { |
|
|
|
if (result.code != 200) { |
|
|
|
this.showErrMsg(result.message+'\n'+this.state.macAddress); |
|
|
|
} else if (result.data.list) { |
|
|
@@ -249,11 +259,19 @@ codePushStatusDidChange(syncStatus) { |
|
|
|
} |
|
|
|
}) |
|
|
|
.catch(error => { |
|
|
|
this.showErrMsg(error.message); |
|
|
|
if (first) { |
|
|
|
this.showErrMsg(error.message); |
|
|
|
} |
|
|
|
else { |
|
|
|
requestFailedCount++ |
|
|
|
this.setState({ versionInfo: versionInfo+`[${requestFailedCount}]`}); |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
getBaseInfo() { |
|
|
|
return HttpUtils.get(NativeModules.BuildConfig.apiHost + 'api/wxDeviceScreenAd/info?deviceId='+encodeURIComponent(this.state.macAddress)) |
|
|
|
HttpUtils.get(NativeModules.BuildConfig.apiHost |
|
|
|
+ 'api/wxDeviceScreenAd/info?deviceId=' |
|
|
|
+ encodeURIComponent(this.state.macAddress)) |
|
|
|
.then(result => { |
|
|
|
if (result.code != 200) { |
|
|
|
this.showErrMsg(result.message+'\n'+this.state.macAddress); |
|
|
@@ -296,7 +314,7 @@ async routine() { |
|
|
|
|
|
|
|
try { |
|
|
|
if (getAdDataCount<=0) { |
|
|
|
await this.getAdDataList() |
|
|
|
await this.getAdDataList(false) |
|
|
|
getAdDataCount = heartConfig.dataRefreshInterval |
|
|
|
} else if (hbRequestCount<=0) { |
|
|
|
await this.hbRequest() |
|
|
@@ -311,12 +329,12 @@ async routine() { |
|
|
|
} |
|
|
|
} else { |
|
|
|
await this.getBaseInfo() |
|
|
|
await this.getAdDataList() |
|
|
|
await this.getAdDataList(true) |
|
|
|
} |
|
|
|
pageChangeCount = heartConfig.pageChangeInterval |
|
|
|
} |
|
|
|
} catch(e){ |
|
|
|
this.setState({ versionInfo: this.state.versionInfo+'[E]'}); |
|
|
|
this.setState({ versionInfo: versionInfo+'[E]'}); |
|
|
|
} |
|
|
|
|
|
|
|
setTimeout(()=>{ |
|
|
@@ -326,7 +344,7 @@ async routine() { |
|
|
|
|
|
|
|
async startAd() { |
|
|
|
await this.getBaseInfo() |
|
|
|
await this.getAdDataList() |
|
|
|
await this.getAdDataList(true) |
|
|
|
await this.hbRequest() |
|
|
|
|
|
|
|
hbRequestCount = heartConfig.heartbeatInterval; |
|
|
|