2022-04-05 15:58:12 +02:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
import { TokenModel, Signal } from 'openvidu-angular';
|
|
|
|
import { Session, SignalOptions } from 'openvidu-browser';
|
|
|
|
import { RestService } from 'src/app/services/rest.service';
|
2022-04-01 12:05:58 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-chatPanel-directive',
|
2022-04-05 15:58:12 +02:00
|
|
|
template: `
|
|
|
|
<ov-videoconference
|
|
|
|
(onJoinButtonClicked)="onJoinButtonClicked()"
|
|
|
|
(onSessionCreated)="onSessionCreated($event)"
|
|
|
|
[tokens]="tokens"
|
|
|
|
[toolbarDisplaySessionName]="false"
|
|
|
|
>
|
|
|
|
<div *ovChatPanel id="my-panel">
|
|
|
|
<h3>Chat</h3>
|
|
|
|
<div>
|
|
|
|
<ul>
|
|
|
|
<li *ngFor="let msg of messages">{{ msg }}</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<input value="Hello" #input />
|
|
|
|
<button (click)="send(input.value)">Send</button>
|
|
|
|
</div>
|
|
|
|
</ov-videoconference>
|
|
|
|
`,
|
|
|
|
styles: [
|
|
|
|
`
|
|
|
|
#my-panel {
|
|
|
|
background: #aafffc;
|
|
|
|
height: 100%;
|
|
|
|
overflow: hidden;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
`
|
|
|
|
]
|
2022-04-01 12:05:58 +02:00
|
|
|
})
|
2022-04-05 15:58:12 +02:00
|
|
|
export class ChatPanelDirectiveComponent {
|
|
|
|
tokens: TokenModel;
|
|
|
|
sessionId = 'chat-panel-directive-example';
|
|
|
|
OPENVIDU_URL = 'https://localhost:4443';
|
|
|
|
OPENVIDU_SECRET = 'MY_SECRET';
|
|
|
|
session: Session;
|
|
|
|
messages: string[] = [];
|
|
|
|
constructor(private restService: RestService) {}
|
2022-04-01 12:05:58 +02:00
|
|
|
|
2022-04-05 15:58:12 +02:00
|
|
|
async onJoinButtonClicked() {
|
|
|
|
this.tokens = {
|
|
|
|
webcam: await this.restService.getToken(this.sessionId, this.OPENVIDU_URL, this.OPENVIDU_SECRET),
|
|
|
|
screen: await this.restService.getToken(this.sessionId, this.OPENVIDU_URL, this.OPENVIDU_SECRET)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onSessionCreated(session: Session) {
|
|
|
|
this.session = session;
|
|
|
|
this.session.on(`signal:${Signal.CHAT}`, (event: any) => {
|
|
|
|
const msg = JSON.parse(event.data).message;
|
|
|
|
this.messages.push(msg);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
send(message: string): void {
|
|
|
|
const signalOptions: SignalOptions = {
|
|
|
|
data: JSON.stringify({ message }),
|
|
|
|
type: Signal.CHAT,
|
|
|
|
to: undefined
|
|
|
|
};
|
|
|
|
this.session.signal(signalOptions);
|
|
|
|
}
|
2022-04-01 12:05:58 +02:00
|
|
|
}
|