NodeCG
https://gyazo.com/188d6af77b15d2fc53b74d0752d67315
Broadcast Graphics | NodeCG
Node.js的全端框架
由Express+前端構成
前端部份亦可使用各種相關框架
主要用於如遊戲實況的畫面設計
可透過後台的儀表板管理畫面資訊
可透過API取得外部資訊
使用例
顯示Speedrun的跑者資訊、倒數時間…etc.
Games Done Quick和RTA in Japan亦有實際使用案例
https://github.com/RTAinJapan/rtainjapan-layouts
shu3在寶可夢 金/銀全圖鑑挑戰裡用作展示捕獲進度
https://www.youtube.com/watch?v=hQU1PlAh5_k
@shu33333: 249匹、なんとか無事走り終わりました!初代をやったあとの金銀、もう最高でした!名前付けで協力してくれた人、見てもらったみなさんありがとうございましたー!
https://pbs.twimg.com/media/FlzD8GyaMAEjYpy.jpg
安裝
https://www.nodecg.dev/docs/installing
1. 使用nodecg-clip
code:bash
npm install --global nodecg-cli@latest
mkdir nodecg
cd nodecg
nodecg setup
2. 從GitHub clone
code:bash
git clone --depth 1 --branch v2.1.0 https://github.com/nodecg/nodecg.git
cd nodecg
npm install
npm run build
執行
1. node index.js
2. nodecg start
預設儀表板網址為 http://localhost:9090
架構
Bundle
包含整個前端與後端的套組
Graphics
實際顯示在直播畫面的頁面
Dashboard
操作顯示畫面用的儀表板頁面
Extension
伺服器端用的控制畫面功能
傳遞資料
Messages
進行暫時性的資料存取,主要用於事件觸發
除了字串和數值之外,也能存取物件等JavaScript的資料型別
使用nodecg.sendMessage()傳送、nodecg.listenFor()接收
Replicants
進行永續性的資料存取,資料會以JSON實際儲存於.rep檔案內
使用nodecg.Replicant(name, *namespace, *opts)取值
可使用options賦予預設值
可藉由namespace取得其他bundle的Replicant
使用.value屬性更新
nodecg.Replicant('title').value = 'New Title';
亦可使用nodecg.readReplicant(name)取值
nodecg.readReplicant(name, (callback) => { ... })
實作
初始化Bundle
code:bash
cd bundles
mkdir counter
cd counter
git init
echo /module_modules/ > .gitignore
npm init -y
簡易計數器範例
code:bundles/new-layout/package.json
{
"name": "new-layout",
"version": "0.0.1",
"nodecg": {
"compatibleRange": "^2.0.0",
Bundle對應的NodeCG版本
code:bundles/new-layout/package.json
"dashboardPanels": [
顯示於Dashboard的控制面板
可用width指定面板寬度
code:bundles/new-layout/package.json
{
"name": "sample-panel",
"title": "Sample Panel",
"file": "sample-panel.html"
}
],
"graphics": [
顯示於Graphics上的頁面
code:bundles/new-layout/package.json
{
"file": "index.html",
"width": 1280,
"height": 720
}
]
}
}
控制面板
code:bundles/new-layout/dashboard/sample-panel.html
<!DOCTYPE html>
<html>
<body>
<button id="increment">+1</button>
<script>
const incrementEl = document.getElementById('increment')
const countReplicant = nodecg.Replicant('count')
incrementEl.addEventListener('click', () => {
countReplicant.value += 1
})
</script>
</body>
</html>
顯示頁面
code:bundles/new-layout/graphics/index.html
<!DOCTYPE html>
<html>
<body>
<div id="count"></div>
<script>
const countEl = document.getElementById('count')
const countReplicant = nodecg.Replicant('count', {defaultValue: 0})
countReplicant.on('change', newValue => {
countEl.innerText = newValue
})
</script>
</body>
</html>
Bundle
https://www.nodecg.dev/docs/frameworks/using-bundlers/
GitHub - codeoverflow-org/nodecg-io: A NodeCG-bundle which implements Social Media API's in the NodeCG framework
提供串接各個社群網站的API
https://nodecg.io/0.2/samples/twitch-api/
speedcontrol/nodecg-speedcontrol: NodeCG bundle to help facilitate the running of speedrunning marathons, including overlays.
Speedrun
相關連結
2018-12-08 ライブ配信レイアウトを作るNode.jsのフレームワーク - Qiita
2022-03-14 NodeCG + React で作る動的なライブ配信画面 - blog.livewing.net
2020-11-02 1から学ぶNodeCG#1:NodeCG導入編
2020-11-05 【NodeCG】実践Replicant
2021-12-04 NodeCG イベントの演目時間を管理するバンドル "nodecg-timekeeper"
レイアウトをNodeCG化した話 - HackMD
2024-05-13 TSKaigiは配信画面もTypeScript製だったという話
2024-07-13 配信オーバーレイフレームワーク「NodeCG」のご紹介と使い方 | OPENSPHERE Inc. Blog