generated from vivid-lapin/ts
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNicoRenderer.tsx
241 lines (233 loc) · 7.85 KB
/
NicoRenderer.tsx
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import $ from "@recoiljs/refine"
import axios from "axios"
import clsx from "clsx"
import React, { useEffect, useState } from "react"
import { atom, useRecoilValue, useRecoilState } from "recoil"
import { syncEffect } from "recoil-sync"
import YAML from "yaml"
import { KakologStream } from "./streams/Kakolog"
import { NicoLiveList } from "./streams/NicoLiveList"
import { NicoSetting } from "./types"
import { InitPlugin } from "../@types/plugin"
import { SayaDefinition } from "../miraktest-saya/types"
import tailwind from "../tailwind.scss"
const _id = "io.github.ci7lus.miraktest-plugins.nico"
const prefix = "plugins.ci7lus.nico"
const meta = {
id: _id,
name: "ニコニコ実況",
author: "ci7lus",
version: "0.3.9",
description:
"ニコニコ実況からコメントを取得するプラグインです。対応するコメントレンダラープラグインが必要です。",
authorUrl: "https://github.com/ci7lus",
url: "https://github.com/ci7lus/miraktest-plugins/tree/master/src/miraktest-nico",
}
export const NicoRenderer: InitPlugin["renderer"] = ({ atoms, constants }) => {
const settingRefine = $.object({
isLiveEnabled: $.withDefault($.boolean(), true),
isTimeshiftEnabled: $.withDefault($.boolean(), true),
mail: $.voidable($.string()),
pass: $.voidable($.string()),
})
const settingAtom = atom<NicoSetting>({
key: `${prefix}.setting`,
default: {
isLiveEnabled: true,
isTimeshiftEnabled: true,
},
effects: [
syncEffect({
storeKey: constants?.recoil?.sharedKey,
refine: settingRefine,
}),
syncEffect({
storeKey: constants?.recoil?.storedKey,
refine: settingRefine,
}),
],
})
let isDplayerFound = false
let isPkrFound = false
return {
...meta,
exposedAtoms: [],
sharedAtoms: [
{
type: "atom",
atom: settingAtom,
},
],
storedAtoms: [
{
type: "atom",
atom: settingAtom,
},
],
setup({ plugins }) {
isDplayerFound = !!plugins.find(
(plugin) => plugin.id === "io.github.ci7lus.miraktest-plugins.dplayer"
)
isPkrFound = !!plugins.find(
(plugin) => plugin.id === "io.github.ci7lus.miraktest-plugins.pecore"
)
},
components: [
{
id: `${prefix}.onPlayer`,
position: "onPlayer",
component: () => {
const setting = useRecoilValue(settingAtom)
const service = useRecoilValue(atoms.contentPlayerServiceSelector)
const program = useRecoilValue(atoms.contentPlayerProgramSelector)
const isSeekable = useRecoilValue(
atoms.contentPlayerIsSeekableSelector
)
const time = useRecoilValue(atoms.contentPlayerPlayingTimeSelector)
const [sayaDefinition, setSayaDefinition] =
useState<SayaDefinition | null>(null)
useEffect(() => {
if (!isPkrFound && !isDplayerFound) {
console.warn("コメント送信先の取得に失敗しています")
return
}
axios
.get<string>(
"https://cdn.jsdelivr.net/gh/SlashNephy/saya-definitions@master/definitions.yml",
{
responseType: "text",
}
)
.then((r) => {
const parsed: SayaDefinition = YAML.parse(r.data)
setSayaDefinition(parsed)
})
.catch(console.error)
}, [])
return (
<>
{setting.isLiveEnabled && sayaDefinition && (
<NicoLiveList
sayaDefinition={sayaDefinition}
service={service}
program={program}
setting={setting}
isSeekable={isSeekable}
isDplayerFound={isDplayerFound}
isPkrFound={isPkrFound}
/>
)}
{setting.isTimeshiftEnabled && sayaDefinition && (
<KakologStream
sayaDefinition={sayaDefinition}
service={service}
program={program}
isSeekable={isSeekable}
time={time}
setting={setting}
isDplayerFound={isDplayerFound}
isPkrFound={isPkrFound}
/>
)}
</>
)
},
},
{
id: `${prefix}.settings`,
position: "onSetting",
label: meta.name,
component: () => {
const [setting, setSetting] = useRecoilState(settingAtom)
const [mail /*, setMail*/] = useState(setting.mail)
const [pass /*, _setPass*/] = useState(setting.pass)
const [isLiveEnabled, setIsLiveEnabled] = useState(
setting.isLiveEnabled
)
const [isTimeshiftEnabled, setIsTimeshiftEnabled] = useState(
setting.isTimeshiftEnabled
)
//const [isHidden, setIsHidden] = useState(true)
return (
<>
<style>{tailwind}</style>
<form
className="m-4"
onSubmit={(e) => {
e.preventDefault()
setSetting({
mail,
pass,
isLiveEnabled,
isTimeshiftEnabled,
})
}}
>
<label className={clsx("block", "mt-4")}>
<span>ニコニコ実況</span>
<input
type="checkbox"
className={clsx("block", "mt-2", "form-checkbox")}
checked={isLiveEnabled || false}
onChange={() => setIsLiveEnabled((enabled) => !enabled)}
/>
</label>
<label className={clsx("block", "mt-4")}>
<span>タイムシフト有効</span>
<input
type="checkbox"
className={clsx("block", "mt-2", "form-checkbox")}
checked={isTimeshiftEnabled || false}
onChange={() =>
setIsTimeshiftEnabled((enabled) => !enabled)
}
/>
</label>
{/*<label className="mt-4 block">
<span>モリタポのメールアドレス</span>
<input
type="text"
placeholder="miyou@miyou.tv"
className="block mt-2 form-input rounded-md w-full text-gray-900"
value={mail || ""}
onChange={(e) => setMail(e.target.value)}
/>
</label>
<label className="mt-4 block">
<span>モリタポのパスワード</span>
<input
type={isHidden ? "password" : "text"}
placeholder="*****"
className="block mt-2 form-input rounded-md w-full text-gray-900"
value={pass || ""}
onChange={(e) => setPass(e.target.value)}
onFocus={() => setIsHidden(false)}
onBlur={() => setIsHidden(true)}
/>
</label>*/}
<button
type="submit"
className={clsx(
"bg-gray-100",
"text-gray-800",
"p-2",
"px-2",
"my-4",
"rounded-md",
"cursor-pointer"
)}
>
保存
</button>
</form>
</>
)
},
},
],
destroy() {
return
},
windows: {},
}
}