Skip to content
Snippets Groups Projects
Commit f666fa5d authored by guillaum.riondet's avatar guillaum.riondet
Browse files

Save audio board and get correct audio on switch shape works

parent aef4a86e
No related branches found
No related tags found
No related merge requests found
Showing
with 209 additions and 85 deletions
# Frontend variables. # Frontend variables
BOARDS_FRONTEND_PORT=4200 BOARDS_FRONTEND_PORT=4200
ELECTRON='false' ELECTRON='false'
......
...@@ -44,6 +44,14 @@ try { ...@@ -44,6 +44,14 @@ try {
} }
break; break;
case 'audios':
if ($key) {
$preparedStatement = $db->prepare('SELECT * FROM `audios` WHERE idBoard = :idBoard');
$preparedStatement->bindValue('idBoard', $key, PDO::PARAM_INT);
$preparedStatement->execute();
$rep = $preparedStatement->fetchAll(PDO::FETCH_ASSOC);
}
break;
} }
break; break;
...@@ -60,6 +68,7 @@ try { ...@@ -60,6 +68,7 @@ try {
'hash' => filter_var($receivedData['hash'], FILTER_SANITIZE_STRING), 'hash' => filter_var($receivedData['hash'], FILTER_SANITIZE_STRING),
'title' => filter_var($receivedData['title'], FILTER_SANITIZE_STRING), 'title' => filter_var($receivedData['title'], FILTER_SANITIZE_STRING),
'creatorId' => filter_var($receivedData['creatorId'], FILTER_VALIDATE_INT), 'creatorId' => filter_var($receivedData['creatorId'], FILTER_VALIDATE_INT),
'currentShapeID' => filter_var($receivedData['currentShapeID'], FILTER_VALIDATE_INT),
); );
if (empty($receivedData['graphics'])) { if (empty($receivedData['graphics'])) {
...@@ -72,9 +81,9 @@ try { ...@@ -72,9 +81,9 @@ try {
$sql = <<<'END' $sql = <<<'END'
INSERT INTO boards INSERT INTO boards
(`uid`, `creatorId`, `title`, `height`, `width`, `hash`, `graphics`, `creationDate`) (`uid`, `creatorId`, `title`, `height`, `width`, `hash`, `graphics`, `creationDate`, `currentShapeID`)
VALUES VALUES
(NULL, :creatorId, :title, :height, :width, :hash, :graphics, NOW()); (NULL, :creatorId, :title, :height, :width, :hash, :graphics, NOW(), :currentShapeID);
END; END;
try { try {
...@@ -85,6 +94,7 @@ try { ...@@ -85,6 +94,7 @@ try {
$preparedStatement->bindValue('title', $validationData['title'], PDO::PARAM_STR); $preparedStatement->bindValue('title', $validationData['title'], PDO::PARAM_STR);
$preparedStatement->bindValue('width', $validationData['width'], PDO::PARAM_INT); $preparedStatement->bindValue('width', $validationData['width'], PDO::PARAM_INT);
$preparedStatement->bindValue('hash', $validationData['hash'], PDO::PARAM_STR); $preparedStatement->bindValue('hash', $validationData['hash'], PDO::PARAM_STR);
$preparedStatement->bindValue('currentShapeID', $validationData['currentShapeID'], PDO::PARAM_STR);
// graphics on the map // graphics on the map
...@@ -110,54 +120,38 @@ try { ...@@ -110,54 +120,38 @@ try {
} }
break; break;
case 'audio': case 'audios':
/* /*
* insert a map in the DB and get back the id * insert a map in the DB and get back the id
*/ */
$receivedData = json_decode(file_get_contents('php://input'), true); $receivedData = json_decode(file_get_contents('php://input'), true);
$validationData = array( $validationData = array(
'idBoard' => filter_var($receivedData['idBoard'], FILTER_VALIDATE_INT), 'idBoard' => filter_var($receivedData['idBoard'], FILTER_VALIDATE_INT),
'idShape' => filter_var($receivedData['idShape'], FILTER_VALIDATE_INT), 'idShape' => filter_var($receivedData['idShape'], FILTER_VALIDATE_INT),
'hash' => filter_var($receivedData['hash'], FILTER_SANITIZE_STRING), 'audioEncoded' => filter_var($receivedData['audioEncoded'], FILTER_SANITIZE_STRING),
'audio' => filter_var($receivedData['audio'], FILTER_SANITIZE_STRING), 'audioName' => filter_var($receivedData['audioName'], FILTER_SANITIZE_STRING),
); );
if (empty($receivedData['graphics'])) {
$validationData['graphics'] = null;
} else {
$validationData['graphics'] = json_encode($receivedData['graphics']);
}
$rep = $validationData; $rep = $validationData;
$sql = <<<'END' $sql = <<<'END'
INSERT INTO boards INSERT INTO audios
(`uid`, `creatorId`, `title`, `height`, `width`, `hash`, `graphics`, `creationDate`) (`idBoard`, `idShape`, `audioName`, `audioEncoded`, `creationDate`)
VALUES VALUES
(NULL, :creatorId, :title, :height, :width, :hash, :graphics, NOW()); (:idBoard, :idShape, :audioName, :audioEncoded, NOW());
END; END;
try { try {
$preparedStatement = $db->prepare($sql); $preparedStatement = $db->prepare($sql);
$preparedStatement->bindValue('creatorId', $validationData['creatorId'], PDO::PARAM_INT); $preparedStatement->bindValue('idBoard', $validationData['idBoard'], PDO::PARAM_INT);
$preparedStatement->bindValue('height', $validationData['height'], PDO::PARAM_INT); $preparedStatement->bindValue('idShape', $validationData['idShape'], PDO::PARAM_INT);
$preparedStatement->bindValue('title', $validationData['title'], PDO::PARAM_STR); $preparedStatement->bindValue('audioName',$validationData['audioName'], PDO::PARAM_STR);
$preparedStatement->bindValue('width', $validationData['width'], PDO::PARAM_INT); $preparedStatement->bindValue('audioEncoded',$validationData['audioEncoded'], PDO::PARAM_STR);
$preparedStatement->bindValue('hash', $validationData['hash'], PDO::PARAM_STR);
// graphics on the map
if (is_null($validationData['graphics'])) {
$preparedStatement->bindValue('graphics', null, PDO::PARAM_NULL);
} else {
$preparedStatement->bindValue('graphics', $validationData['graphics'], PDO::PARAM_STR);
}
$preparedStatement->execute(); $preparedStatement->execute();
$id= $db->lastInsertId();
$rep = array('id' => $id);
} catch (Exception $e) { } catch (Exception $e) {
if ($conf['displayError']) { if ($conf['displayError']) {
......
...@@ -68,6 +68,8 @@ COMMIT; ...@@ -68,6 +68,8 @@ COMMIT;
CREATE TABLE `audios` ( CREATE TABLE `audios` (
`idBoard` INT NOT NULL , `idBoard` INT NOT NULL ,
`idShape` INT NOT NULL , `idShape` INT NOT NULL ,
`audioBlob` MEDIUMBLOB NOT NULL , `audioName` varchar(255) DEFAULT NULL,
`audioEncoded` longtext DEFAULT NULL,
`creationDate` datetime NOT NULL,
PRIMARY KEY (`idBoard`,`idShape`) PRIMARY KEY (`idBoard`,`idShape`)
) ENGINE = InnoDB; ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
{ {
"_from": "@fortawesome/free-solid-svg-icons", "_from": "@fortawesome/free-solid-svg-icons@^5.14.0",
"_id": "@fortawesome/free-solid-svg-icons@5.14.0", "_id": "@fortawesome/free-solid-svg-icons@5.14.0",
"_inBundle": false, "_inBundle": false,
"_integrity": "sha512-M933RDM8cecaKMWDSk3FRYdnzWGW7kBBlGNGfvqLVwcwhUPNj9gcw+xZMrqBdRqxnSXdl3zWzTCNNGEtFUq67Q==", "_integrity": "sha512-M933RDM8cecaKMWDSk3FRYdnzWGW7kBBlGNGfvqLVwcwhUPNj9gcw+xZMrqBdRqxnSXdl3zWzTCNNGEtFUq67Q==",
"_location": "/@fortawesome/free-solid-svg-icons", "_location": "/@fortawesome/free-solid-svg-icons",
"_phantomChildren": {}, "_phantomChildren": {},
"_requested": { "_requested": {
"type": "tag", "type": "range",
"registry": true, "registry": true,
"raw": "@fortawesome/free-solid-svg-icons", "raw": "@fortawesome/free-solid-svg-icons@^5.14.0",
"name": "@fortawesome/free-solid-svg-icons", "name": "@fortawesome/free-solid-svg-icons",
"escapedName": "@fortawesome%2ffree-solid-svg-icons", "escapedName": "@fortawesome%2ffree-solid-svg-icons",
"scope": "@fortawesome", "scope": "@fortawesome",
"rawSpec": "", "rawSpec": "^5.14.0",
"saveSpec": null, "saveSpec": null,
"fetchSpec": "latest" "fetchSpec": "^5.14.0"
}, },
"_requiredBy": [ "_requiredBy": [
"#USER", "#USER",
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
], ],
"_resolved": "https://registry.npmjs.org/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-5.14.0.tgz", "_resolved": "https://registry.npmjs.org/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-5.14.0.tgz",
"_shasum": "970453f5e8c4915ad57856c3a0252ac63f6fec18", "_shasum": "970453f5e8c4915ad57856c3a0252ac63f6fec18",
"_spec": "@fortawesome/free-solid-svg-icons", "_spec": "@fortawesome/free-solid-svg-icons@^5.14.0",
"_where": "/home/reddevil/Documents/abaplans/boards/frontend", "_where": "/home/reddevil/Documents/abaplans/boards/frontend",
"author": { "author": {
"name": "Dave Gandy", "name": "Dave Gandy",
......
...@@ -36,8 +36,16 @@ ...@@ -36,8 +36,16 @@
margin: 4px 10px 0px; margin: 4px 10px 0px;
} }
.btns {
border: 1px solid white;
}
.btn { .btn {
border: 1px solid white; border: 1px solid white;
margin: 7px 0px 10px 3px;
border-style: solid;
border-width: 1px;
border-radius: 5px;
} }
.toolbar { .toolbar {
......
...@@ -25,9 +25,24 @@ ...@@ -25,9 +25,24 @@
<!-- Drawing tools buttons --> <!-- Drawing tools buttons -->
<div> <div>
<div class="buttons-group"> <div class="buttons-group">
<div class="buttons-group">
<div class= btn-group>
<label class="btn btn-secondary" for="files">Choisir un arrière plan</label>
<input id="files" type="file" style="display:none;" (change)="handle($event.target.files)" accept=".jpeg,.png,.jpg">
</div>
<button
class="btns btn-secondary toolbar-button"
tooltip="Modif arrière plan"
placement="bottom"
(click)='editBackImg()'>
</button>
</div>
<div class="buttons-group"> <div class="buttons-group">
<button <button
class="btn btn-secondary toolbar-button" class="btns btn-secondary toolbar-button"
[ngClass]="{selected: selectedButton['ellipse']===true}" [ngClass]="{selected: selectedButton['ellipse']===true}"
tooltip="Ellipse" tooltip="Ellipse"
placement="bottom" placement="bottom"
...@@ -35,7 +50,7 @@ ...@@ -35,7 +50,7 @@
<!-- <fa-icon [icon]="faCircle"></fa-icon> --> <!-- <fa-icon [icon]="faCircle"></fa-icon> -->
</button> </button>
<button <button
class="btn btn-secondary toolbar-button" class="btns btn-secondary toolbar-button"
[ngClass]="{selected: selectedButton['rectangle']===true}" [ngClass]="{selected: selectedButton['rectangle']===true}"
tooltip="Rectangle" tooltip="Rectangle"
placement="bottom" placement="bottom"
...@@ -43,7 +58,7 @@ ...@@ -43,7 +58,7 @@
<!-- <fa-icon [icon]="faCircle"></fa-icon> --> <!-- <fa-icon [icon]="faCircle"></fa-icon> -->
</button> </button>
<button <button
class="btn btn-secondary toolbar-button" class="btns btn-secondary toolbar-button"
[ngClass]="{selected: selectedButton['line']===true}" [ngClass]="{selected: selectedButton['line']===true}"
tooltip="Ligne" tooltip="Ligne"
placement="bottom" placement="bottom"
...@@ -51,7 +66,7 @@ ...@@ -51,7 +66,7 @@
<!-- <fa-icon [icon]="faCircle"></fa-icon> --> <!-- <fa-icon [icon]="faCircle"></fa-icon> -->
</button> </button>
<button <button
class="btn btn-secondary toolbar-button" class="btns btn-secondary toolbar-button"
[ngClass]="{selected: selectedButton['polygon']===true}" [ngClass]="{selected: selectedButton['polygon']===true}"
tooltip="Polygone" tooltip="Polygone"
placement="bottom" placement="bottom"
...@@ -59,7 +74,7 @@ ...@@ -59,7 +74,7 @@
<!-- <fa-icon [icon]="faCircle"></fa-icon> --> <!-- <fa-icon [icon]="faCircle"></fa-icon> -->
</button> </button>
<button <button
class="btn btn-secondary toolbar-button" class="btns btn-secondary toolbar-button"
[ngClass]="{selected: selectedButton['pencil']===true}" [ngClass]="{selected: selectedButton['pencil']===true}"
tooltip="Crayon" tooltip="Crayon"
placement="bottom" placement="bottom"
...@@ -70,19 +85,13 @@ ...@@ -70,19 +85,13 @@
<div class="buttons-group"> <div class="buttons-group">
<button <button
class="btn btn-secondary toolbar-button" class="btns btn-secondary toolbar-button"
tooltip="Modif arrière plan"
placement="bottom"
(click)='changeBackImg()'>
</button>
<button
class="btn btn-secondary toolbar-button"
tooltip="Sauvegarder" tooltip="Sauvegarder"
placement="bottom" placement="bottom"
(click)='save()'> (click)='save()'>
</button> </button>
<button <button
class="btn btn-secondary toolbar-button" class="btns btn-secondary toolbar-button"
tooltip="Imprimer" tooltip="Imprimer"
placement="bottom" placement="bottom"
(click)='print()'> (click)='print()'>
......
...@@ -11,14 +11,14 @@ export class NavComponent implements OnInit { ...@@ -11,14 +11,14 @@ export class NavComponent implements OnInit {
@Output() setShape = new EventEmitter<String>(); @Output() setShape = new EventEmitter<String>();
@Output() saveBoard = new EventEmitter<any>(); @Output() saveBoard = new EventEmitter<any>();
@Output() printBoard = new EventEmitter<any>(); @Output() printBoard = new EventEmitter<any>();
@Output() changeBackgroundImg = new EventEmitter<any>(); @Output() editBackgroundImg = new EventEmitter<any>();
@Output() changeBackgroundImg = new EventEmitter<string>();
constructor(private shapeService: ShapeService) { } constructor(private shapeService: ShapeService) { }
ngOnInit(): void { ngOnInit(): void {
console.log("init"); console.log("init");
} }
select(param: string){ select(param: string){
this.setShape.emit(param); this.setShape.emit(param);
} }
...@@ -31,7 +31,14 @@ export class NavComponent implements OnInit { ...@@ -31,7 +31,14 @@ export class NavComponent implements OnInit {
this.printBoard.emit(); this.printBoard.emit();
} }
changeBackImg(){ editBackImg(){
this.changeBackgroundImg.emit(); this.editBackgroundImg.emit();
}
handle(file : FileList){
console.log(file);
const url = URL.createObjectURL(file[0]);
console.log(url);
this.changeBackgroundImg.emit(url);
} }
} }
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<button (click)="initiateRecording()" class="btn btn-primary" *ngIf="!recording"> Start Recording </button> <button (click)="initiateRecording()" class="btn btn-primary" *ngIf="!recording"> Start Recording </button>
<button (click)="stopRecording()" class="btn btn-danger" *ngIf="recording"> Stop Recording </button> <button (click)="stopRecording()" class="btn btn-danger" *ngIf="recording"> Stop Recording </button>
<div class="clearfix"></div> <div class="clearfix"></div>
<audio controls="" *ngIf="selectedShape && shapeAudio[selectedShape.getAttr('id')]">
<audio id=audio controls="" *ngIf="selectedShape && shapeAudio[selectedShape.getAttr('id')]">
<source [src]="sanitize(shapeAudio[selectedShape.getAttr('id')])" type="audio/wav"> <source [src]="sanitize(shapeAudio[selectedShape.getAttr('id')])" type="audio/wav">
</audio> </audio>
</div> </div>
...@@ -23,9 +23,23 @@ export class RecorderComponent { ...@@ -23,9 +23,23 @@ export class RecorderComponent {
constructor(private domSanitizer: DomSanitizer) { constructor(private domSanitizer: DomSanitizer) {
} }
sanitize(url:string){ sanitize(url:string){
console.log(url)
return this.domSanitizer.bypassSecurityTrustUrl(url); return this.domSanitizer.bypassSecurityTrustUrl(url);
} }
ngOnChanges(): void {
this.loadAudioInPlayer()
}
loadAudioInPlayer(){
if(this.selectedShape && this.shapeAudio[this.selectedShape.getAttr('id')]){
let audio = document.getElementById('audio') as HTMLMediaElement
if(audio){
console.log(audio)
audio.src = this.shapeAudio[this.selectedShape.getAttr('id')]
audio.load()
}
}
}
/** /**
* Start recording. * Start recording.
*/ */
...@@ -66,14 +80,8 @@ export class RecorderComponent { ...@@ -66,14 +80,8 @@ export class RecorderComponent {
*/ */
async processRecording(blob) { async processRecording(blob) {
this.url = URL.createObjectURL(blob); this.url = URL.createObjectURL(blob);
console.log(this.shapeAudio[this.selectedShape.getAttr('id')]);
console.log(blob);
let blobFromURL = await fetch(this.url).then(r => r.blob());
console.log(blobFromURL)
this.shapeAudio[this.selectedShape.getAttr('id')]=this.url; this.shapeAudio[this.selectedShape.getAttr('id')]=this.url;
console.log(this.shapeAudio); this.loadAudioInPlayer();
} }
/** /**
* Process Error. * Process Error.
...@@ -82,4 +90,5 @@ export class RecorderComponent { ...@@ -82,4 +90,5 @@ export class RecorderComponent {
this.error = 'Can not play audio in your browser'; this.error = 'Can not play audio in your browser';
} }
} }
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import { environment } from '../../../environments/environment'; import { environment } from '../../../environments/environment';
import { Board, Drawing } from './utils'; import { Board, Audio } from './utils';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
...@@ -31,6 +31,15 @@ export class BoardsDatabaseService { ...@@ -31,6 +31,15 @@ export class BoardsDatabaseService {
return this.http.get<Board>(`${environment.boardServerUrl}/boards/${uid}`).toPromise(); return this.http.get<Board>(`${environment.boardServerUrl}/boards/${uid}`).toPromise();
} }
/**
* Get the list of all existing maps on the maps server.
*
* @returns A Promise containing the list of maps saved on the maps server.
*/
async getAudios(idBoard :string): Promise<Audio[]> {
return this.http.get<Audio[]>(`${environment.boardServerUrl}/audios/${idBoard}`).toPromise();
}
/** /**
* Save a new map on the maps server. * Save a new map on the maps server.
* *
...@@ -54,7 +63,30 @@ export class BoardsDatabaseService { ...@@ -54,7 +63,30 @@ export class BoardsDatabaseService {
title: board.title, title: board.title,
height: board.height, height: board.height,
width: board.width, width: board.width,
graphics: board.graphics graphics: board.graphics,
currentShapeID: board.currentShapeID
},
httpOptions
).toPromise();
}
async saveAudio(audio : Audio): Promise<{}> {
// Set the http header to avoid sending an OPTIONS request before the POST,
// which would cause CORS issues.
console.log(`${environment.boardServerUrl}/audio/`)
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'text/plain',
})
};
return this.http.post<{id: number}>(
`${environment.boardServerUrl}/audios/`,
{
idBoard: audio.idBoard,
idShape: audio.idShape,
audioName : audio.audioName,
audioEncoded : audio.audioEncoded
}, },
httpOptions httpOptions
).toPromise(); ).toPromise();
......
...@@ -8,13 +8,12 @@ export interface Board { ...@@ -8,13 +8,12 @@ export interface Board {
height?: number; height?: number;
width?: number; width?: number;
graphics?: string; graphics?: string;
currentShapeID :number, currentShapeID :number;
} }
export interface Drawing { export interface Audio {
uid?: number; idBoard : string;
title: string; idShape : string;
height?: number; audioName : string;
width?: number; audioEncoded : string;
graphics?: string;
} }
<app-nav (setShape)="setSelection($event); addShape($event)" [selectedButton]="selectedButton" (saveBoard)="saveBoard()" (printBoard)="printBoard()" (changeBackgroundImg)="activeChangeOnBackground()"></app-nav> <app-nav (setShape)="setSelection($event); addShape($event)" [selectedButton]="selectedButton" (saveBoard)="saveBoard()" (printBoard)="printBoard()" (changeBackgroundImg)="addBackground($event)" (editBackgroundImg)="editBackground()"></app-nav>
<table> <table>
<tr> <tr>
<td id=aside width=100%> <td id=aside width=100%>
......
...@@ -5,7 +5,7 @@ import { ShapeService } from '../shape/shape.service'; ...@@ -5,7 +5,7 @@ import { ShapeService } from '../shape/shape.service';
import { PrinterService } from '../printer/printer.service'; import { PrinterService } from '../printer/printer.service';
import { BoardsDatabaseService } from './boards-database/boards-database.service'; import { BoardsDatabaseService } from './boards-database/boards-database.service';
import { NavComponent } from '../nav/nav.component'; import { NavComponent } from '../nav/nav.component';
import { Board } from './boards-database/utils'; import { Board, Audio } from './boards-database/utils';
import { MainMenuComponent } from './main-menu/main-menu.component'; import { MainMenuComponent } from './main-menu/main-menu.component';
import { ModalModule } from 'ngx-bootstrap/modal'; import { ModalModule } from 'ngx-bootstrap/modal';
import { BoardsMenuComponent } from './boards-menu/boards-menu.component'; import { BoardsMenuComponent } from './boards-menu/boards-menu.component';
...@@ -23,6 +23,7 @@ export class WhiteboardPageComponent implements OnInit { ...@@ -23,6 +23,7 @@ export class WhiteboardPageComponent implements OnInit {
@ViewChild('boardsMenu') private boardsMenuModal: BoardsMenuComponent; @ViewChild('boardsMenu') private boardsMenuModal: BoardsMenuComponent;
@ViewChild('availableSpace') private availableSpace: ElementRef<HTMLDivElement>; @ViewChild('availableSpace') private availableSpace: ElementRef<HTMLDivElement>;
@ViewChild('container') private container: ElementRef<HTMLDivElement>; @ViewChild('container') private container: ElementRef<HTMLDivElement>;
@ViewChild('audioPlayer') audioPlayerRef: ElementRef<HTMLAudioElement>;
width: number = window.innerWidth-330; width: number = window.innerWidth-330;
height: number = window.innerHeight-104; height: number = window.innerHeight-104;
...@@ -46,7 +47,7 @@ export class WhiteboardPageComponent implements OnInit { ...@@ -46,7 +47,7 @@ export class WhiteboardPageComponent implements OnInit {
private openedBoard: Board; private openedBoard: Board;
boardId = ''; boardId = '';
boardTitle = ''; boardTitle = '';
backgroundImg: Konva.Image; backgroundImg: Konva.Image = null;
constructor( constructor(
...@@ -77,8 +78,6 @@ export class WhiteboardPageComponent implements OnInit { ...@@ -77,8 +78,6 @@ export class WhiteboardPageComponent implements OnInit {
this.addDeleteListener(); this.addDeleteListener();
//this.addBackground(); //this.addBackground();
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
...@@ -93,8 +92,10 @@ export class WhiteboardPageComponent implements OnInit { ...@@ -93,8 +92,10 @@ export class WhiteboardPageComponent implements OnInit {
this.boardsMenuModal.open = false; this.boardsMenuModal.open = false;
const board = await this.boardsDbService.getBoard(id); const board = await this.boardsDbService.getBoard(id);
this.openedBoard = board; this.openedBoard = board;
this.boardId = '' + board.uid;
this.boardTitle = board.title;
this.currentShapeID = board.currentShapeID; this.currentShapeID = board.currentShapeID;
console.log(this.openedBoard.graphics) await this.loadAudios();
this.stage = Konva.Node.create(this.openedBoard.graphics, 'container'); this.stage = Konva.Node.create(this.openedBoard.graphics, 'container');
this.layer = (this.stage.getLayers().toArray()[0] as Konva.Layer); this.layer = (this.stage.getLayers().toArray()[0] as Konva.Layer);
this.initTextures(); this.initTextures();
...@@ -111,6 +112,29 @@ export class WhiteboardPageComponent implements OnInit { ...@@ -111,6 +112,29 @@ export class WhiteboardPageComponent implements OnInit {
this.mainMenuModal.open = true; this.mainMenuModal.open = true;
}; };
} }
b64toBlob(dataURI) {
var byteString = atob(dataURI.split(',')[1]);
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ab], { type: 'audio/wav' });
}
private async loadAudios(){
var audios : Audio[] = await this.boardsDbService.getAudios(this.boardId);
for(let audio of audios){
let blob = this.b64toBlob(audio.audioEncoded);
let blobUrl = URL.createObjectURL(blob);
this.shapeAudio[audio.idShape]=blobUrl;
}
}
private resizeBoardView() { private resizeBoardView() {
// it from influencing the availableSpace container's size. // it from influencing the availableSpace container's size.
let availableSpaceWidth = window.innerWidth-330; let availableSpaceWidth = window.innerWidth-330;
...@@ -185,15 +209,18 @@ export class WhiteboardPageComponent implements OnInit { ...@@ -185,15 +209,18 @@ export class WhiteboardPageComponent implements OnInit {
} }
addBackground(){ addBackground(fileURL : string){
var component = this var component = this
var imageObj = new Image(); var imageObj = new Image();
if(component.backgroundImg != null){
imageObj.src = '/assets/swiss.jpg'; component.backgroundImg.remove();
}
imageObj.src = fileURL;
imageObj.onload = function() { imageObj.onload = function() {
var background = new Konva.Image({ var background = new Konva.Image({
x: 0, x: 0,
y: 0, y: 0,
zIndex: 0,
image: imageObj, image: imageObj,
draggable:false, draggable:false,
listening : false, listening : false,
...@@ -201,13 +228,16 @@ export class WhiteboardPageComponent implements OnInit { ...@@ -201,13 +228,16 @@ export class WhiteboardPageComponent implements OnInit {
// add the image to the layer // add the image to the layer
component.layer.add(background); component.layer.add(background);
component.backgroundImg = background; component.backgroundImg = background;
component.backgroundImg.moveToBottom();
component.layer.batchDraw(); component.layer.batchDraw();
}; };
} }
activeChangeOnBackground(){ editBackground(){
this.backgroundImg.listening(!this.backgroundImg.listening()); this.backgroundImg.listening(!this.backgroundImg.listening());
this.backgroundImg.draggable(!this.backgroundImg.draggable()); this.backgroundImg.draggable(!this.backgroundImg.draggable());
this.layer.batchDraw()
} }
addShape(type: string) { addShape(type: string) {
this.clearSelection(); this.clearSelection();
...@@ -410,6 +440,11 @@ export class WhiteboardPageComponent implements OnInit { ...@@ -410,6 +440,11 @@ export class WhiteboardPageComponent implements OnInit {
console.log(component.transformers) console.log(component.transformers)
component.layer.batchDraw(); component.layer.batchDraw();
component.selectedShape = tr.nodes()[0]; component.selectedShape = tr.nodes()[0];
// document.getElementById('audioPlayer').load();
} }
else { else {
tr.detach(); tr.detach();
...@@ -417,6 +452,7 @@ export class WhiteboardPageComponent implements OnInit { ...@@ -417,6 +452,7 @@ export class WhiteboardPageComponent implements OnInit {
component.layer.batchDraw(); component.layer.batchDraw();
component.selectedShape = null; component.selectedShape = null;
} }
}); });
tr.on('transform', function () { tr.on('transform', function () {
var shape = tr.nodes()[0]; var shape = tr.nodes()[0];
...@@ -429,6 +465,7 @@ export class WhiteboardPageComponent implements OnInit { ...@@ -429,6 +465,7 @@ export class WhiteboardPageComponent implements OnInit {
// shape.scaleY(1); // shape.scaleY(1);
}); });
} }
addDeleteListener() { addDeleteListener() {
const component = this; const component = this;
...@@ -486,9 +523,35 @@ export class WhiteboardPageComponent implements OnInit { ...@@ -486,9 +523,35 @@ export class WhiteboardPageComponent implements OnInit {
this.boardId = '' + newUid.id; this.boardId = '' + newUid.id;
this.boardTitle = mapTitle; this.boardTitle = mapTitle;
message = "Plan sauvegardé avec succès"; var blobToBase64 = blob => {
alert(message); var reader = new FileReader();
reader.readAsDataURL(blob);
return new Promise(resolve => {
reader.onloadend = () => {
resolve(reader.result);
};
});
};
for (const [key, url] of Object.entries(this.shapeAudio)) {
let audio :Audio;
let audioEncoded;
let blobFromURL = await fetch(url).then(r => r.blob());
await blobToBase64(blobFromURL).then(res => {
audioEncoded = res;
});
audio = {
idBoard : this.boardId,
idShape : key,
audioName : this.boardId + '-' + key,
audioEncoded : '' + audioEncoded
}
await this.boardsDbService.saveAudio(audio);
}
message = "ok";
alert(message);
} catch (error) { } catch (error) {
message = "Une erreur s'est produite lors de la sauvegarde du plan"; message = "Une erreur s'est produite lors de la sauvegarde du plan";
alert(message); alert(message);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment