openvidu-insecure-vue

This commit is contained in:
Victor Astakhov 2020-05-30 21:44:23 +03:00
parent 005dbb415f
commit 8a2ba6ed0f
15 changed files with 665 additions and 0 deletions

22
openvidu-insecure-vue/.gitignore vendored Normal file
View File

@ -0,0 +1,22 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@ -0,0 +1,13 @@
[![License badge](https://img.shields.io/badge/license-Apache2-orange.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![Documentation Status](https://readthedocs.org/projects/openviduio-docs/badge/?version=stable)](https://docs.openvidu.io/en/stable/?badge=stable)
[![Docker badge](https://img.shields.io/docker/pulls/openvidu/openvidu-server-kms.svg)](https://hub.docker.com/r/openvidu/openvidu-server-kms)
[![Support badge](https://img.shields.io/badge/support-sof-yellowgreen.svg)](https://groups.google.com/forum/#!forum/openvidu)
[![][OpenViduLogo]](http://openvidu.io)
openvidu-insecure-vue
===
Visit [docs.openvidu.io/en/stable/tutorials/openvidu-insecure-vue/](http://docs.openvidu.io/en/stable/tutorials/openvidu-insecure-vue/)
[OpenViduLogo]: https://secure.gravatar.com/avatar/5daba1d43042f2e4e85849733c8e5702?s=120

View File

@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

View File

@ -0,0 +1,48 @@
{
"name": "openvidu-insecure-vue",
"version": "2.14.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.19.2",
"core-js": "^3.6.5",
"openvidu-browser": "2.14.0",
"vue": "^2.6.11"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.4.0",
"@vue/cli-plugin-eslint": "~4.4.0",
"@vue/cli-service": "~4.4.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
],
"repository": {
"type": "git",
"url": "git@github.com:OpenVidu/openvidu-tutorials.git"
}
}

View File

@ -0,0 +1,44 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>resources/images/favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
<!-- Bootstrap -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Bootstrap -->
<link rel="stylesheet" href="style.css" type="text/css" media="screen">
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/"><img class="demo-logo" src="resources/images/openvidu_vert_white_bg_trans_cropped.png"/> Insecure Vue</a>
<a class="navbar-brand nav-icon" href="https://github.com/OpenVidu/openvidu-tutorials/tree/master/openvidu-insecure-vue" title="GitHub Repository" target="_blank"><i class="fa fa-github" aria-hidden="true"></i></a>
<a class="navbar-brand nav-icon" href="http://www.docs.openvidu.io/en/stable/tutorials/openvidu-insecure-vue/" title="Documentation" target="_blank"><i class="fa fa-book" aria-hidden="true"></i></a>
</div>
</div>
</nav>
<div id="app"></div>
<!-- built files will be auto injected -->
<footer class="footer">
<div class="container">
<div class="text-muted">OpenVidu © 2020</div>
<a href="http://www.openvidu.io/" target="_blank">
<img class="openvidu-logo" src="resources/images/openvidu_globe_bg_transp_cropped.png" />
</a>
</div>
</footer>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -0,0 +1,266 @@
html {
position: relative;
min-height: 100%;
}
nav {
height: 50px;
width: 100%;
z-index: 1;
background-color: #4d4d4d !important;
border-color: #4d4d4d !important;
border-top-right-radius: 0 !important;
border-top-left-radius: 0 !important;
}
.navbar-header {
width: 100%;
}
.nav-icon {
padding: 5px 15px 5px 15px;
float: right;
}
nav a {
color: #ccc !important;
}
nav i.fa {
font-size: 40px;
color: #ccc;
}
nav a:hover {
color: #a9a9a9 !important;
}
nav i.fa:hover {
color: #a9a9a9;
}
#main-container {
padding-bottom: 80px;
}
/*vertical-center {
position: relative;
top: 30%;
left: 50%;
transform: translate(-50%, -50%);
}*/
.horizontal-center {
margin: 0 auto;
}
.form-control {
color: #0088aa;
font-weight: bold;
}
.form-control:focus {
border-color: #0088aa;
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(0, 136, 170, 0.6);
box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(0, 136, 170, 0.6);
}
input.btn {
font-weight: bold;
}
.btn {
font-weight: bold !important;
}
.btn-success {
background-color: #06d362 !important;
border-color: #06d362;
}
.btn-success:hover {
background-color: #1abd61 !important;
border-color: #1abd61;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
background-color: #4d4d4d;
}
.footer .text-muted {
margin: 20px 0;
float: left;
color: #ccc;
}
.openvidu-logo {
height: 35px;
float: right;
margin: 12px 0;
-webkit-transition: all 0.1s ease-in-out;
-moz-transition: all 0.1s ease-in-out;
-o-transition: all 0.1s ease-in-out;
transition: all 0.1s ease-in-out;
}
.openvidu-logo:hover {
-webkit-filter: grayscale(0.5);
filter: grayscale(0.5);
}
.demo-logo {
margin: 0;
height: 22px;
float: left;
padding-right: 8px;
}
a:hover .demo-logo {
-webkit-filter: brightness(0.7);
filter: brightness(0.7);
}
#join-dialog {
margin-left: auto;
margin-right: auto;
max-width: 70%;
}
#join-dialog h1 {
color: #4d4d4d;
font-weight: bold;
text-align: center;
}
#img-div {
text-align: center;
margin-top: 3em;
margin-bottom: 3em;
/*position: relative;
top: 20%;
left: 50%;
transform: translate(-50%, -50%);*/
}
#img-div img {
height: 15%;
}
#join-dialog label {
color: #0088aa;
}
#join-dialog input.btn {
margin-top: 15px;
}
#session-header {
margin-bottom: 20px;
}
#session-title {
display: inline-block;
}
#buttonLeaveSession {
float: right;
margin-top: 20px;
}
#video-container video {
position: relative;
float: left;
width: 50%;
cursor: pointer;
}
#video-container video + div {
float: left;
width: 50%;
position: relative;
margin-left: -50%;
}
#video-container p {
display: inline-block;
background: #f8f8f8;
padding-left: 5px;
padding-right: 5px;
color: #777777;
font-weight: bold;
border-bottom-right-radius: 4px;
}
video {
width: 100%;
height: auto;
}
#main-video p {
position: absolute;
display: inline-block;
background: #f8f8f8;
padding-left: 5px;
padding-right: 5px;
font-size: 22px;
color: #777777;
font-weight: bold;
border-bottom-right-radius: 4px;
}
#session img {
width: 100%;
height: auto;
display: inline-block;
object-fit: contain;
vertical-align: baseline;
}
#session #video-container img {
position: relative;
float: left;
width: 50%;
cursor: pointer;
object-fit: cover;
height: 180px;
}
/* xs ans md screen resolutions*/
@media screen and (max-width: 991px) and (orientation: portrait) {
#join-dialog {
max-width: inherit;
}
#img-div img {
height: 10%;
}
#img-div {
margin-top: 2em;
margin-bottom: 2em;
}
.container-fluid>.navbar-collapse, .container-fluid>.navbar-header, .container>.navbar-collapse, .container>.navbar-header {
margin-right: 0;
margin-left: 0;
}
.navbar-header i.fa {
font-size: 30px;
}
.navbar-header a.nav-icon {
padding: 7px 3px 7px 3px;
}
}
@media only screen and (max-height: 767px) and (orientation: landscape) {
#img-div {
margin-top: 1em;
margin-bottom: 1em;
}
#join-dialog {
max-width: inherit;
}
}

View File

@ -0,0 +1,206 @@
<template>
<div id="main-container" class="container">
<div id="join" v-if="!session">
<div id="img-div"><img src="resources/images/openvidu_grey_bg_transp_cropped.png" /></div>
<div id="join-dialog" class="jumbotron vertical-center">
<h1>Join a video session</h1>
<form class="form-group" @submit="joinSession">
<p>
<label>Participant</label>
<input v-model="myUserName" class="form-control" type="text" required>
</p>
<p>
<label>Session</label>
<input v-model="mySessionId" class="form-control" type="text" required>
</p>
<p class="text-center">
<input class="btn btn-lg btn-success" type="submit" name="commit" value="Join!">
</p>
</form>
</div>
</div>
<div id="session" v-if="session">
<div id="session-header">
<h1 id="session-title">{{ mySessionId }}</h1>
<input class="btn btn-large btn-danger" type="button" id="buttonLeaveSession" @click="leaveSession" value="Leave session">
</div>
<div id="main-video" class="col-md-6">
<user-video :stream-manager="mainStreamManager"/>
</div>
<div id="video-container" class="col-md-6">
<user-video :stream-manager="publisher" @click="setMainVideoStream(publisher)"/>
<user-video v-for="(sub, index) in subscribers" :key="index" :stream-manager="sub" @click="setMainVideoStream(sub)"/>
</div>
</div>
</div>
</template>
<script>
import axios from 'axios';
import { OpenVidu } from 'openvidu-browser';
import UserVideo from './components/UserVideo';
axios.defaults.headers.post['Content-Type'] = 'application/json';
const OPENVIDU_SERVER_URL = "https://" + location.hostname + ":4443";
const OPENVIDU_SERVER_SECRET = "MY_SECRET";
export default {
name: 'App',
components: {
UserVideo,
},
data () {
return {
session: undefined,
mainStreamManager: undefined,
publisher: undefined,
subscribers: [],
mySessionId: 'SessionA',
myUserName: 'Participant' + Math.floor(Math.random() * 100),
}
},
methods: {
joinSession () {
// --- Get an OpenVidu object ---
const OV = new OpenVidu();
// --- Init a session ---
this.session = OV.initSession();
// --- Specify the actions when events take place in the session ---
// On every new Stream received...
this.session.on('streamCreated', ({ stream }) => {
this.subscribers.push(this.session.subscribe(stream));
});
// On every Stream destroyed...
this.session.on('streamDestroyed', ({ stream }) => {
const index = this.subscribers.indexOf(stream.streamManager, 0);
if (index >= 0) {
this.subscribers.splice(index, 1);
}
});
// --- Connect to the session with a valid user token ---
// 'getToken' method is simulating what your server-side should do.
// 'token' parameter should be retrieved and returned by your own backend
this.getToken(this.mySessionId).then(token => {
this.session.connect(token, { clientData: this.myUserName })
.then(() => {
// --- Get your own camera stream with the desired properties ---
this.publisher = OV.initPublisher(undefined, {
audioSource: undefined, // The source of audio. If undefined default microphone
videoSource: undefined, // The source of video. If undefined default webcam
publishAudio: true, // Whether you want to start publishing with your audio unmuted or not
publishVideo: true, // Whether you want to start publishing with your video enabled or not
resolution: '640x480', // The resolution of your video
frameRate: 30, // The frame rate of your video
insertMode: 'APPEND', // How the video is inserted in the target element 'video-container'
mirror: false // Whether to mirror your local video or not
});
this.mainStreamManager = this.publisher;
// --- Publish your stream ---
this.session.publish(this.publisher);
})
.catch(error => {
console.log('There was an error connecting to the session:', error.code, error.message);
});
});
window.addEventListener('beforeunload', this.leaveSession)
},
leaveSession () {
// --- Leave the session by calling 'disconnect' method over the Session object ---
if (this.session) this.session.disconnect();
this.session = undefined;
this.mainStreamManager = undefined;
this.publisher = undefined;
this.subscribers = [];
window.removeEventListener('beforeunload', this.leaveSession);
},
setMainVideoStream (stream) {
if (this.mainStreamManager === stream) return;
this.mainStreamManager = stream
},
/**
* --------------------------
* SERVER-SIDE RESPONSIBILITY
* --------------------------
* These methods retrieve the mandatory user token from OpenVidu Server.
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION (by using
* the API REST, openvidu-java-client or openvidu-node-client):
* 1) Initialize a session in OpenVidu Server (POST /api/sessions)
* 2) Generate a token in OpenVidu Server (POST /api/tokens)
* 3) The token must be consumed in Session.connect() method
*/
getToken (mySessionId) {
return this.createSession(mySessionId).then(sessionId => this.createToken(sessionId));
},
// See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apisessions
createSession (sessionId) {
return new Promise((resolve, reject) => {
axios
.post(`${OPENVIDU_SERVER_URL}/api/sessions`, JSON.stringify({
customSessionId: sessionId,
}), {
auth: {
username: 'OPENVIDUAPP',
password: OPENVIDU_SERVER_SECRET,
},
})
.then(response => response.data)
.then(data => resolve(data.id))
.catch(error => {
if (error.response.status === 409) {
resolve(sessionId);
} else {
console.warn(`No connection to OpenVidu Server. This may be a certificate error at ${OPENVIDU_SERVER_URL}`);
if (window.confirm(`No connection to OpenVidu Server. This may be a certificate error at ${OPENVIDU_SERVER_URL}\n\nClick OK to navigate and accept it. If no certificate warning is shown, then check that your OpenVidu Server is up and running at "${OPENVIDU_SERVER_URL}"`)) {
location.assign(`${OPENVIDU_SERVER_URL}/accept-certificate`);
}
reject(error.response);
}
});
});
},
// See https://docs.openvidu.io/en/stable/reference-docs/REST-API/#post-apitokens
createToken (sessionId) {
return new Promise((resolve, reject) => {
axios
.post(`${OPENVIDU_SERVER_URL}/api/tokens`, JSON.stringify({
session: sessionId,
}), {
auth: {
username: 'OPENVIDUAPP',
password: OPENVIDU_SERVER_SECRET,
},
})
.then(response => response.data)
.then(data => resolve(data.token))
.catch(error => reject(error.response));
});
},
}
}
</script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -0,0 +1,17 @@
<template>
<video autoplay/>
</template>
<script>
export default {
name: 'OvVideo',
props: {
streamManager: Object,
},
mounted () {
this.streamManager.addVideoElement(this.$el);
},
};
</script>

View File

@ -0,0 +1,36 @@
<template>
<div v-if="streamManager">
<ov-video :stream-manager="streamManager"/>
<div><p>{{ clientData }}</p></div>
</div>
</template>
<script>
import OvVideo from './OvVideo';
export default {
name: 'UserVideo',
components: {
OvVideo,
},
props: {
streamManager: Object,
},
computed: {
clientData () {
const { clientData } = this.getConnectionData();
return clientData;
},
},
methods: {
getConnectionData () {
const { connection } = this.streamManager.stream;
return JSON.parse(connection.data);
},
},
};
</script>

View File

@ -0,0 +1,8 @@
import Vue from 'vue'
import App from './App.vue'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')