Toggle navigation
Toggle navigation
This project
Loading...
Sign in
MotherProject
/
myYoutube
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Flare-k
2020-06-21 04:38:48 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
40e3fd405a73d6c769f7c485e76841963ea80116
40e3fd40
1 parent
c68147d5
[Add] Recording and User image
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
100 additions
and
5 deletions
assets/js/main.js
assets/js/videoRecorder.js
assets/scss/partials/videoRecorder.scss
assets/scss/styles.scss
controllers/userController.js
static/main.js
static/style.css
views/upload.pug
views/userDetail.pug
assets/js/main.js
View file @
40e3fd4
import
"../scss/styles.scss"
;
import
"./videoPlayer"
;
import
"./videoRecorder"
;
...
...
assets/js/videoRecorder.js
0 → 100644
View file @
40e3fd4
const
recorderContainer
=
document
.
getElementById
(
"jsRecordContainer"
);
const
recordBtn
=
document
.
getElementById
(
"jsRecordBtn"
);
const
videoPreview
=
document
.
getElementById
(
"jsVideoPreview"
);
// media devices navigator mdn -> video API
let
streamObject
;
let
videoRecorder
;
const
handleVideoData
=
(
event
)
=>
{
const
{
data
:
videoFile
}
=
event
;
const
link
=
document
.
createElement
(
"a"
);
link
.
href
=
URL
.
createObjectURL
(
videoFile
);
link
.
download
=
"recorded.webm"
;
document
.
body
.
appendChild
(
link
);
link
.
click
();
};
const
stopRecording
=
()
=>
{
videoRecorder
.
stop
();
recordBtn
.
removeEventListener
(
"click"
,
stopRecording
);
recordBtn
.
addEventListener
(
"click"
,
getVideo
);
recordBtn
.
innerHTML
=
"Start recording"
;
};
const
startRecording
=
()
=>
{
videoRecorder
=
new
MediaRecorder
(
streamObject
);
videoRecorder
.
start
();
videoRecorder
.
addEventListener
(
"dataavailable"
,
handleVideoData
);
recordBtn
.
addEventListener
(
"click"
,
stopRecording
);
};
const
getVideo
=
async
()
=>
{
try
{
const
stream
=
await
navigator
.
mediaDevices
.
getUserMedia
({
audio
:
true
,
video
:
{
width
:
1280
,
height
:
720
},
});
videoPreview
.
srcObject
=
stream
;
videoPreview
.
play
();
videoPreview
.
muted
=
true
;
recordBtn
.
innerHTML
=
"Stop recording."
;
streamObject
=
stream
;
startRecording
();
}
catch
(
error
)
{
recordBtn
.
innerHTML
=
"Sorry, You can't recording."
;
}
finally
{
recordBtn
.
removeEventListener
(
"click"
,
getVideo
);
}
};
function
init
()
{
recordBtn
.
addEventListener
(
"click"
,
getVideo
);
}
if
(
recorderContainer
)
{
init
();
}
assets/scss/partials/videoRecorder.scss
0 → 100644
View file @
40e3fd4
.record-container
{
width
:
100%
;
max-width
:
320px
;
margin-bottom
:
50px
;
video
{
background-color
:
$black
;
width
:
100%
;
margin-bottom
:
20px
;
}
}
assets/scss/styles.scss
View file @
40e3fd4
...
...
@@ -9,6 +9,7 @@
@import
"partials/socialLogin.scss"
;
@import
"partials/videoBlock.scss"
;
@import
"partials/videoPlayer.scss"
;
@import
"partials/videoRecorder.scss"
;
@import
"pages/home.scss"
;
@import
"pages/videoDetail.scss"
;
...
...
controllers/userController.js
View file @
40e3fd4
...
...
@@ -118,8 +118,14 @@ export const logout = (req, res) => {
res
.
redirect
(
routes
.
home
);
};
export
const
getMe
=
(
req
,
res
)
=>
res
.
render
(
"userDetail"
,
{
pageTitle
:
"User Detail"
,
user
:
req
.
user
});
export
const
getMe
=
async
(
req
,
res
)
=>
{
try
{
const
user
=
await
User
.
findById
(
req
.
user
.
id
).
populate
(
"videos"
);
res
.
render
(
"userDetail"
,
{
pageTitle
:
"User Detail"
,
user
});
}
catch
(
error
)
{
res
.
redirect
(
routes
.
home
);
}
};
// req.user -> 로그인된 유저
// export const users = (req, res) => res.render("users", { pageTitle: "Users" });
...
...
static/main.js
View file @
40e3fd4
...
...
@@ -94,7 +94,7 @@
/***/
(
function
(
module
,
__webpack_exports__
,
__webpack_require__
)
{
"use strict"
;
eval
(
"__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _scss_styles_scss__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../scss/styles.scss */ \"./assets/scss/styles.scss\");\n/* harmony import */ var _scss_styles_scss__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_scss_styles_scss__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _videoPlayer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./videoPlayer */ \"./assets/js/videoPlayer.js\");\n/* harmony import */ var _videoPlayer__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_videoPlayer__WEBPACK_IMPORTED_MODULE_1__);\n\n\n\n\n//# sourceURL=webpack:///./assets/js/main.js?"
);
eval
(
"__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _scss_styles_scss__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../scss/styles.scss */ \"./assets/scss/styles.scss\");\n/* harmony import */ var _scss_styles_scss__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_scss_styles_scss__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _videoPlayer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./videoPlayer */ \"./assets/js/videoPlayer.js\");\n/* harmony import */ var _videoPlayer__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_videoPlayer__WEBPACK_IMPORTED_MODULE_1__);\n
/* harmony import */ var _videoRecorder__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./videoRecorder */ \"./assets/js/videoRecorder.js\");\n/* harmony import */ var _videoRecorder__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_videoRecorder__WEBPACK_IMPORTED_MODULE_2__);\n\n
\n\n\n\n//# sourceURL=webpack:///./assets/js/main.js?"
);
/***/
}),
...
...
@@ -109,6 +109,17 @@ eval("const videoContainer = document.getElementById(\"jsVideoPlayer\");\nconst
/***/
}),
/***/
"./assets/js/videoRecorder.js"
:
/*!************************************!*\
!*** ./assets/js/videoRecorder.js ***!
\************************************/
/*! no static exports found */
/***/
(
function
(
module
,
exports
)
{
eval
(
"const recorderContainer = document.getElementById(\"jsRecordContainer\");\nconst recordBtn = document.getElementById(\"jsRecordBtn\");\nconst videoPreview = document.getElementById(\"jsVideoPreview\");\n// media devices navigator mdn -> video API\n\nlet streamObject;\nlet videoRecorder;\nconst handleVideoData = (event) => {\n const { data: videoFile } = event;\n const link = document.createElement(\"a\");\n link.href = URL.createObjectURL(videoFile);\n link.download = \"recorded.webm\";\n document.body.appendChild(link);\n link.click();\n};\n\nconst stopRecording = () => {\n videoRecorder.stop();\n recordBtn.removeEventListener(\"click\", stopRecording);\n recordBtn.addEventListener(\"click\", getVideo);\n recordBtn.innerHTML = \"Start recording\";\n};\nconst startRecording = () => {\n videoRecorder = new MediaRecorder(streamObject);\n videoRecorder.start();\n videoRecorder.addEventListener(\"dataavailable\", handleVideoData);\n recordBtn.addEventListener(\"click\", stopRecording);\n};\nconst getVideo = async () => {\n try {\n const stream = await navigator.mediaDevices.getUserMedia({\n audio: true,\n video: { width: 1280, height: 720 },\n });\n videoPreview.srcObject = stream;\n videoPreview.play();\n videoPreview.muted = true;\n recordBtn.innerHTML = \"Stop recording.\";\n streamObject = stream;\n startRecording();\n } catch (error) {\n recordBtn.innerHTML = \"Sorry, You can't recording.\";\n } finally {\n recordBtn.removeEventListener(\"click\", getVideo);\n }\n};\n\nfunction init() {\n recordBtn.addEventListener(\"click\", getVideo);\n}\n\nif (recorderContainer) {\n init();\n}\n\n\n//# sourceURL=webpack:///./assets/js/videoRecorder.js?"
);
/***/
}),
/***/
"./assets/scss/styles.scss"
:
/*!*********************************!*\
!*** ./assets/scss/styles.scss ***!
...
...
static/style.css
View file @
40e3fd4
...
...
@@ -492,6 +492,15 @@ input[type="submit"] {
font-size
:
25px
;
cursor
:
pointer
;
}
.record-container
{
width
:
100%
;
max-width
:
320px
;
margin-bottom
:
50px
;
}
.record-container
video
{
background-color
:
#444444
;
width
:
100%
;
margin-bottom
:
20px
;
}
.home-videos
{
display
:
grid
;
grid-template-columns
:
repeat
(
6
,
minmax
(
150px
,
1
fr
));
...
...
views/upload.pug
View file @
40e3fd4
...
...
@@ -2,6 +2,9 @@ extends layouts/main
block content
.form-container
.record-container#jsRecordContainer
video#jsVideoPreview
button#jsRecordBtn Start Recording
form(action=`/videos${routes.upload}`, method="post", enctype="multipart/form-data")
div.fileUpload
label(for="file") Video File
...
...
views/userDetail.pug
View file @
40e3fd4
...
...
@@ -4,9 +4,9 @@ include mixins/videoBlock
block content
.user-profile
.user-profile__header
img.u-avatar(src=user.avatarUrl)
img.u-avatar(src=user.avatarUrl
.startsWith("http") ? user.avatarUrl : `/${user.avatarUrl}`
)
h4.profile__username=user.name
if
user.id === loggedU
ser.id
if
loggedUser && loggedUser.id === u
ser.id
.user-profile__btns
a(href=`/users${routes.editProfile}`)
button 🖌 Edit Profile
...
...
Please
register
or
login
to post a comment