mirror of https://github.com/OpenVidu/openvidu.git
REST API tab finished on testapp
parent
64a68bb42e
commit
3a12428be8
|
@ -24,6 +24,7 @@
|
|||
"@angular/platform-browser": "^4.2.4",
|
||||
"@angular/platform-browser-dynamic": "^4.2.4",
|
||||
"@angular/router": "^4.2.4",
|
||||
"colormap": "^2.2.0",
|
||||
"core-js": "^2.4.1",
|
||||
"hammerjs": "^2.0.8",
|
||||
"openvidu-browser": "1.1.0",
|
||||
|
|
|
@ -11,6 +11,10 @@ import {
|
|||
MdDialogModule,
|
||||
MdToolbarModule,
|
||||
MdTabsModule,
|
||||
MdTableModule,
|
||||
MdListModule,
|
||||
MdRadioModule,
|
||||
MdSelectModule,
|
||||
MdSlideToggleModule
|
||||
} from '@angular/material';
|
||||
|
||||
|
@ -27,6 +31,10 @@ import {
|
|||
MdDialogModule,
|
||||
MdToolbarModule,
|
||||
MdTabsModule,
|
||||
MdTableModule,
|
||||
MdListModule,
|
||||
MdRadioModule,
|
||||
MdSelectModule,
|
||||
MdSlideToggleModule
|
||||
],
|
||||
})
|
||||
|
|
|
@ -26,7 +26,9 @@ import { OpenviduRestService } from './services/openvidu-rest.service';
|
|||
FlexLayoutModule,
|
||||
routing
|
||||
],
|
||||
providers: [OpenviduRestService],
|
||||
providers: [
|
||||
OpenviduRestService
|
||||
],
|
||||
bootstrap: [AppComponent]
|
||||
})
|
||||
export class AppModule { }
|
||||
|
|
|
@ -1,3 +1,35 @@
|
|||
.demo-tab-content {
|
||||
margin-top: 50px;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
table tr {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
#table-row {
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.first-col {
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
th {
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
#server-data-field {
|
||||
padding-top: 16px;
|
||||
}
|
||||
|
||||
md-card {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#join-dialog h1 {
|
||||
color: #4d4d4d;
|
||||
font-weight: bold;
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<md-tab-group class="demo-tab-group" dynamicHeight="true">
|
||||
<md-form-field class="example-full-width">
|
||||
<input mdInput placeholder="OpenVidu Server URL" [(ngModel)]="openviduURL">
|
||||
</md-form-field>
|
||||
|
||||
<md-tab-group class="demo-tab-group" dynamicHeight="true" selectedIndex="5">
|
||||
<md-tab id="audio-video" label="Audio + Video">
|
||||
<div class="demo-tab-content">
|
||||
|
||||
|
@ -18,11 +22,72 @@
|
|||
</div>
|
||||
</md-tab>
|
||||
<md-tab id="screen-only" label="Screen only">
|
||||
|
||||
<div class="demo-tab-content">
|
||||
</div>
|
||||
</md-tab>
|
||||
<md-tab id="api-rest" label="API REST">
|
||||
<div class="demo-tab-content">
|
||||
<md-form-field>
|
||||
<input mdInput placeholder="OpenVidu Server Secret" [(ngModel)]="openviduSecret">
|
||||
</md-form-field>
|
||||
<button md-raised-button color="primary" (click)="cleanAllSessions()" style="float: right">Clean sessions</button>
|
||||
|
||||
<div fxLayout="row" fxLayoutGap="20px" fxLayoutAlign="start space-around">
|
||||
<div fxLayout="column" fxFlex="50" fxFlexAlign="center" fxFill>
|
||||
<button md-raised-button color="primary" (click)="getSessionId()">Get sessionId</button>
|
||||
<button md-raised-button color="primary" (click)="getToken()">Get token</button>
|
||||
</div>
|
||||
<div fxLayout="column" fxFlex="50" fxFlexAlign="center" fxFill>
|
||||
<button md-raised-button color="primary" (click)="getToken()" [disabled]="getTokenDisabled()">Get token</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="table-row" fxLayout="row" fxLayoutGap="20px" fxLayoutAlign="start">
|
||||
<div fxLayout="column" fxFlex="65" fxFlexAlign="start" fxFill>
|
||||
<table>
|
||||
<tr>
|
||||
<th class="first-col">sessionIds</th>
|
||||
<th>tokens</th>
|
||||
<th>Session</th>
|
||||
</tr>
|
||||
<tr *ngFor="let sid of this.data; let ind = index">
|
||||
<td class="first-col">
|
||||
<md-card [style.background]="getBackgroundColor(ind)">{{sid[0]}}</md-card>
|
||||
</td>
|
||||
<td>
|
||||
<md-card *ngIf="sid[1].length > 0" [style.background]="getBackgroundColor(ind)">
|
||||
<p *ngFor="let token of sid[1]">{{token}}</p>
|
||||
</md-card>
|
||||
</td>
|
||||
<td style="text-align: center">
|
||||
<md-radio-button [checked]="selectedRadioIndex === ind" (click)="selectedRadioIndex = ind" name="sidOption"></md-radio-button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div fxLayout="column" fxFlex="35" fxFlexAlign="start" fxFill>
|
||||
<table>
|
||||
<tr>
|
||||
<th>OpenVidu Role</th>
|
||||
<th>Server data</th>
|
||||
</tr>
|
||||
<tr id="tr-token-options" *ngIf="data.length > 0">
|
||||
<td>
|
||||
<md-select placeholder="OpenVidu Role" [(ngModel)]="selectedRole">
|
||||
<md-option *ngFor="let role of openViduRoles" [value]="role">
|
||||
{{ role }}
|
||||
</md-option>
|
||||
</md-select>
|
||||
</td>
|
||||
<td>
|
||||
<md-form-field id="server-data-field">
|
||||
<input mdInput placeholder="Server Data" [(ngModel)]="serverData">
|
||||
</md-form-field>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</md-tab>
|
||||
</md-tab-group>
|
||||
|
||||
|
|
|
@ -1,19 +1,49 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { OpenviduRestService } from '../../services/openvidu-rest.service';
|
||||
import { DataSource } from '@angular/cdk/table';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/observable/of';
|
||||
|
||||
import { OpenVidu } from 'openvidu-browser';
|
||||
|
||||
import * as colormap from 'colormap';
|
||||
const numColors = 64;
|
||||
|
||||
declare var $: any;
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard',
|
||||
templateUrl: './dashboard.component.html',
|
||||
styleUrls: ['./dashboard.component.css']
|
||||
styleUrls: ['./dashboard.component.css'],
|
||||
})
|
||||
export class DashboardComponent implements OnInit {
|
||||
|
||||
openviduURL = 'https://localhost:8443';
|
||||
openviduSecret = 'MY_SECRET';
|
||||
serverData = 'data_test';
|
||||
selectedRole = 'PUBLISHER';
|
||||
selectedRadioIndex = 0;
|
||||
|
||||
openViduRoles = ['SUBSCRIBER', 'PUBLISHER', 'MODERATOR'];
|
||||
|
||||
// Join form
|
||||
sessionName: string;
|
||||
clientData: string;
|
||||
|
||||
// API REST data collected
|
||||
data = [];
|
||||
cg;
|
||||
|
||||
constructor(private openviduRestService: OpenviduRestService) {
|
||||
this.generateSessionInfo();
|
||||
const options = {
|
||||
colormap: [
|
||||
{ 'index': 0, 'rgb': [135, 196, 213] },
|
||||
{ 'index': 1, 'rgb': [255, 230, 151] }],
|
||||
nshades: numColors,
|
||||
format: 'hex'
|
||||
};
|
||||
this.cg = colormap(options);
|
||||
}
|
||||
|
||||
ngOnInit() { }
|
||||
|
@ -24,9 +54,9 @@ export class DashboardComponent implements OnInit {
|
|||
}
|
||||
|
||||
private getSessionId() {
|
||||
this.openviduRestService.getSessionId()
|
||||
this.openviduRestService.getSessionId(this.openviduURL, this.openviduSecret)
|
||||
.then((sessionId) => {
|
||||
alert(sessionId);
|
||||
this.updateData();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error getting a sessionId', error);
|
||||
|
@ -34,12 +64,32 @@ export class DashboardComponent implements OnInit {
|
|||
}
|
||||
|
||||
private getToken() {
|
||||
this.openviduRestService.getToken()
|
||||
const sessionId = this.data[this.selectedRadioIndex][0];
|
||||
|
||||
this.openviduRestService.getToken(this.openviduURL, this.openviduSecret, sessionId, this.selectedRole, this.serverData)
|
||||
.then((token) => {
|
||||
alert(token);
|
||||
this.updateData();
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Error getting a token', error);
|
||||
});
|
||||
}
|
||||
|
||||
private updateData() {
|
||||
this.data = Array.from(this.openviduRestService.getAvailableParams());
|
||||
}
|
||||
|
||||
private getTokenDisabled(): boolean {
|
||||
return ((this.data.length === 0) || this.selectedRadioIndex === undefined);
|
||||
}
|
||||
|
||||
private getBackgroundColor(index: number) {
|
||||
return this.cg[((index + 1) * 15) % numColors];
|
||||
}
|
||||
|
||||
private cleanAllSessions() {
|
||||
this.data = [];
|
||||
this.openviduRestService.sessionIdSession.clear();
|
||||
this.openviduRestService.sessionIdTokenOpenViduRole.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,29 +10,49 @@ import { environment } from '../../environments/environment';
|
|||
@Injectable()
|
||||
export class OpenviduRestService {
|
||||
|
||||
sessionIdSession: Map<string, SessionAPI> = new Map();
|
||||
sessionIdTokenOpenViduRole: Map<string, Map<string, OpenViduRoleAPI>> = new Map();
|
||||
|
||||
constructor() { }
|
||||
|
||||
getSessionId(): Promise<String> {
|
||||
const OV = new OpenViduAPI(environment.OPENVIDU_URL, environment.OPENVIDU_SECRET);
|
||||
getSessionId(openviduURL: string, openviduSecret: string): Promise<string> {
|
||||
const OV = new OpenViduAPI(openviduURL, openviduSecret);
|
||||
const session = OV.createSession();
|
||||
|
||||
return new Promise(resolve => {
|
||||
session.getSessionId((sessionId) => {
|
||||
this.sessionIdSession.set(sessionId, session);
|
||||
this.sessionIdTokenOpenViduRole.set(sessionId, new Map());
|
||||
resolve(sessionId);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getToken(): Promise<String> {
|
||||
const OV = new OpenViduAPI(environment.OPENVIDU_URL, environment.OPENVIDU_SECRET);
|
||||
const session = OV.createSession();
|
||||
getToken(openviduURL: string, openviduSecret: string, sessionId: string, role: string, serverData: string): Promise<string> {
|
||||
console.warn(sessionId);
|
||||
|
||||
const OV = new OpenViduAPI(openviduURL, openviduSecret);
|
||||
const session: SessionAPI = this.sessionIdSession.get(sessionId);
|
||||
const OVRole: OpenViduRoleAPI = OpenViduRoleAPI[role];
|
||||
|
||||
return new Promise(resolve => {
|
||||
let tokenOptions: TokenOptionsAPI;
|
||||
session.generateToken((token) => {
|
||||
const tokenOptions: TokenOptionsAPI = new TokenOptionsAPI.Builder()
|
||||
.role(OVRole)
|
||||
.data(serverData)
|
||||
.build();
|
||||
session.generateToken(tokenOptions, (token) => {
|
||||
this.sessionIdTokenOpenViduRole.get(sessionId).set(token, OVRole);
|
||||
resolve(token);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getAvailableParams(): Map<string, string[]> {
|
||||
const params = new Map<string, string[]>();
|
||||
this.sessionIdSession.forEach((sessionApi, sessionId, map) => {
|
||||
params.set(sessionId, Array.from(this.sessionIdTokenOpenViduRole.get(sessionId).keys()));
|
||||
});
|
||||
return params;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha256-k2WSCIexGzOj3Euiig+TlR8gA0EmPjuc79OEeY5L45g="
|
||||
crossorigin="anonymous"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
|
|
@ -16,64 +16,7 @@ a {
|
|||
text-decoration: inherit;
|
||||
}
|
||||
|
||||
|
||||
/* Elevation */
|
||||
|
||||
.z-depth-1 {
|
||||
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -2px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.z-depth-1-half {
|
||||
box-shadow: 0 3px 3px 0 rgba(0, 0, 0, 0.14), 0 1px 7px 0 rgba(0, 0, 0, 0.12), 0 3px 1px -1px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.z-depth-2 {
|
||||
box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.z-depth-3 {
|
||||
box-shadow: 0 6px 10px 0 rgba(0, 0, 0, 0.14), 0 1px 18px 0 rgba(0, 0, 0, 0.12), 0 3px 5px -1px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.z-depth-4 {
|
||||
box-shadow: 0 8px 10px 1px rgba(0, 0, 0, 0.14), 0 3px 14px 2px rgba(0, 0, 0, 0.12), 0 5px 5px -3px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.z-depth-5 {
|
||||
box-shadow: 0 16px 24px 2px rgba(0, 0, 0, 0.14), 0 6px 30px 5px rgba(0, 0, 0, 0.12), 0 8px 10px -5px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
|
||||
/* Colors of Deep Purple Material Theme */
|
||||
|
||||
.back-primary {
|
||||
background: #673ab7 !important;
|
||||
}
|
||||
|
||||
.back-accent {
|
||||
background: #ffd740;
|
||||
}
|
||||
|
||||
.back-warn {
|
||||
background: #f44336;
|
||||
}
|
||||
|
||||
.back-secondary {
|
||||
background: #D1C4E9;
|
||||
}
|
||||
|
||||
.color-primary {
|
||||
color: #673ab7 !important;
|
||||
}
|
||||
|
||||
.color-accent {
|
||||
color: #ffd740;
|
||||
}
|
||||
|
||||
.color-warn {
|
||||
color: #f44336;
|
||||
}
|
||||
|
||||
.color-secondary {
|
||||
color: #D1C4E9;
|
||||
ul {
|
||||
list-style: none;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue