Skip to content

Commit 1781731

Browse files
sgfnmickel8
authored andcommitted
[All] Setup CI for JS assets (#28)
* [All] Setup CI for JS assets * Update version and licence
1 parent 080f439 commit 1781731

36 files changed

+4380
-352
lines changed

.github/workflows/build-check-app.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ jobs:
3434
otp-version: ${{ matrix.otp }}
3535
elixir-version: ${{ matrix.elixir }}
3636

37+
- name: Set up Node.js
38+
uses: actions/setup-node@v4
39+
with:
40+
node-version: 22
41+
42+
- name: Install libsrtp2
43+
working-directory: .
44+
run: |
45+
sudo apt-get update
46+
sudo apt-get install -y libsrtp2-dev
47+
3748
- name: Install FFmpeg development libraries
3849
if: ${{ inputs.with-ffmpeg }}
3950
working-directory: .
@@ -94,3 +105,12 @@ jobs:
94105
- name: Check with dialyzer
95106
if: ${{ !cancelled() && steps.compile.outcome == 'success' }}
96107
run: mix dialyzer
108+
109+
- name: Check assets formatting
110+
if: ${{ !cancelled() }}
111+
run: |
112+
mix assets.format
113+
if [[ -n "$(git status --porcelain)" ]]; then
114+
echo "Assets formatter introduced changes. Run `mix assets.format` and commit the updated files"
115+
exit 1
116+
fi

broadcaster/assets/.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5",
4+
"tabWidth": 2,
5+
"useTabs": false,
6+
"semi": true,
7+
"printWidth": 80
8+
}

broadcaster/assets/css/app.css

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
@import "tailwindcss/base";
2-
@import "tailwindcss/components";
3-
@import "tailwindcss/utilities";
1+
@import 'tailwindcss/base';
2+
@import 'tailwindcss/components';
3+
@import 'tailwindcss/utilities';
44

55
/* This file is for your main application CSS */
66
.invalid-input {
7-
border-color: #d52b4d;
7+
border-color: #d52b4d;
88
}
99

1010
.chat-message {
11-
display: flex;
12-
flex-direction: column;
13-
padding-top: 0.5rem;
14-
padding-bottom: 0.5rem;
11+
display: flex;
12+
flex-direction: column;
13+
padding-top: 0.5rem;
14+
padding-bottom: 0.5rem;
1515
}
1616

1717
.chat-nickname {
18-
font-weight: 600;
18+
font-weight: 600;
1919
}
2020

2121
/* from https://stackoverflow.com/a/38994837/9620900 */
2222
/* Hiding scrollbar for Chrome, Safari and Opera */
2323
#chat-messages::-webkit-scrollbar {
24-
display: none;
24+
display: none;
2525
}
2626

2727
/* Hiding scrollbar for IE, Edge and Firefox */
2828
#chat-messages {
29-
scrollbar-width: none; /* Firefox */
30-
-ms-overflow-style: none; /* IE and Edge */
29+
scrollbar-width: none; /* Firefox */
30+
-ms-overflow-style: none; /* IE and Edge */
3131
}
3232

3333
#chat-input::-webkit-scrollbar {
34-
display: none;
34+
display: none;
3535
}
3636

3737
/* Hiding scrollbar for IE, Edge and Firefox */
3838
#chat-input {
39-
scrollbar-width: none; /* Firefox */
40-
-ms-overflow-style: none; /* IE and Edge */
41-
}
39+
scrollbar-width: none; /* Firefox */
40+
-ms-overflow-style: none; /* IE and Edge */
41+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
import prettierPlugin from 'eslint-plugin-prettier';
4+
import prettierConfig from 'eslint-config-prettier';
5+
6+
export default [
7+
{
8+
files: ['**/*.js'],
9+
languageOptions: {
10+
ecmaVersion: 2021,
11+
sourceType: "module",
12+
globals: globals.browser
13+
},
14+
plugins: {
15+
prettier: prettierPlugin
16+
},
17+
rules: {
18+
"prettier/prettier": "error",
19+
"no-unused-vars": [
20+
"error",
21+
{
22+
"argsIgnorePattern": "^_",
23+
"varsIgnorePattern": "^_"
24+
}
25+
]
26+
},
27+
settings: {
28+
prettier: prettierConfig
29+
}
30+
},
31+
pluginJs.configs.recommended,
32+
];

broadcaster/assets/js/app.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,38 @@
1616
//
1717

1818
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
19-
import "phoenix_html"
19+
import 'phoenix_html';
2020
// Establish Phoenix Socket and LiveView configuration.
21-
import { Socket } from "phoenix"
22-
import { LiveSocket } from "phoenix_live_view"
23-
import topbar from "../vendor/topbar"
21+
import { Socket } from 'phoenix';
22+
import { LiveSocket } from 'phoenix_live_view';
23+
import topbar from '../vendor/topbar';
2424

25-
import { Home } from "./home.js"
26-
import { Player } from "./player.js"
25+
import { Home } from './home.js';
26+
import { Player } from './player.js';
2727

28-
let Hooks = {}
29-
Hooks.Home = Home
30-
Hooks.Player = Player
28+
let Hooks = {};
29+
Hooks.Home = Home;
30+
Hooks.Player = Player;
3131

32-
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
33-
let liveSocket = new LiveSocket("/live", Socket, {
32+
let csrfToken = document
33+
.querySelector("meta[name='csrf-token']")
34+
.getAttribute('content');
35+
let liveSocket = new LiveSocket('/live', Socket, {
3436
longPollFallbackMs: 2500,
3537
params: { _csrf_token: csrfToken },
3638
hooks: Hooks,
37-
})
39+
});
3840

3941
// Show progress bar on live navigation and form submits
40-
topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" })
41-
window.addEventListener("phx:page-loading-start", _info => topbar.show(300))
42-
window.addEventListener("phx:page-loading-stop", _info => topbar.hide())
42+
topbar.config({ barColors: { 0: '#29d' }, shadowColor: 'rgba(0, 0, 0, .3)' });
43+
window.addEventListener('phx:page-loading-start', (_info) => topbar.show(300));
44+
window.addEventListener('phx:page-loading-stop', (_info) => topbar.hide());
4345

4446
// connect if there are any LiveViews on the page
45-
liveSocket.connect()
47+
liveSocket.connect();
4648

4749
// expose liveSocket on window for web console debug logs and latency simulation:
4850
// >> liveSocket.enableDebug()
4951
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
5052
// >> liveSocket.disableLatencySim()
51-
window.liveSocket = liveSocket
52-
53+
window.liveSocket = liveSocket;

broadcaster/assets/js/chat.js

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
1-
import { Socket, Presence } from "phoenix"
1+
import { Socket, Presence } from 'phoenix';
22

33
export async function connectChat() {
4-
const viewercount = document.getElementById("viewercount");
5-
const chatMessages = document.getElementById("chat-messages");
6-
const chatInput = document.getElementById("chat-input");
7-
const chatNickname = document.getElementById("chat-nickname");
8-
const chatButton = document.getElementById("chat-button");
4+
const viewercount = document.getElementById('viewercount');
5+
const chatMessages = document.getElementById('chat-messages');
6+
const chatInput = document.getElementById('chat-input');
7+
const chatNickname = document.getElementById('chat-nickname');
8+
const chatButton = document.getElementById('chat-button');
99

10-
let socket = new Socket("/socket", { params: { token: window.userToken } });
10+
let socket = new Socket('/socket', { params: { token: window.userToken } });
1111

1212
socket.connect();
1313

14-
const channel = socket.channel("stream:chat");
14+
const channel = socket.channel('stream:chat');
1515
const presence = new Presence(channel);
1616

17-
send = function() {
18-
body = chatInput.value.trim();
19-
if (body != "") {
20-
channel.push("chat_msg", { body: body });
21-
chatInput.value = "";
17+
const send = function () {
18+
const body = chatInput.value.trim();
19+
if (body != '') {
20+
channel.push('chat_msg', { body: body });
21+
chatInput.value = '';
2222
}
23-
}
23+
};
2424

2525
presence.onSync(() => {
2626
viewercount.innerText = presence.list().length;
2727
});
2828

29-
channel.join()
30-
.receive("ok", resp => { console.log("Joined chat channel successfully", resp) })
31-
.receive("error", resp => { console.log("Unable to join chat channel", resp) });
29+
channel
30+
.join()
31+
.receive('ok', (resp) => {
32+
console.log('Joined chat channel successfully', resp);
33+
})
34+
.receive('error', (resp) => {
35+
console.log('Unable to join chat channel', resp);
36+
});
3237

33-
channel.on("join_chat_resp", resp => {
38+
channel.on('join_chat_resp', (resp) => {
3439
if (resp.result === 'success') {
35-
chatButton.innerText = "Send";
40+
chatButton.innerText = 'Send';
3641
chatButton.onclick = send;
3742
chatNickname.disabled = true;
3843
chatInput.disabled = false;
@@ -42,13 +47,13 @@ export async function connectChat() {
4247
ev.preventDefault();
4348
send();
4449
}
45-
}
50+
};
4651
} else {
4752
chatNickname.classList.add('invalid-input');
4853
}
4954
});
5055

51-
channel.on("chat_msg", msg => {
56+
channel.on('chat_msg', (msg) => {
5257
if (msg.nickname == undefined || msg.body == undefined) return;
5358

5459
const chatMessage = document.createElement('div');
@@ -71,15 +76,15 @@ export async function connectChat() {
7176

7277
// allow for 1 scroll history
7378
if (chatMessages.scrollHeight > 2 * chatMessages.clientHeight) {
74-
chatMessages.removeChild(chatMessages.children[0]);
79+
chatMessages.removeChild(chatMessages.children[0]);
7580
}
76-
})
81+
});
7782

7883
chatButton.onclick = () => {
79-
channel.push("join_chat", { nickname: chatNickname.value });
84+
channel.push('join_chat', { nickname: chatNickname.value });
8085
};
8186

8287
chatNickname.onclick = () => {
83-
chatNickname.classList.remove("invalid-input");
84-
}
88+
chatNickname.classList.remove('invalid-input');
89+
};
8590
}

0 commit comments

Comments
 (0)