Skip to content

Commit

Permalink
chore: update hap-server
Browse files Browse the repository at this point in the history
Signed-off-by: JayFate <[email protected]>
  • Loading branch information
JayFate committed Aug 22, 2024
1 parent 7b3a574 commit 7ef24f3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 31 deletions.
5 changes: 3 additions & 2 deletions __tests__/examples/sample.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ describe('hap-toolkit', () => {
it(
'hap-server',
async () => {
const serverReg = /服务器地址: (http:\/\/.*),/
const dialogs = [
{
pattern: (output) => {
return output.match(/生成HTTP服务器的二维码: (http:\/\/.*)/)
return output.match(serverReg)
},
feeds: (proc, output) => {
const match = output.match(/生成HTTP服务器的二维码: (http:\/\/.*)/)
const match = output.match(serverReg)
const url = match[1]
const p1 = fetch(url)
.then((res) => {
Expand Down
14 changes: 1 addition & 13 deletions packages/hap-packager/src/router/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,6 @@ async function notify(context, next) {
await next()
}

/**
* 二维码api
*/
async function qrCode(context, next) {
const port = context.app.server.address().port
const data = getServerAddress(port)
const image = qr.image(data, { size: 9 })
await next()
context.type = 'image/png'
context.body = image
}

async function saveDataCoverage(context, next) {
const reqDataCoverage = context.request.body.coverage
if (!reqDataCoverage) {
Expand Down Expand Up @@ -224,7 +212,7 @@ async function saveDataLogs(context, next) {
export default {
index,
bundle,
qrCode,
qrCode: index,
logger,
notify,
saveDataCoverage,
Expand Down
8 changes: 3 additions & 5 deletions packages/hap-server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import http from 'http'
import Koa from 'koa'
import opn from 'opn'
import portfinder from 'portfinder'
import qrTerminal from 'qrcode-terminal'
import {
outputQRCodeOnTerminal,
getIPv4IPAddress,
colorconsole,
globalConfig,
Expand Down Expand Up @@ -75,11 +75,9 @@ export async function launch(conf) {
colorconsole.info(`### App Server ### 服务器地址: ${localUrl}, ${lanUrl}`)
colorconsole.info(`### App Server ### 请确保手机与App Server处于相同网段`)
// 输出二维码地址
outputQRCodeOnTerminal(lanUrl)
qrTerminal.generate(lanUrl, { small: true })
// 在浏览器中打开二维码页面
if (openBrowser) {
opn(lanUrl)
}
openBrowser && opn(lanUrl)
resolve({
launchServerError: null,
server,
Expand Down
3 changes: 1 addition & 2 deletions packages/hap-shared-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"event-bus.js"
],
"dependencies": {
"chalk": "^2.4.2",
"qrcode-terminal": "^0.12.0"
"chalk": "^2.4.2"
},
"devDependencies": {
"strip-ansi": "^5.2.0"
Expand Down
9 changes: 0 additions & 9 deletions packages/hap-shared-utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,6 @@ export function stripPrefixForIPV4MappedIPV6Address(ip) {
return ip
}

/**
* 命令行输出二维码
* @param text
*/
export function outputQRCodeOnTerminal(text) {
console.info(`\n生成HTTP服务器的二维码: ${text}`)
qrTerminal.generate(text, { small: true })
}

/**
* 相对工作目录的路径
*
Expand Down

0 comments on commit 7ef24f3

Please sign in to comment.