niimbot-web-print
v1.2.3
Published
niimbot-web-print
Downloads
5
Readme
精臣web打印websocket封装为promise
引入
npm install --save niimbot-web-print
使用
import { Socket, NMPrintSocket } form 'niimbot-web-print'
// 创建socket实例
const socketData = new Socket('ws://127.0.0.1:373989')
socketData.open((openBool) => {
if (openBool) {
// websocket连接成功
} else {
// websocket连接失败
}
})
// 创建打印实例
const nMPrintSocket = new NMPrintSocket(socketData)
// 获取打印机列表 支持以下两种写法
nMPrintSocket.getAllPrinters().then(res => {
// res 打印socket消息方法数据
console.log(res)
if (res.resultAck.errorCode === 0) {
nMPrintSocket.selectPrinter(res.resultAck.result[0], '1234').then(res2 => {
console.log(res2)
})
}
})
const fn = async () => {
try {
const res = await nMPrintSocket.getAllPrinters()
const res2 = await nMPrintSocket.selectPrinter(res.resultAck.result[0], '1234')
console.log(res2)
} catch (err) {
console.log(err)
}
}