Skip to content

Commit

Permalink
chore: 도메인 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
van1164 committed Apr 22, 2024
1 parent d75ea07 commit 2a568f3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SecurityConfig(
csrf { disable() }
cors { }
authorizeRequests {
authorize("/api/v1/stream/**",authenticated)
authorize("/api/v1/upload/**",authenticated)
authorize("/api/v1/stream/**",authenticated)
authorize("/**",permitAll)
Expand Down
10 changes: 0 additions & 10 deletions src/main/kotlin/com/KY/KoreanYoutube/detail/DetailController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,4 @@ class DetailController(
return "streamDetail"
}

@ResponseBody
@GetMapping("/live/{key}")
fun getm3u8(
@PathVariable("key") key : String,
): ResponseEntity<Any> {
val fileName = "index.m3u8"
logger.info { fileName }
return streamService.getTsFile(key,fileName)
}

}
2 changes: 1 addition & 1 deletion src/main/resources/templates/streamDetail.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/* video Element */
let video = null;
/* 샘플 m3u8 url */
let videoSrc ="http://localhost:8080/api/v1/stream/live/"+"[[${streamKey}]]"
let videoSrc ="https://video-share.shop/api/v1/stream/live/"+"[[${streamKey}]]"

/* initVideo */
const initVideo = () => {
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/templates/streaming.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ <h3>연결되면 나옵니다.</h3>
const keyElement = document.getElementById("key");
rtmpElement.textContent = "rtmp://localhost:1935/live"
keyElement.textContent = data
const eventSource = new EventSource("http://localhost/api/v1/stream/start_stream/" + data)
const eventSource = new EventSource("/api/v1/stream/start_stream/" + data)
eventSource.addEventListener("finish", (event) => {
console.log("finish")
console.log(event.data)
videoSrc = "http://localhost/api/v1/stream/live/"+data
videoSrc = "https://video-share.shop/api/v1/stream/live/"+data
initHls()
initVideo()
eventSource.close()
})

}
)

Expand Down
79 changes: 11 additions & 68 deletions src/main/resources/templates/uploadPage.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
</body>
<script>
let jwt = localStorage.getItem("jwt")

const generateUUID = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16)
);
const sendVideoChunks = () => {
let startTime = new Date(); // 시작
const chunkSize = 1024 * 1024 * 3; // 1MB
Expand All @@ -24,7 +32,7 @@
const totalChunks = Math.ceil(file.size / chunkSize);
let uploadFinish = 0;
let promises = [];
let fileUUID = crypto.randomUUID().toString()
let fileUUID = generateUUID()
for(let currentChunk =0; currentChunk<totalChunks; currentChunk++) {
let startPartTime = new Date(); // 시작
// chunk size 만큼 데이터 분할
Expand Down Expand Up @@ -79,7 +87,7 @@
Promise.all(promises).then(
() => {
console.log("모든 chunk 업로드하는데 걸린시간" + String(new Date() - startTime))
const eventSource = new EventSource("http://localhost:8080/api/v1/upload/videoPartLast/" + fileUUID + "/" + totalChunks.toString())
const eventSource = new EventSource("/api/v1/upload/videoPartLast/" + fileUUID + "/" + totalChunks.toString())

eventSource.addEventListener("ing", (event) => {
console.log(event.data)
Expand All @@ -89,78 +97,13 @@
eventSource.addEventListener("finish", (event) => {
console.log(event.data)
resultElement.textContent = "동영상 보러가기"
resultElement.href = "http://localhost:8080/detail/" + event.data
resultElement.href = "/detail/" + event.data
console.log("최종 걸린시간: " + String(new Date() - startTime));
eventSource.close()
})
})

}


const sendVideoChunksOriginal = () => {
let startTime = new Date(); // 시작
const chunkSize = 1024 * 1024 * 3; // 1MB
const file = document.getElementById("video-file").files[0];
const resultElement = document.getElementById("result");
const title = document.getElementById("title").value
console.log(title)
// total size 계산
const totalChunks = Math.ceil(file.size / chunkSize);
let currentChunk = 0;

const generateUUID = () =>
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(
c ^
(crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
).toString(16)
);

// chunk file 전송
const sendNextChunk = () => {

// chunk size 만큼 데이터 분할
const start = currentChunk * chunkSize;
const end = Math.min(start + chunkSize, file.size);

const chunk = file.slice(start, end);

// form data 형식으로 전송
const formData = new FormData();
formData.append("video", chunk);
console.log(generateUUID())
const json = JSON.stringify({title : title, chunkNumber : currentChunk, totalChunk : totalChunks, fileUUID : crypto.randomUUID().toString()})
formData.append("videoData", new Blob([json],{type:"application/json"}) );


fetch("/api/v1/upload/video", {
method: "POST",
body: formData,
headers : {}
}).then(resp => {
// 전송 결과가 206이면 다음 파일 조각 전송
if (resp.status === 206) {
// 진행률 표시
resultElement.textContent = Math.round(currentChunk / totalChunks * 100) + "%"
currentChunk++;
if (currentChunk < totalChunks) {
sendNextChunk();
}
// 마지막 파일까지 전송 되면
} else if (resp.status === 200) {
resp.text().then(data => {
console.log("최종 걸린시간: " + String(new Date() - startTime));
resultElement.textContent = "동영상 보러가기"
resultElement.href = "http://localhost:8080/detail/" +data
});
}
}).catch(err => {
console.error("Error uploading video chunk");
});
};

sendNextChunk();
}
</script>
</html>

0 comments on commit 2a568f3

Please sign in to comment.