Merge branch 'feature/shared-content' of https://bitbucket.org/equilibriumito/gabinete-digital-fo into feature/shared-content

This commit is contained in:
Eudes Inácio
2023-12-13 17:09:08 +01:00
13 changed files with 251 additions and 19 deletions
@@ -1,5 +1,5 @@
import { Directive, ElementRef, Input } from '@angular/core';
import { StopvideoService } from "src/app/services/stopvideo.service";
@Directive({
selector: '[appVisibility]'
})
@@ -8,7 +8,10 @@ export class VisibilityDirective {
intersectionObserver: IntersectionObserver;
@Input() appVisibility: (arg: any) => void;
constructor(private elementRef: ElementRef) {
constructor(
private elementRef: ElementRef,
private stopvideoService: StopvideoService
) {
const options = {
root: null,
rootMargin: '0px',
@@ -16,12 +19,13 @@ export class VisibilityDirective {
};
console.log(this.elementRef.nativeElement.parentElement, "=1=")
// this.stopvideoService.registerVideo()
this.intersectionObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
this.appVisibility(true);
this.stopvideoService.registerVideo(this.elementRef.nativeElement);
} else {
this.elementRef.nativeElement.pause()
// Pause video when not visible
@@ -1,4 +1,5 @@
import { Directive, ElementRef, Input } from '@angular/core';
import { StopvideoService } from '../stopvideo.service';
@Directive({
selector: '[appVisibility]'
@@ -8,7 +9,10 @@ export class VisibilityDirective {
intersectionObserver: IntersectionObserver;
@Input() appVisibility: (arg: any) => void;
constructor(private elementRef: ElementRef) {
constructor(
private elementRef: ElementRef,
private stopvideoService: StopvideoService
) {
const options = {
root: null,
rootMargin: '0px',
@@ -16,12 +20,11 @@ export class VisibilityDirective {
};
console.log(this.elementRef.nativeElement.parentElement, "=1=")
this.intersectionObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
this.appVisibility(true);
this.stopvideoService.registerVideo(this.elementRef.nativeElement)
} else {
this.elementRef.nativeElement.pause()
// Pause video when not visible
@@ -1,6 +1,6 @@
import { HttpClient, HttpContext, HttpHeaders, HttpParams } from '@angular/common/http';
import { HttpContext, HttpHeaders, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
// import { Result, err, ok } from 'neverthrow'
import { HttpClient, HttpResponse, HttpErrorResponse } from '@angular/common/http';
import { tap, shareReplay, catchError } from "rxjs/operators";
import { Observable, of } from "rxjs";
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { StopvideoService } from './stopvideo.service';
describe('StopvideoService', () => {
let service: StopvideoService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(StopvideoService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
+45
View File
@@ -0,0 +1,45 @@
import { Injectable } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class StopvideoService {
video: HTMLVideoElement[] = []
constructor(
private router: Router
) {
this.router.events.forEach((event) => {
if (event instanceof NavigationEnd && !event.url.includes('/home/publications')) {
this.stopAndRemoveAllVideos();
}
});
}
registerVideo(tagVideo: HTMLVideoElement) {
this.video.push(tagVideo);
}
stopAndRemoveAllVideos() {
for (let i = 0; i < this.video.length; i++) {
const video = this.video[i];
// Pause the video
video.pause();
// Optionally, you can also reset the current time to start from the beginning
video.currentTime = 0;
// Remove the video from the array
this.video.splice(i, 1);
// Decrement the index to properly continue the loop
i--;
}
}
}