scanner: Global session id
This commit is contained in:
parent
0593c1f8a5
commit
6d4f831003
@ -1,4 +1,8 @@
|
|||||||
// app.js
|
// app.js
|
||||||
|
import {
|
||||||
|
make_new_session_id,
|
||||||
|
} from './utils.js';
|
||||||
|
|
||||||
App({
|
App({
|
||||||
onLaunch() {
|
onLaunch() {
|
||||||
// 展示本地存储能力
|
// 展示本地存储能力
|
||||||
@ -27,7 +31,8 @@ App({
|
|||||||
},
|
},
|
||||||
globalData: {
|
globalData: {
|
||||||
userInfo: null,
|
userInfo: null,
|
||||||
server_url: 'https://themblem.com'
|
server_url: 'https://themblem.com',
|
||||||
|
session_id: make_new_session_id(),
|
||||||
},
|
},
|
||||||
|
|
||||||
get_real_ip() {
|
get_real_ip() {
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
get_camera_rule,
|
get_camera_rule,
|
||||||
get_system_info,
|
get_system_info,
|
||||||
|
send_event,
|
||||||
} from '../../utils.js'
|
} from '../../utils.js'
|
||||||
|
|
||||||
import { debug, info, error } from '../../log.js'
|
import { debug, info, error } from '../../log.js'
|
||||||
@ -49,6 +50,7 @@ Page({
|
|||||||
qrarc_class: "sm",
|
qrarc_class: "sm",
|
||||||
qrmarkers_class: "hidden",
|
qrmarkers_class: "hidden",
|
||||||
frame_upload_in_flight: 0,
|
frame_upload_in_flight: 0,
|
||||||
|
frame_upload_failed: 0,
|
||||||
frame_upload_time_cost: 0,
|
frame_upload_time_cost: 0,
|
||||||
frame_upload_interval_ms: 2000,
|
frame_upload_interval_ms: 2000,
|
||||||
},
|
},
|
||||||
@ -89,8 +91,6 @@ Page({
|
|||||||
this.setData({
|
this.setData({
|
||||||
ai_chat_mode: options.ai_chat_mode,
|
ai_chat_mode: options.ai_chat_mode,
|
||||||
});
|
});
|
||||||
var new_session_id = Date.now();
|
|
||||||
getApp().globalData.session_id = new_session_id;
|
|
||||||
if (options.env == 'dev') {
|
if (options.env == 'dev') {
|
||||||
console.log("Using dev env settings.");
|
console.log("Using dev env settings.");
|
||||||
getApp().globalData.server_url = 'https://dev.themblem.com';
|
getApp().globalData.server_url = 'https://dev.themblem.com';
|
||||||
@ -392,36 +392,30 @@ Page({
|
|||||||
frame_upload_in_flight: this.data.frame_upload_in_flight + 1,
|
frame_upload_in_flight: this.data.frame_upload_in_flight + 1,
|
||||||
});
|
});
|
||||||
var seq_num = this.data.frame_upload_seq_num.toString().padStart(3, '0');
|
var seq_num = this.data.frame_upload_seq_num.toString().padStart(3, '0');
|
||||||
var fd = {
|
var event_data = {
|
||||||
session_id: getApp().globalData.session_id,
|
session_id: getApp().globalData.session_id,
|
||||||
phone_model: getApp().globalData.phone_model,
|
phone_model: getApp().globalData.phone_model,
|
||||||
seq_num: seq_num,
|
seq_num: seq_num,
|
||||||
image_data_url: data_url,
|
image_data_url: data_url,
|
||||||
}
|
}
|
||||||
wx.request({
|
var success_cb = (res) => {
|
||||||
url: "https://research.themblem.com/event/camera-frame",
|
this.setData({
|
||||||
method: "POST",
|
frame_uploaded: this.data.frame_uploaded + 1,
|
||||||
data: JSON.stringify(fd),
|
frame_upload_in_flight: this.data.frame_upload_in_flight - 1,
|
||||||
header: {
|
frame_upload_time_cost: Date.now() - begin,
|
||||||
"Content-Type": "application/json",
|
frame_upload_interval_ms: this.data.frame_upload_interval_ms * 2,
|
||||||
},
|
});
|
||||||
success: (res) => {
|
}
|
||||||
this.setData({
|
var fail_cb = (e) => {
|
||||||
frame_uploaded: this.data.frame_uploaded + 1,
|
this.log("frame upload failed", e);
|
||||||
frame_upload_in_flight: this.data.frame_upload_in_flight - 1,
|
this.setData({
|
||||||
frame_upload_time_cost: Date.now() - begin,
|
frame_upload_failed: this.data.frame_upload_failed + 1,
|
||||||
frame_upload_interval_ms: this.data.frame_upload_interval_ms * 2,
|
frame_upload_in_flight: this.data.frame_upload_in_flight - 1,
|
||||||
});
|
frame_upload_time_cost: Date.now() - begin,
|
||||||
},
|
frame_upload_interval_ms: this.data.frame_upload_interval_ms * 2,
|
||||||
fail: (e) => {
|
});
|
||||||
this.log("frame upload failed", e);
|
}
|
||||||
this.setData({
|
send_event("camera-frame", event_data, success_cb, fail_cb);
|
||||||
frame_upload_in_flight: this.data.frame_upload_in_flight - 1,
|
|
||||||
frame_upload_time_cost: Date.now() - begin,
|
|
||||||
frame_upload_interval_ms: this.data.frame_upload_interval_ms * 2,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
do_handle_frame(res) {
|
do_handle_frame(res) {
|
||||||
if (this.busy) return;
|
if (this.busy) return;
|
||||||
@ -441,7 +435,8 @@ Page({
|
|||||||
var uca1 = new Uint8ClampedArray(res.data);
|
var uca1 = new Uint8ClampedArray(res.data);
|
||||||
var uca = new Uint8ClampedArray(uca1);
|
var uca = new Uint8ClampedArray(uca1);
|
||||||
const data_url = data_url_from_frame(res.width, res.height, uca);
|
const data_url = data_url_from_frame(res.width, res.height, uca);
|
||||||
var r = frame_pre_check(res.width, res.height, uca, this.data.camera_sensitivity);
|
var r = frame_pre_check(res.width, res.height, uca,
|
||||||
|
this.data.camera_sensitivity)
|
||||||
const result = r.result;
|
const result = r.result;
|
||||||
this.log("frame_pre_check: ", JSON.stringify(result));
|
this.log("frame_pre_check: ", JSON.stringify(result));
|
||||||
this.setData({
|
this.setData({
|
||||||
|
|||||||
@ -91,11 +91,30 @@ function goto_camera(redirect, opts) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function make_new_session_id() {
|
||||||
|
return `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function send_event(event_name, data, success_cb, fail_cb) {
|
||||||
|
wx.request({
|
||||||
|
url: 'https://research.themblem.com/event/' + event_name,
|
||||||
|
method: 'POST',
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
header: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
success: success_cb,
|
||||||
|
fail: fail_cb,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
get_system_info,
|
get_system_info,
|
||||||
get_phone_model,
|
get_phone_model,
|
||||||
get_camera_rule,
|
get_camera_rule,
|
||||||
goto_camera,
|
goto_camera,
|
||||||
formatTime
|
formatTime,
|
||||||
|
make_new_session_id,
|
||||||
|
send_event,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user