openvidu-insecure-angular new style
This commit is contained in:
parent
fdae18eb4b
commit
4a67a7f9f1
@ -21,18 +21,19 @@ window.addEventListener('load', function () {
|
||||
});
|
||||
|
||||
// Disconnect participant on browser's window closed
|
||||
window.onbeforeunload = function () {
|
||||
session.disconnect()
|
||||
};
|
||||
window.addEventListener('beforeunload', function () {
|
||||
session.disconnect();
|
||||
});
|
||||
|
||||
|
||||
function joinRoom(sessionId) {
|
||||
// If the user is joining to a new room
|
||||
|
||||
if (!sessionId) {
|
||||
// If the user is joining to a new room
|
||||
var sessionId = '#' + randomString();
|
||||
}
|
||||
|
||||
// As insecure OpenVidu, the user's token will be a random id
|
||||
// As insecure OpenVidu, the user's token can be a random string
|
||||
var userId = randomString();
|
||||
|
||||
// --- 1) Get an OpenVidu object and init a session with a sessionId ---
|
||||
@ -105,10 +106,10 @@ function joinRoom(sessionId) {
|
||||
|
||||
function leaveRoom() {
|
||||
|
||||
// 6) Leave the session by calling 'disconnect' method over the Session object
|
||||
// --- 6) Leave the session by calling 'disconnect' method over the Session object ---
|
||||
session.disconnect();
|
||||
|
||||
showJoinHideSession();
|
||||
|
||||
window.location.href = window.location.origin;
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,23 @@
|
||||
#publisher {
|
||||
float: left;
|
||||
width: 20%;
|
||||
margin: 10px;
|
||||
.stream-container {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#subscriber {
|
||||
float: left;
|
||||
width: 20%;
|
||||
margin: 10px;
|
||||
#session {
|
||||
padding-top: 70px;
|
||||
height: 100vh;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#session-header {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#session-title {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
#buttonLeaveSession {
|
||||
float: right;
|
||||
margin-top: 20px;
|
||||
}
|
||||
@ -1,31 +1,36 @@
|
||||
<div *ngIf="!session">
|
||||
<h1>Join a video session</h1>
|
||||
<form (submit)="joinSession()" accept-charset="UTF-8">
|
||||
<p>
|
||||
<label>Participant:</label>
|
||||
<input type="text" name="token" id="participantId" [(ngModel)]="token" required>
|
||||
</p>
|
||||
<p>
|
||||
<label>Session:</label>
|
||||
<input type="text" name="sessionId" id="sessionId" [(ngModel)]="sessionId" required>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" name="commit" value="Join!">
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div *ngIf="session">
|
||||
<h2 id="session-header">{{sessionId}}</h2>
|
||||
<input id="buttonLeaveSession" type="button" (click)="leaveSession()" value="Leave session">
|
||||
<div id="publisher">
|
||||
<div *ngIf="this.localStream">
|
||||
<stream-component [stream]="this.localStream"></stream-component>
|
||||
</div>
|
||||
<div class="container vertical-center">
|
||||
<div *ngIf="!session" id="join" class="jumbotron horizontal-center">
|
||||
<h1>Join a video session</h1>
|
||||
<form class="form-group" (submit)="joinSession()">
|
||||
<p>
|
||||
<label>Participant</label>
|
||||
<input class="form-control" type="text" name="token" id="participantId" [(ngModel)]="token" required>
|
||||
</p>
|
||||
<p>
|
||||
<label>Session</label>
|
||||
<input class="form-control" type="text" name="sessionId" id="sessionId" [(ngModel)]="sessionId" required>
|
||||
</p>
|
||||
<p class="text-center">
|
||||
<input class="btn btn-lg btn-success" type="submit" name="commit" value="Join!">
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<div id="subscriber">
|
||||
<div *ngFor="let s of this.remoteStreams">
|
||||
<stream-component [stream]="s"></stream-component>
|
||||
|
||||
<div *ngIf="session" id="session">
|
||||
<div id="session-header">
|
||||
<h1 id="session-title">{{sessionId}}</h1>
|
||||
<input class="btn btn-large btn-danger" type="button" id="buttonLeaveSession" (click)="leaveSession()" value="Leave session">
|
||||
</div>
|
||||
<div *ngIf="this.mainVideoStream" id="main-video" class="col-md-6">
|
||||
<stream-component [stream]="this.mainVideoStream"></stream-component>
|
||||
</div>
|
||||
<div id="video-container" class="col-md-6">
|
||||
<div class="stream-container col-md-6 col-xs-6" *ngIf="this.localStream">
|
||||
<stream-component [stream]="this.localStream" (mainVideoStream)="getMainVideoStream($event)"></stream-component>
|
||||
</div>
|
||||
<div class="stream-container col-md-6 col-xs-6" *ngFor="let s of this.remoteStreams">
|
||||
<stream-component [stream]="s" (mainVideoStream)="getMainVideoStream($event)"></stream-component>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -1,5 +1,5 @@
|
||||
import { OpenVidu, Session, Stream } from 'openvidu-browser';
|
||||
import { Component, HostListener } from '@angular/core';
|
||||
import { Component, HostListener, Input } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@ -20,6 +20,9 @@ export class AppComponent {
|
||||
sessionId: string;
|
||||
token: string;
|
||||
|
||||
@Input()
|
||||
mainVideoStream: Stream;
|
||||
|
||||
constructor() {
|
||||
this.generateParticipantInfo();
|
||||
}
|
||||
@ -63,6 +66,7 @@ export class AppComponent {
|
||||
});
|
||||
|
||||
this.localStream = publisher.stream;
|
||||
this.mainVideoStream = this.localStream;
|
||||
|
||||
// 5) Publish your stream
|
||||
this.session.publish(publisher);
|
||||
@ -99,4 +103,8 @@ export class AppComponent {
|
||||
}
|
||||
}
|
||||
|
||||
private getMainVideoStream(stream: Stream) {
|
||||
this.mainVideoStream = stream;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { Component, Input, DoCheck } from '@angular/core';
|
||||
import { Component, Input, Output, DoCheck, EventEmitter } from '@angular/core';
|
||||
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
|
||||
|
||||
import { Stream } from 'openvidu-browser';
|
||||
@ -9,11 +9,26 @@ import { Stream } from 'openvidu-browser';
|
||||
video {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
float: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
div div {
|
||||
position: absolute;
|
||||
background: #f8f8f8;
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
color: #777777;
|
||||
font-weight: bold;
|
||||
border-bottom-right-radius: 4px;
|
||||
}
|
||||
p{
|
||||
margin: 0;
|
||||
}`],
|
||||
template: `
|
||||
<div>
|
||||
<video autoplay="true" [src]="videoSrc" [id]="'native-video-' + this.stream.connection.connectionId + '_webcam'"></video>
|
||||
<p [id]="'data-' + this.stream.connection.connectionId">{{this.getNicknameTag()}}</p>
|
||||
<video autoplay="true" [src]="videoSrc" [id]="'native-video-' + this.stream.connection.connectionId + '_webcam'"
|
||||
(click)="this.videoClicked()"></video>
|
||||
<div [id]="'data-' + this.stream.connection.connectionId"><p>{{this.getNicknameTag()}}</p></div>
|
||||
</div>`
|
||||
})
|
||||
export class StreamComponent implements DoCheck {
|
||||
@ -21,6 +36,9 @@ export class StreamComponent implements DoCheck {
|
||||
@Input()
|
||||
stream: Stream;
|
||||
|
||||
@Output()
|
||||
mainVideoStream = new EventEmitter();
|
||||
|
||||
videoSrc: SafeUrl = '';
|
||||
videSrcUnsafe = '';
|
||||
|
||||
@ -37,7 +55,11 @@ export class StreamComponent implements DoCheck {
|
||||
}
|
||||
|
||||
getNicknameTag() {
|
||||
return 'Nickname: ' + JSON.parse(this.stream.connection.data).clientData;
|
||||
return JSON.parse(this.stream.connection.data).clientData;
|
||||
}
|
||||
|
||||
videoClicked() {
|
||||
this.mainVideoStream.next(this.stream);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,14 +1,43 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>OpenviduNg2Example</title>
|
||||
<title>openvidu-insecure-angular</title>
|
||||
<base href="/">
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
|
||||
<!-- Bootstrap -->
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g="
|
||||
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 -->
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-default">
|
||||
<div class="container">
|
||||
<div class="navbar-header">
|
||||
<a class="navbar-brand" href="#">OpenVidu Tutorial</a>
|
||||
<a class="navbar-brand nav-icon" href="https://github.com/OpenVidu/openvidu-tutorials/tree/master/openvidu-insecure-angular" target="_blank"><i class="fa fa-github" aria-hidden="true"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<app-root>Loading...</app-root>
|
||||
|
||||
<footer class="footer">
|
||||
<div class="container">
|
||||
<div class="text-muted">OpenVidu © 2017</div>
|
||||
<a href="http://www.codeurjc.es/" target="_blank"><img src="https://codeurjc.files.wordpress.com/2016/01/logo_cetrado_negro.png?w=275&h=165"/></a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
</html>
|
||||
@ -1 +1,61 @@
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
html {
|
||||
position: relative;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
nav {
|
||||
height: 50px;
|
||||
position: absolute !important;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.navbar-header {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.nav-icon {
|
||||
padding: 5px 15px 5px 15px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
nav i.fa {
|
||||
font-size: 40px;
|
||||
}
|
||||
|
||||
.vertical-center {
|
||||
min-height: 80%;
|
||||
min-height: 80vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.horizontal-center {
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
height: 60px;
|
||||
background-color: #f8f8f8;
|
||||
}
|
||||
|
||||
.footer .text-muted {
|
||||
margin: 20px 0;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.footer img {
|
||||
height: 50px;
|
||||
float: right;
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
#main-video video {
|
||||
cursor: auto;
|
||||
}
|
||||
|
||||
#main-video p {
|
||||
font-size: 22px;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user