Skip to content

Commit 42b4304

Browse files
committed
✨ [rmcn] mdnsでサービスを公開するように
1 parent ecfd242 commit 42b4304

File tree

4 files changed

+79
-9
lines changed

4 files changed

+79
-9
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"@types/react-dom": "^18.0.6",
8383
"axios": "^1.0.0-alpha.1",
8484
"axios-retry": "^3.3.1",
85+
"bonjour-service": "^1.0.14",
8586
"clsx": "^1.2.1",
8687
"dayjs": "^1.11.3",
8788
"discord-rpc": "^4.0.1",

src/miraktest-rmcn/Main.ts

+32-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Server } from "net"
22
import { networkInterfaces } from "os"
33
import Router from "@koa/router"
4+
import Bonjour from "bonjour-service"
5+
import type { Service as BonjourServcie } from "bonjour-service"
46
import { eventmit } from "eventmit"
57
import getPort from "get-port"
68
import Koa from "koa"
@@ -20,20 +22,39 @@ import {
2022

2123
export const Main: InitPlugin["main"] = async ({ appInfo, packages }) => {
2224
let server: Server | null = null
25+
let bonjour: Bonjour | null = null
2326
return {
2427
...RMCN_META,
2528
setup: async () => {
29+
let service: BonjourServcie | null = null
2630
const port = await getPort({ port: 10171 }) // TODO: Configurable
31+
try {
32+
bonjour = new Bonjour()
33+
service = bonjour.publish({
34+
name: "miraktest-rmcn",
35+
host: "miraktest-rmcn.local",
36+
type: "http",
37+
port,
38+
txt: appInfo,
39+
})
40+
console.info("[rmcn] Published Bonjour service:", service)
41+
} catch (error) {
42+
console.warn(error, "[rmcn] Bonjour not supported")
43+
}
2744
packages.Electron.ipcMain.handle(RMCN_GET_PORT, () => {
2845
let ip = "unknown"
29-
try {
30-
const addr = Object.values(networkInterfaces())
31-
.flat()
32-
.find((i) => i && i.family === "IPv4" && !i.internal)?.address
33-
if (addr) {
34-
ip = addr
35-
}
36-
} catch {}
46+
if (service && service.host) {
47+
ip = service.host
48+
} else {
49+
try {
50+
const addr = Object.values(networkInterfaces())
51+
.flat()
52+
.find((i) => i && i.family === "IPv4" && !i.internal)?.address
53+
if (addr) {
54+
ip = addr
55+
}
56+
} catch {}
57+
}
3758
return `${ip}:${port}`
3859
})
3960
type ContentPlayerState = {
@@ -160,6 +181,9 @@ export const Main: InitPlugin["main"] = async ({ appInfo, packages }) => {
160181
if (server) {
161182
server.close()
162183
}
184+
if (bonjour) {
185+
bonjour.destroy()
186+
}
163187
packages.Electron.ipcMain.removeHandler(RMCN_GET_PORT)
164188
packages.Electron.ipcMain.removeHandler(RMCN_SET_CP_STATE)
165189
packages.Electron.ipcMain.removeHandler(RMCN_SET_SERVICES)

src/miraktest-rmcn/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const RMCN_META = {
44
id: RMCN_ID,
55
name: "rmcn",
66
author: "ci7lus",
7-
version: "0.0.3",
7+
version: "0.1.0",
88
description: "リモコン用のAPIを生やすプラグイン",
99
authorUrl: "https://github.com/ci7lus",
1010
url: "https://github.com/ci7lus/miraktest-plugins/tree/master/src/miraktest-rmcn",

yarn.lock

+45
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,11 @@
13431343
methods "^1.1.2"
13441344
path-to-regexp "^6.2.1"
13451345

1346+
"@leichtgewicht/ip-codec@^2.0.1":
1347+
version "2.0.4"
1348+
resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b"
1349+
integrity sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A==
1350+
13461351
"@maxim_mazurok/gapi.client.drive@latest":
13471352
version "3.0.20220731"
13481353
resolved "https://registry.yarnpkg.com/@maxim_mazurok/gapi.client.drive/-/gapi.client.drive-3.0.20220731.tgz#1b8523aaefebcba41c87b9392e50d47eed3a7e63"
@@ -2159,6 +2164,11 @@ aribb24.js@1.9.16:
21592164
resolved "https://registry.yarnpkg.com/aribb24.js/-/aribb24.js-1.9.16.tgz#b024c37debf9fc7acc17dcaad3eb7065de97517a"
21602165
integrity sha512-HooKo7kYsfMzAG7QTZG+p1hhiVLB1I+SAkYZx5xP/wTVGh/3V6qVJ3RKS1rxyzlh4PRVQoMwAdkWqqS5OqaNNA==
21612166

2167+
array-flatten@^2.1.2:
2168+
version "2.1.2"
2169+
resolved "https://registry.yarnpkg.com/array-flatten/-/array-flatten-2.1.2.tgz#24ef80a28c1a893617e2149b0c6d0d788293b099"
2170+
integrity sha512-hNfzcOV8W4NdualtqBFPyVO+54DSJuZGY9qT4pRroB6S9e3iiido2ISIC5h9R2sPJ8H3FHCIiEnsv1lPXO3KtQ==
2171+
21622172
array-includes@^3.1.4:
21632173
version "3.1.5"
21642174
resolved "https://registry.yarnpkg.com/array-includes/-/array-includes-3.1.5.tgz#2c320010db8d31031fd2a5f6b3bbd4b1aad31bdb"
@@ -2363,6 +2373,16 @@ bn.js@^5.0.0, bn.js@^5.1.1:
23632373
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70"
23642374
integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==
23652375

2376+
bonjour-service@^1.0.14:
2377+
version "1.0.14"
2378+
resolved "https://registry.yarnpkg.com/bonjour-service/-/bonjour-service-1.0.14.tgz#c346f5bc84e87802d08f8d5a60b93f758e514ee7"
2379+
integrity sha512-HIMbgLnk1Vqvs6B4Wq5ep7mxvj9sGz5d1JJyDNSGNIdA/w2MCz6GTjWTdjqOJV1bEPj+6IkxDvWNFKEBxNt4kQ==
2380+
dependencies:
2381+
array-flatten "^2.1.2"
2382+
dns-equal "^1.0.0"
2383+
fast-deep-equal "^3.1.3"
2384+
multicast-dns "^7.2.5"
2385+
23662386
brace-expansion@^1.1.7:
23672387
version "1.1.11"
23682388
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
@@ -3231,6 +3251,18 @@ dlv@^1.1.3:
32313251
resolved "https://registry.yarnpkg.com/dlv/-/dlv-1.1.3.tgz#5c198a8a11453596e751494d49874bc7732f2e79"
32323252
integrity sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==
32333253

3254+
dns-equal@^1.0.0:
3255+
version "1.0.0"
3256+
resolved "https://registry.yarnpkg.com/dns-equal/-/dns-equal-1.0.0.tgz#b39e7f1da6eb0a75ba9c17324b34753c47e0654d"
3257+
integrity sha512-z+paD6YUQsk+AbGCEM4PrOXSss5gd66QfcVBFTKR/HpFL9jCqikS94HYwKww6fQyO7IxrIIyUu+g0Ka9tUS2Cg==
3258+
3259+
dns-packet@^5.2.2:
3260+
version "5.4.0"
3261+
resolved "https://registry.yarnpkg.com/dns-packet/-/dns-packet-5.4.0.tgz#1f88477cf9f27e78a213fb6d118ae38e759a879b"
3262+
integrity sha512-EgqGeaBB8hLiHLZtp/IbaDQTL8pZ0+IvwzSHA6d7VyMDM+B9hgddEMa9xjK5oYnw0ci0JQ6g2XCD7/f6cafU6g==
3263+
dependencies:
3264+
"@leichtgewicht/ip-codec" "^2.0.1"
3265+
32343266
doctrine@^2.1.0:
32353267
version "2.1.0"
32363268
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.1.0.tgz#5cd01fc101621b42c4cd7f5d1a66243716d3f39d"
@@ -5427,6 +5459,14 @@ ms@^2.1.1:
54275459
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
54285460
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
54295461

5462+
multicast-dns@^7.2.5:
5463+
version "7.2.5"
5464+
resolved "https://registry.yarnpkg.com/multicast-dns/-/multicast-dns-7.2.5.tgz#77eb46057f4d7adbd16d9290fa7299f6fa64cced"
5465+
integrity sha512-2eznPJP8z2BFLX50tf0LuODrpINqP1RVIm/CObbTcBRITQgmC/TjcREF1NeTBzIcR5XO/ukWo+YHOjBbFwIupg==
5466+
dependencies:
5467+
dns-packet "^5.2.2"
5468+
thunky "^1.0.2"
5469+
54305470
mute-stream@0.0.8:
54315471
version "0.0.8"
54325472
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
@@ -7006,6 +7046,11 @@ through@^2.3.6, through@^2.3.8:
70067046
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
70077047
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=
70087048

7049+
thunky@^1.0.2:
7050+
version "1.1.0"
7051+
resolved "https://registry.yarnpkg.com/thunky/-/thunky-1.1.0.tgz#5abaf714a9405db0504732bbccd2cedd9ef9537d"
7052+
integrity sha512-eHY7nBftgThBqOyHGVN+l8gF0BucP09fMo0oO/Lb0w1OF80dJv+lDVpXG60WMQvkcxAkNybKsrEIE3ZtKGmPrA==
7053+
70097054
title-case@^3.0.3:
70107055
version "3.0.3"
70117056
resolved "https://registry.yarnpkg.com/title-case/-/title-case-3.0.3.tgz#bc689b46f02e411f1d1e1d081f7c3deca0489982"

0 commit comments

Comments
 (0)