Skip to content

Commit

Permalink
Updated imports in openvidu-webcomponent
Browse files Browse the repository at this point in the history
  • Loading branch information
CSantosM committed Jan 25, 2022
1 parent a73230a commit 262f51a
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 75 deletions.
55 changes: 29 additions & 26 deletions openvidu-components-angular/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ $openvidu-components-theme: mat.define-light-theme((

--ov-light-color: #ffffff;
--ov-light-dark-color: #f1f1f1;
}
}

html, body { height: 100%; overflow: hidden;}
body { margin: 0; font-family: 'Roboto','RobotoDraft',Helvetica,Arial,sans-serif;}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input, OnInit } from "@angular/core";
import { Component, Input, OnInit } from '@angular/core';

export interface SessionConfig {
sessionName: string;
Expand All @@ -7,58 +7,58 @@ export interface SessionConfig {
}

@Component({
template: ` <ov-videoconference
template: `<ov-videoconference
*ngIf="successParams"
[sessionName]="sessionConfig.sessionName"
[userName]="sessionConfig.userName"
[sessionName]="_sessionConfig.sessionName"
[userName]="_sessionConfig.userName"
[openviduServerUrl]="openviduServerUrl"
[openviduSecret]="openviduSecret"
[tokens]="sessionConfig.tokens"
></ov-videoconference>`,
[tokens]="_sessionConfig.tokens"
></ov-videoconference>`
})
export class OpenviduWebComponentComponent implements OnInit {
@Input() openviduServerUrl: string;
@Input() openviduSecret: string;
_sessionConfig: SessionConfig;

successParams: boolean = false;

constructor() {}

ngOnInit(): void {}

@Input("sessionConfig")
@Input('sessionConfig')
set sessionConfig(config: SessionConfig | string) {
console.log("Webcomponent sessionConfig: ", config);
// setTimeout(() => {
if (typeof config === "string") {
console.log('Webcomponent sessionConfig: ', config);
if (typeof config === 'string') {
try {
console.log('STRING')
config = JSON.parse(config);
} catch (error) {
console.error("Unexpected JSON", error);
console.error('Unexpected JSON', error);
throw 'Unexpected JSON';
}
}

if (this.isEmpty(<SessionConfig>config)) {
// Leaving session when sessionConfig is empty
} else {
if (this.isEmpty(config)) {
// Leaving session when sessionConfig is empty
} else {
this.successParams = this.isCorrectParams(config);
if (!this.successParams) {
console.error("Parameters received are incorrect: ", config);
console.error("Session cannot start");
}
console.log("URL",this.openviduServerUrl);
console.log('SECRET',this.openviduSecret);
this.successParams = this.isCorrectParams(<SessionConfig>config);
this._sessionConfig = <SessionConfig>config;
if (!this.successParams) {
console.error('Parameters received are incorrect: ', config);
console.error('Session cannot start');
}
}

// }, 200);
}

private isCorrectParams(config: SessionConfig): boolean {
const canGenerateToken =
!!config.sessionName &&
!!config.userName &&
!!this.openviduServerUrl &&
!!this.openviduSecret;
const hasToken =
!!config.tokens?.webcam && !!config.tokens?.screen && !!config.userName;

console.log(config)
const canGenerateToken = !!config.sessionName && !!config.userName && !!this.openviduServerUrl && !!this.openviduSecret;
const hasToken = !!config.tokens?.webcam && !!config.tokens?.screen && !!config.userName;

return canGenerateToken || hasToken;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
import { BrowserModule } from "@angular/platform-browser";
import { DoBootstrap, Injector, NgModule } from "@angular/core";
import { APP_BASE_HREF, CommonModule } from "@angular/common";
import { createCustomElement, NgElement, WithProperties } from "@angular/elements";
import { OpenviduWebComponentComponent } from "./openvidu-webcomponent.component";
import { BrowserModule } from '@angular/platform-browser';
import { DoBootstrap, Injector, NgModule } from '@angular/core';
import { APP_BASE_HREF, CommonModule } from '@angular/common';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { OpenviduAngularModule, VideoconferenceComponent } from "openvidu-angular";
import { environment } from '../../environments/environment';
import { OpenviduWebComponentComponent } from './openvidu-webcomponent.component';

import { OpenviduAngularModule, VideoconferenceComponent } from 'openvidu-angular';
import { environment } from '../../environments/environment';

declare global {
interface HTMLElementTagNameMap {
'openvidu-webcomponent': NgElement & WithProperties<{ openviduServerUrl: string, openviduSecret: string}>;
}
}
import { createCustomElement } from '@angular/elements';

@NgModule({
declarations: [OpenviduWebComponentComponent],
imports: [
CommonModule,
BrowserModule,
OpenviduAngularModule.forRoot(environment),
],
imports: [CommonModule, BrowserModule, BrowserAnimationsModule, OpenviduAngularModule.forRoot(environment)],
// exports: [OpenviduWebComponentComponent],
providers: [{provide: APP_BASE_HREF, useValue: '/'} , VideoconferenceComponent],
providers: [{ provide: APP_BASE_HREF, useValue: '/' }, VideoconferenceComponent]
})
export class OpenviduWebComponentModule implements DoBootstrap {
constructor(private injector: Injector) {}

ngDoBootstrap(): void {
const element = createCustomElement(OpenviduWebComponentComponent, {
injector: this.injector,
injector: this.injector
});

customElements.define("openvidu-webcomponent", element);
customElements.define('openvidu-webcomponent', element);
}
}

0 comments on commit 262f51a

Please sign in to comment.