Skip to content

Commit b5b8505

Browse files
committed
dockerizing
1 parent c7674a6 commit b5b8505

File tree

9 files changed

+93
-22
lines changed

9 files changed

+93
-22
lines changed

.dockerignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.git
2+
.vscode
3+
/files/*
4+
/files_server_side_record/*
5+
/node_modules
6+
/security/cert.key
7+
/security/cert.pem
8+
*.mp4
9+
*.webm
10+
*.sock
11+
video_list.txt

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
/security/cert.key
55
/security/cert.pem
66
*.mp4
7-
*.webm
7+
*.webm
8+
*.sock
9+
video_list.txt

Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:14
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY package*.json ./
6+
7+
RUN npm install
8+
9+
COPY . .
10+
11+
RUN npm run gen-pem
12+
13+
EXPOSE 3000
14+
15+
ENTRYPOINT npm run start-serverside

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"start-serverside": "__public_path__=public_serverside_record node server_ffmpeg_wrapper.js",
88
"start-clientside": "__public_path__=public_clientside_record node server_mediarecorder.js",
9-
"gen-pem": "rm security/cert.* && openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout security/cert.key -out security/cert.pem -config security/req.cnf -sha256",
9+
"gen-pem": "rm -f security/cert.* && openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout security/cert.key -out security/cert.pem -config security/req.cnf -sha256",
1010
"test": "echo \"Error: no test specified\" && exit 1"
1111
},
1212
"keywords": [],

public_clientside_record/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ function handleSuccess(stream) {
188188

189189
async function init(constraints) {
190190
try {
191+
// getDisplayMedia();
191192
const stream = await navigator.mediaDevices.getUserMedia(constraints);
192193
handleSuccess(stream);
193194
} catch (e) {
@@ -204,7 +205,7 @@ document.querySelector("button#start").addEventListener("click", async () => {
204205
audio: {
205206
echoCancellation: { ideal: hasEchoCancellation },
206207
},
207-
video: VIDEO_CONSTRAINTS_MOBILE,
208+
video: VIDEO_CONSTRAINTS,
208209
};
209210
console.log("Using media constraints:", constraints);
210211
await init(constraints);

public_serverside_record/index.js

+40-14
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,26 @@
33
const ICE_SERVERS_CONFIG = {
44
iceServers: [
55
{
6-
urls: "stun:stun.l.google.com:19302",
6+
urls: "stun:115.85.180.162",
77
},
8+
// TURN 서버 추가했는데 잘 되는듯?
89
{
9-
urls: "stun:stun1.l.google.com:19302",
10-
},
11-
{
12-
urls: "stun:stun2.l.google.com:19302",
13-
},
14-
{
15-
urls: "stun:stun3.l.google.com:19302",
16-
},
17-
{
18-
urls: "stun:stun4.l.google.com:19302",
10+
urls: "turn:115.85.180.162",
11+
username: "classvar",
12+
credential: "classvar",
1913
},
14+
// {
15+
// urls: "stun:stun1.l.google.com:19302",
16+
// },
17+
// {
18+
// urls: "stun:stun2.l.google.com:19302",
19+
// },
20+
// {
21+
// urls: "stun:stun3.l.google.com:19302",
22+
// },
23+
// {
24+
// urls: "stun:stun4.l.google.com:19302",
25+
// },
2026
],
2127
};
2228

@@ -137,18 +143,17 @@ function call() {
137143

138144
pcClient.onicecandidate = (event) => {
139145
socket.emit(NEW_PEER_ICE_CANDIDATE, event.candidate);
140-
// trace("ICE candidate:", event.candidate);
146+
trace("ICE candidate:", event.candidate);
141147
};
142148

143149
socket.on(NEW_PEER_ICE_CANDIDATE, (candidate) => {
144-
// trace("receiving new remote Ice Candidate: ");
145150
pcClient
146151
.addIceCandidate(candidate)
147152
.then(() => {
148153
trace("client: new Remote Ice Candidate: ", candidate);
149154
})
150155
.catch((e) => {
151-
trace("Error adding new Remote Ice Candidate: ", e);
156+
trace("Error adding new Remote Ice Candidate: ", candidate, e);
152157
});
153158
});
154159

@@ -260,6 +265,27 @@ function call() {
260265
trace("Failed to setLocalDescription: " + error.toString());
261266
});
262267
});
268+
269+
setTimeout(() => {
270+
pcClient.getSenders().map((sender) => {
271+
const kindOfTrack = sender.track?.kind;
272+
if (sender.transport) {
273+
const iceTransport = sender.transport.iceTransport;
274+
const logSelectedCandidate = () => {
275+
const selectedCandidatePair =
276+
iceTransport.getSelectedCandidatePair();
277+
console.log(
278+
`SELECTED ${kindOfTrack || "unknown"} SENDER CANDIDATE PAIR`,
279+
selectedCandidatePair
280+
);
281+
};
282+
iceTransport.onselectedcandidatepairchange = logSelectedCandidate;
283+
logSelectedCandidate();
284+
} else {
285+
// retry at some time later
286+
}
287+
});
288+
}, 3000);
263289
}
264290
}
265291

server_ffmpeg_wrapper.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const {
2424
3. ConnectionStateChange
2525
*/
2626
let pcServer;
27+
let uFrag;
2728
const IS_CALLER = true;
2829

2930
io.on("connection", async (serverSocket) => {
@@ -51,6 +52,13 @@ io.on("connection", async (serverSocket) => {
5152
// unified-plan의 효과는 뭘까?
5253
pcServer = new RTCPeerConnection(PEER_CONNECTION_CONFIG);
5354

55+
setTimeout(() => {
56+
serverSocket.emit(
57+
NEW_PEER_ICE_CANDIDATE,
58+
`candidate:1234512345 1 udp 4294967295 192.168.219.191 35000 typ srflx generation 0 ufrag ${uFrag} network-id 1`
59+
);
60+
}, 1000);
61+
5462
trace(
5563
"new PC\n- connectionState:",
5664
pcServer.connectionState,
@@ -83,9 +91,9 @@ io.on("connection", async (serverSocket) => {
8391
}
8492
*/
8593
pcServer.addEventListener(ICE_CANDIDATE, ({ candidate }) => {
86-
trace("My new Ice Candidate: ", candidate);
87-
// trace("Sending new ICE Candidate: ");
88-
// serverSocket.emit(NEW_PEER_ICE_CANDIDATE, candidate);
94+
// trace("My new Ice Candidate: ", candidate);
95+
trace("Sending new ICE Candidate: ");
96+
serverSocket.emit(NEW_PEER_ICE_CANDIDATE, candidate);
8997
});
9098

9199
// https://developer.mozilla.org/ko/docs/Web/API/RTCPeerConnection/onconnectionstatechange
@@ -126,6 +134,11 @@ io.on("connection", async (serverSocket) => {
126134
if (IS_CALLER) {
127135
try {
128136
const offerDesc = await pcServer.createOffer();
137+
138+
// const idx = offerDesc.sdp.indexOf("ice-ufrag:") + "ice-ufrag:".length;
139+
// uFrag = offerDesc.sdp.substring(idx, idx + 4);
140+
// offerDesc.sdp = offerDesc.sdp.replaceAll("0.0.0.0", "192.168.219.191");
141+
129142
// offerDesc.sdp +=
130143
// "a=candidate:4234997325 1 udp 2043278322 192.168.219.191 5000 typ host\r\n";
131144
trace("Created Offer: ", offerDesc);

test.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const fs = require("fs");
21
const { spawn } = require("child_process");
32
const ffmpegPath = require("@ffmpeg-installer/ffmpeg").path;
43
const VIDEO_OUTPUT_FILE = "./recording.mp4";

video_list.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
file './recording-360x640-1.mp4'
1+
file './recording-320x180-6.mp4'
2+
file './recording-480x270-7.mp4'
3+
file './recording-640x360-8.mp4'
4+
file './recording-960x540-9.mp4'
5+
file './recording-1280x720-10.mp4'

0 commit comments

Comments
 (0)