Repository navigation
Expand file tree
/
Copy pathbackground-services.js
More file actions
101 lines (93 loc) · 2.87 KB
/
Copy pathbackground-services.js
File metadata and controls
101 lines (93 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const { ipcMain } = require('electron')
const dbr = require('./libs/nodejs-barcode/index')
const barcodeTypes = dbr.barcodeTypes
const DEBUG = false
ipcMain.setMaxListeners(30)
function videoDecode(evt, imgData, width, height) {
if (DEBUG)
console.log(`${new Date().toLocaleString()}/real-time decoding for video stream: ${imgData.length/height}, ${width}`)
dbr.decodeBufferAsync(imgData, width, height, width*4, barcodeTypes, (err, msg) => {
if (err)
console.log(err)
let results = [];
for (index in msg) {
let result = Object()
let res = msg[index];
result.format = res['format']
result.value = res['value']
results.push(result)
}
evt.reply('videoDecode-next', results)
if (DEBUG)
console.log('ipcMain: replied with ' + JSON.stringify(results))
})
}
function decodeFileAsync(evt, filepath) {
if (DEBUG)
console.log('ipcMain: decodeFileAsync invoked: ' + filepath)
dbr.decodeFileAsync(filepath, barcodeTypes, (err, msg) => {
if (err)
console.log(err)
let results = [];
for (index in msg) {
let result = Object()
let res = msg[index];
result.format = res['format']
result.value = res['value']
results.push(result)
}
evt.reply('decodeFileAsync-done', results)
if (DEBUG)
console.log('ipcMain: replied with ' + JSON.stringify(results))
})
}
function decodeBase64Async(evt, base64Str) {
if (DEBUG)
console.log('ipcMain: decodeBase64Async is invoked')
dbr.decodeBase64Async(base64Str, barcodeTypes, (err, msg) => {
if (err)
console.error(err)
let results = [];
for (index in msg) {
let result = Object()
let res = msg[index];
result.format = res['format']
result.value = res['value']
results.push(result)
}
evt.reply('decodeBase64Async-done', results)
if (DEBUG)
console.log('ipcMain: replied with ' + JSON.stringify(results))
})
}
function decodeBufferAsync(evt, imgData, width, height) {
if (DEBUG)
console.log('ipcMain: decodeBufferAsync is invoked')
console.log(imgData)
dbr.decodeBufferAsync(imgData, width, height, width*4, barcodeTypes, (err, msg) => {
if (err)
console.error(err)
let results = [];
for (index in msg) {
let result = Object()
let res = msg[index];
result.format = res['format']
result.value = res['value']
results.push(result)
}
evt.reply('decodeBufferAsync-done', results)
if (DEBUG)
console.log('ipcMain: replied with ' + JSON.stringify(results))
})
}
function register() {
if (DEBUG)
console.log('background service to register')
ipcMain.on('decodeFileAsync', decodeFileAsync)
ipcMain.on('decodeBase64Async', decodeBase64Async)
ipcMain.on('decodeBufferAsync', decodeBufferAsync)
ipcMain.on('videoDecode', videoDecode)
}
module.exports = {
register
}