2017-09-30 13:48:40 +02:00
|
|
|
import {
|
|
|
|
Component, Input, HostListener, ChangeDetectorRef, SimpleChanges, ElementRef, ViewChild,
|
|
|
|
OnInit, OnDestroy, OnChanges
|
|
|
|
} from '@angular/core';
|
2018-03-01 11:25:25 +01:00
|
|
|
import { Subscription } from 'rxjs/Subscription';
|
|
|
|
|
2018-04-27 11:08:03 +02:00
|
|
|
import {
|
|
|
|
OpenVidu, Session, Subscriber, Publisher, Stream, Connection,
|
|
|
|
LocalRecorder, VideoInsertMode, StreamEvent, ConnectionEvent,
|
2018-05-29 18:32:49 +02:00
|
|
|
SessionDisconnectedEvent, SignalEvent, RecordingEvent, VideoElementEvent, PublisherSpeakingEvent, StreamManagerEvent, StreamManager
|
2018-04-27 11:08:03 +02:00
|
|
|
} from 'openvidu-browser';
|
2018-05-18 12:46:41 +02:00
|
|
|
import {
|
|
|
|
OpenVidu as OpenViduAPI,
|
|
|
|
Session as SessionAPI,
|
|
|
|
SessionProperties as SessionPropertiesAPI,
|
|
|
|
MediaMode,
|
|
|
|
RecordingMode,
|
|
|
|
RecordingLayout
|
|
|
|
} from 'openvidu-node-client';
|
2018-03-01 11:25:25 +01:00
|
|
|
import { MatDialog, MatDialogRef } from '@angular/material';
|
2018-05-18 12:46:41 +02:00
|
|
|
import { ExtensionDialogComponent } from '../dialogs/extension-dialog.component';
|
|
|
|
import { LocalRecordingDialogComponent } from '../dialogs/local-recording-dialog.component';
|
2017-10-09 18:48:05 +02:00
|
|
|
import { TestFeedService } from '../../services/test-feed.service';
|
2018-03-01 11:25:25 +01:00
|
|
|
import { MuteSubscribersService } from '../../services/mute-subscribers.service';
|
2018-05-29 18:32:49 +02:00
|
|
|
import { EventsDialogComponent } from '../dialogs/events-dialog.component';
|
2018-05-18 12:46:41 +02:00
|
|
|
import { SessionPropertiesDialogComponent } from '../dialogs/session-properties-dialog.component';
|
|
|
|
import { SessionApiDialogComponent } from '../dialogs/session-api-dialog.component';
|
2017-09-28 19:13:29 +02:00
|
|
|
|
|
|
|
|
2017-10-02 15:18:28 +02:00
|
|
|
export interface SessionConf {
|
|
|
|
subscribeTo: boolean;
|
|
|
|
publishTo: boolean;
|
|
|
|
sendAudio: boolean;
|
|
|
|
sendVideo: boolean;
|
|
|
|
startSession: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface OpenViduEvent {
|
|
|
|
name: string;
|
|
|
|
content: string;
|
|
|
|
}
|
|
|
|
|
2017-09-28 19:13:29 +02:00
|
|
|
@Component({
|
|
|
|
selector: 'app-openvidu-instance',
|
|
|
|
templateUrl: './openvidu-instance.component.html',
|
|
|
|
styleUrls: ['./openvidu-instance.component.css']
|
|
|
|
})
|
2017-09-30 13:48:40 +02:00
|
|
|
export class OpenviduInstanceComponent implements OnInit, OnChanges, OnDestroy {
|
2017-09-28 19:13:29 +02:00
|
|
|
|
|
|
|
@Input()
|
2017-09-30 13:48:40 +02:00
|
|
|
openviduUrl: string;
|
2017-09-28 19:13:29 +02:00
|
|
|
|
|
|
|
@Input()
|
|
|
|
openviduSecret: string;
|
|
|
|
|
2017-10-02 15:18:28 +02:00
|
|
|
@Input()
|
|
|
|
sessionConf: SessionConf;
|
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
@Input()
|
|
|
|
index: number;
|
|
|
|
|
2017-09-29 16:19:23 +02:00
|
|
|
// Session join data
|
|
|
|
clientData: string;
|
|
|
|
sessionName: string;
|
|
|
|
|
|
|
|
// Session options
|
2017-10-02 15:18:28 +02:00
|
|
|
subscribeTo;
|
|
|
|
publishTo;
|
|
|
|
sendAudio;
|
|
|
|
sendVideo;
|
2017-09-28 19:13:29 +02:00
|
|
|
activeAudio = true;
|
|
|
|
activeVideo = true;
|
|
|
|
sendVideoRadio = true;
|
2017-09-29 13:54:22 +02:00
|
|
|
subscribeToRemote = false;
|
2017-09-29 16:19:23 +02:00
|
|
|
optionsVideo = 'video';
|
|
|
|
|
|
|
|
// Form 'check' and 'disable' attributes
|
|
|
|
checkSubscribeTo = true;
|
|
|
|
checkPublishTo = true;
|
|
|
|
checkSendAudio = true;
|
|
|
|
checkSendVideo = true;
|
|
|
|
checkActiveAudio = true;
|
|
|
|
checkActiveVideo = true;
|
|
|
|
checkRadioVideo = true;
|
|
|
|
checkRadioScreen = false;
|
|
|
|
disablePublishTo = false;
|
|
|
|
disableSendAudio = false;
|
|
|
|
disableSendVideo = false;
|
|
|
|
disableActiveAudio = false;
|
|
|
|
disableActiveVideo = false;
|
|
|
|
disableRadioButtons = false;
|
2017-09-28 19:13:29 +02:00
|
|
|
|
2018-05-18 12:46:41 +02:00
|
|
|
// OpenVidu Browser objects
|
2017-09-28 19:13:29 +02:00
|
|
|
OV: OpenVidu;
|
|
|
|
session: Session;
|
2017-09-29 13:54:22 +02:00
|
|
|
publisher: Publisher;
|
2018-05-29 18:32:49 +02:00
|
|
|
subscribers: Subscriber[] = [];
|
2017-09-29 13:54:22 +02:00
|
|
|
|
2018-05-18 12:46:41 +02:00
|
|
|
// OpenVidu Node Client objects
|
|
|
|
sessionProperties: SessionPropertiesAPI = {
|
|
|
|
mediaMode: MediaMode.ROUTED,
|
|
|
|
recordingMode: RecordingMode.MANUAL,
|
|
|
|
defaultRecordingLayout: RecordingLayout.BEST_FIT,
|
|
|
|
defaultCustomLayout: '',
|
|
|
|
customSessionId: ''
|
|
|
|
};
|
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
sessionEvents = {
|
|
|
|
connectionCreated: true,
|
|
|
|
connectionDestroyed: true,
|
|
|
|
sessionDisconnected: true,
|
|
|
|
streamCreated: true,
|
|
|
|
streamDestroyed: true,
|
|
|
|
recordingStarted: true,
|
|
|
|
recordingStopped: true,
|
|
|
|
signal: true,
|
|
|
|
publisherStartSpeaking: false,
|
|
|
|
publisherStopSpeaking: false
|
|
|
|
};
|
2018-01-18 16:09:39 +01:00
|
|
|
|
2017-10-02 15:18:28 +02:00
|
|
|
events: OpenViduEvent[] = [];
|
2017-09-30 13:48:40 +02:00
|
|
|
|
2017-10-04 10:30:15 +02:00
|
|
|
openviduError: any;
|
|
|
|
|
2018-03-01 11:25:25 +01:00
|
|
|
private publisherRecorder: LocalRecorder;
|
|
|
|
private publisherRecording = false;
|
|
|
|
private publisherPaused = false;
|
|
|
|
private muteSubscribersSubscription: Subscription;
|
|
|
|
|
2018-01-11 11:13:50 +01:00
|
|
|
constructor(
|
|
|
|
private changeDetector: ChangeDetectorRef,
|
2018-05-18 12:46:41 +02:00
|
|
|
private dialog: MatDialog,
|
2018-03-01 11:25:25 +01:00
|
|
|
private recordDialog: MatDialog,
|
2018-05-29 18:32:49 +02:00
|
|
|
private testFeedService: TestFeedService
|
2018-01-11 11:13:50 +01:00
|
|
|
) {
|
2017-09-28 19:13:29 +02:00
|
|
|
this.generateSessionInfo();
|
|
|
|
}
|
|
|
|
|
2017-10-02 15:18:28 +02:00
|
|
|
ngOnInit() {
|
|
|
|
this.subscribeTo = this.sessionConf.subscribeTo;
|
|
|
|
this.publishTo = this.sessionConf.publishTo;
|
|
|
|
this.sendAudio = this.sessionConf.sendAudio;
|
|
|
|
this.sendVideo = this.sessionConf.sendVideo;
|
|
|
|
|
|
|
|
if (!this.publishTo) {
|
|
|
|
this.publishTo = !this.publishTo;
|
|
|
|
this.togglePublishTo();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.sessionConf.startSession) {
|
|
|
|
this.joinSession();
|
|
|
|
}
|
|
|
|
}
|
2017-09-28 19:13:29 +02:00
|
|
|
|
2017-09-30 13:48:40 +02:00
|
|
|
ngOnChanges(changes: SimpleChanges) {
|
|
|
|
if (changes.openviduSecret) {
|
|
|
|
this.openviduSecret = changes.openviduSecret.currentValue;
|
|
|
|
}
|
|
|
|
if (changes.openviduUrl) {
|
|
|
|
this.openviduUrl = changes.openviduUrl.currentValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-28 19:13:29 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.leaveSession();
|
|
|
|
}
|
|
|
|
|
|
|
|
@HostListener('window:beforeunload')
|
|
|
|
beforeunloadHandler() {
|
|
|
|
this.leaveSession();
|
|
|
|
}
|
|
|
|
|
|
|
|
private generateSessionInfo(): void {
|
|
|
|
this.sessionName = 'TestSession';
|
|
|
|
this.clientData = 'TestClient';
|
|
|
|
}
|
|
|
|
|
|
|
|
private removeHttps = input => input.replace(/^https?:\/\//, '');
|
|
|
|
|
|
|
|
private joinSession(): void {
|
|
|
|
|
|
|
|
if (this.session) {
|
|
|
|
this.leaveSession();
|
|
|
|
}
|
|
|
|
|
2018-05-18 12:46:41 +02:00
|
|
|
this.getToken().then(token => {
|
|
|
|
this.joinSessionShared(token);
|
|
|
|
});
|
2017-10-16 15:49:23 +02:00
|
|
|
}
|
|
|
|
|
2018-05-03 11:48:57 +02:00
|
|
|
private joinSessionShared(token): void {
|
2017-10-16 15:49:23 +02:00
|
|
|
|
2018-01-18 16:09:39 +01:00
|
|
|
this.OV = new OpenVidu();
|
2017-09-28 19:13:29 +02:00
|
|
|
|
2018-05-03 11:48:57 +02:00
|
|
|
this.session = this.OV.initSession();
|
2017-09-28 19:13:29 +02:00
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
this.updateSessionEvents({
|
|
|
|
connectionCreated: false,
|
|
|
|
connectionDestroyed: false,
|
|
|
|
sessionDisconnected: false,
|
|
|
|
streamCreated: false,
|
|
|
|
streamDestroyed: false,
|
|
|
|
recordingStarted: false,
|
|
|
|
recordingStopped: false,
|
|
|
|
signal: false,
|
|
|
|
publisherStartSpeaking: true,
|
|
|
|
publisherStopSpeaking: true
|
|
|
|
}, true);
|
2017-12-12 14:36:43 +01:00
|
|
|
|
2018-04-27 11:43:21 +02:00
|
|
|
this.session.connect(token, this.clientData)
|
|
|
|
.then(() => {
|
2018-04-05 20:06:48 +02:00
|
|
|
this.changeDetector.detectChanges();
|
|
|
|
|
2017-09-29 13:54:22 +02:00
|
|
|
if (this.publishTo) {
|
2018-04-17 15:08:02 +02:00
|
|
|
// this.asyncInitPublisher();
|
|
|
|
this.syncInitPublisher();
|
2017-09-29 13:54:22 +02:00
|
|
|
}
|
2018-04-27 11:43:21 +02:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2017-09-28 19:13:29 +02:00
|
|
|
console.log('There was an error connecting to the session:', error.code, error.message);
|
2018-04-27 11:43:21 +02:00
|
|
|
});
|
2017-09-28 19:13:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private leaveSession(): void {
|
|
|
|
if (this.session) {
|
|
|
|
this.session.disconnect();
|
|
|
|
}
|
2018-05-29 18:32:49 +02:00
|
|
|
delete this.session;
|
|
|
|
delete this.OV;
|
|
|
|
delete this.publisher;
|
|
|
|
this.subscribers = [];
|
2017-09-28 19:13:29 +02:00
|
|
|
}
|
|
|
|
|
2017-10-02 15:18:28 +02:00
|
|
|
private updateEventList(event: string, content: string) {
|
|
|
|
this.events.push({ name: event, content: content });
|
2017-10-09 18:48:05 +02:00
|
|
|
this.testFeedService.pushNewEvent(this.sessionName, this.session.connection.connectionId, event, content);
|
2017-09-30 13:48:40 +02:00
|
|
|
}
|
|
|
|
|
2017-09-29 16:19:23 +02:00
|
|
|
toggleSubscribeTo(): void {
|
|
|
|
this.subscribeTo = !this.subscribeTo;
|
|
|
|
}
|
|
|
|
|
|
|
|
togglePublishTo(): void {
|
|
|
|
this.publishTo = !this.publishTo;
|
|
|
|
|
|
|
|
this.sendAudio = this.publishTo;
|
|
|
|
this.sendVideo = this.publishTo;
|
|
|
|
this.activeAudio = this.publishTo;
|
|
|
|
this.activeVideo = this.publishTo;
|
|
|
|
|
|
|
|
this.checkPublishTo = this.publishTo;
|
|
|
|
this.checkSendAudio = this.publishTo;
|
|
|
|
this.checkSendVideo = this.publishTo;
|
|
|
|
this.checkActiveAudio = this.publishTo;
|
|
|
|
this.checkActiveVideo = this.publishTo;
|
|
|
|
|
|
|
|
if (this.publishTo) {
|
|
|
|
this.checkRadioVideo = true;
|
|
|
|
this.optionsVideo = 'video';
|
|
|
|
} else {
|
|
|
|
this.checkRadioVideo = false;
|
|
|
|
this.optionsVideo = '';
|
2017-09-29 13:54:22 +02:00
|
|
|
}
|
2017-09-29 16:19:23 +02:00
|
|
|
|
|
|
|
this.disableSendAudio = !this.publishTo;
|
|
|
|
this.disableSendVideo = !this.publishTo;
|
|
|
|
this.disableActiveAudio = !this.publishTo;
|
|
|
|
this.disableActiveVideo = !this.publishTo;
|
|
|
|
this.disableRadioButtons = !this.publishTo;
|
|
|
|
|
|
|
|
this.subscribeToRemote = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSendAudio(): void {
|
|
|
|
this.sendAudio = !this.sendAudio;
|
|
|
|
|
|
|
|
this.activeAudio = this.sendAudio;
|
|
|
|
this.checkActiveAudio = this.sendAudio;
|
|
|
|
this.disableActiveAudio = !this.sendAudio;
|
|
|
|
|
|
|
|
if (!this.sendAudio && !this.sendVideo && this.publishTo) {
|
|
|
|
this.togglePublishTo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSendVideo(): void {
|
|
|
|
this.sendVideo = !this.sendVideo;
|
|
|
|
|
|
|
|
this.activeVideo = this.sendVideo;
|
|
|
|
|
|
|
|
this.checkActiveVideo = this.sendVideo;
|
|
|
|
this.checkRadioScreen = false;
|
|
|
|
if (this.sendVideo) {
|
|
|
|
this.checkRadioVideo = true;
|
|
|
|
this.optionsVideo = 'video';
|
|
|
|
} else {
|
|
|
|
this.checkRadioVideo = false;
|
|
|
|
this.optionsVideo = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
this.disableActiveVideo = !this.sendVideo;
|
|
|
|
this.disableRadioButtons = !this.sendVideo;
|
|
|
|
|
|
|
|
if (!this.sendAudio && !this.sendVideo && this.publishTo) {
|
|
|
|
this.togglePublishTo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleActiveAudio(): void {
|
|
|
|
this.activeAudio = !this.activeAudio;
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleActiveVideo(): void {
|
|
|
|
this.activeVideo = !this.activeVideo;
|
2017-09-28 19:13:29 +02:00
|
|
|
}
|
|
|
|
|
2017-12-11 17:09:57 +01:00
|
|
|
sendMessage(): void {
|
|
|
|
this.session.signal({
|
|
|
|
data: 'Test message',
|
|
|
|
to: [],
|
|
|
|
type: 'chat'
|
2018-04-27 11:43:21 +02:00
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
console.log('Message succesfully sent');
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
2018-04-02 12:11:30 +02:00
|
|
|
});
|
2018-04-27 11:08:03 +02:00
|
|
|
// this.initGrayVideo();
|
2017-12-11 17:09:57 +01:00
|
|
|
}
|
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
updateSessionEvents(oldValues, firstTime) {
|
2018-03-01 11:25:25 +01:00
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
if (this.sessionEvents.streamCreated !== oldValues.streamCreated || firstTime) {
|
|
|
|
this.session.off('streamCreated');
|
|
|
|
if (this.sessionEvents.streamCreated) {
|
|
|
|
this.session.on('streamCreated', (event: StreamEvent) => {
|
|
|
|
this.changeDetector.detectChanges();
|
|
|
|
if (this.subscribeTo) {
|
|
|
|
this.syncSubscribe(this.session, event);
|
|
|
|
}
|
|
|
|
this.updateEventList('streamCreated', event.stream.streamId);
|
2018-03-01 11:25:25 +01:00
|
|
|
});
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
if (this.sessionEvents.streamDestroyed !== oldValues.streamDestroyed || firstTime) {
|
|
|
|
this.session.off('streamDestroyed');
|
|
|
|
if (this.sessionEvents.streamDestroyed) {
|
|
|
|
this.session.on('streamDestroyed', (event: StreamEvent) => {
|
|
|
|
const index = this.subscribers.indexOf(<Subscriber>event.stream.streamManager);
|
|
|
|
if (index > -1) {
|
|
|
|
this.subscribers.splice(index, 1);
|
|
|
|
}
|
|
|
|
this.updateEventList('streamDestroyed', event.stream.streamId);
|
2018-03-01 11:25:25 +01:00
|
|
|
});
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
if (this.sessionEvents.connectionCreated !== oldValues.connectionCreated || firstTime) {
|
|
|
|
this.session.off('connectionCreated');
|
|
|
|
if (this.sessionEvents.connectionCreated) {
|
|
|
|
this.session.on('connectionCreated', (event: ConnectionEvent) => {
|
|
|
|
this.updateEventList('connectionCreated', event.connection.connectionId);
|
2018-04-17 15:08:02 +02:00
|
|
|
});
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2018-01-11 11:13:50 +01:00
|
|
|
}
|
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
if (this.sessionEvents.connectionDestroyed !== oldValues.connectionDestroyed || firstTime) {
|
|
|
|
this.session.off('connectionDestroyed');
|
|
|
|
if (this.sessionEvents.connectionDestroyed) {
|
|
|
|
this.session.on('connectionDestroyed', (event: ConnectionEvent) => {
|
|
|
|
delete this.subscribers[event.connection.connectionId];
|
|
|
|
this.updateEventList('connectionDestroyed', event.connection.connectionId);
|
|
|
|
});
|
2018-01-18 16:09:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
if (this.sessionEvents.sessionDisconnected !== oldValues.sessionDisconnected || firstTime) {
|
|
|
|
this.session.off('sessionDisconnected');
|
|
|
|
if (this.sessionEvents.sessionDisconnected) {
|
|
|
|
this.session.on('sessionDisconnected', (event: SessionDisconnectedEvent) => {
|
|
|
|
this.updateEventList('sessionDisconnected', 'No data');
|
|
|
|
if (event.reason === 'networkDisconnect') {
|
|
|
|
this.session = null;
|
|
|
|
this.OV = null;
|
2018-01-18 16:09:39 +01:00
|
|
|
}
|
2018-04-17 15:08:02 +02:00
|
|
|
});
|
2018-01-18 16:09:39 +01:00
|
|
|
}
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2018-01-18 16:09:39 +01:00
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
if (this.sessionEvents.signal !== oldValues.signal || firstTime) {
|
|
|
|
this.session.off('signal');
|
|
|
|
if (this.sessionEvents.signal) {
|
|
|
|
this.session.on('signal', (event: SignalEvent) => {
|
|
|
|
this.updateEventList('signal', event.from.connectionId + '-' + event.data);
|
|
|
|
});
|
2018-04-17 15:08:02 +02:00
|
|
|
}
|
2018-05-29 18:32:49 +02:00
|
|
|
}
|
2018-01-18 16:09:39 +01:00
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
if (this.sessionEvents.recordingStarted !== oldValues.recordingStarted || firstTime) {
|
|
|
|
this.session.off('recordingStarted');
|
|
|
|
if (this.sessionEvents.recordingStarted) {
|
|
|
|
this.session.on('recordingStarted', (event: RecordingEvent) => {
|
|
|
|
this.updateEventList('recordingStarted', event.id);
|
|
|
|
});
|
2018-01-18 16:09:39 +01:00
|
|
|
}
|
2018-03-02 11:36:12 +01:00
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
if (this.sessionEvents.recordingStopped !== oldValues.recordingStopped || firstTime) {
|
|
|
|
this.session.off('recordingStopped');
|
|
|
|
if (this.sessionEvents.recordingStopped) {
|
|
|
|
this.session.on('recordingStopped', (event: RecordingEvent) => {
|
|
|
|
this.updateEventList('recordingStopped', event.id);
|
|
|
|
});
|
2018-03-02 11:36:12 +01:00
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
if (this.sessionEvents.publisherStartSpeaking !== oldValues.publisherStartSpeaking || firstTime) {
|
|
|
|
this.session.off('publisherStartSpeaking');
|
|
|
|
if (this.sessionEvents.publisherStartSpeaking) {
|
|
|
|
this.session.on('publisherStartSpeaking', (event: PublisherSpeakingEvent) => {
|
|
|
|
this.updateEventList('publisherStartSpeaking', event.connection.connectionId);
|
|
|
|
});
|
2018-03-02 11:36:12 +01:00
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
}
|
2018-03-02 11:36:12 +01:00
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
if (this.sessionEvents.publisherStopSpeaking !== oldValues.publisherStopSpeaking || firstTime) {
|
|
|
|
this.session.off('publisherStopSpeaking');
|
|
|
|
if (this.sessionEvents.publisherStopSpeaking) {
|
|
|
|
this.session.on('publisherStopSpeaking', (event: PublisherSpeakingEvent) => {
|
|
|
|
this.updateEventList('publisherStopSpeaking', event.connection.connectionId);
|
|
|
|
});
|
|
|
|
}
|
2018-03-02 11:36:12 +01:00
|
|
|
}
|
2018-03-01 11:25:25 +01:00
|
|
|
}
|
|
|
|
|
2018-04-17 15:08:02 +02:00
|
|
|
syncInitPublisher() {
|
|
|
|
this.publisher = this.OV.initPublisher(
|
2018-05-29 18:32:49 +02:00
|
|
|
undefined,
|
2018-04-17 15:08:02 +02:00
|
|
|
{
|
|
|
|
audioSource: this.sendAudio ? undefined : false,
|
|
|
|
videoSource: this.sendVideo ? (this.optionsVideo === 'screen' ? 'screen' : undefined) : false,
|
|
|
|
publishAudio: this.activeAudio,
|
|
|
|
publishVideo: this.activeVideo,
|
|
|
|
resolution: '640x480',
|
2018-05-29 18:32:49 +02:00
|
|
|
frameRate: 30
|
2018-04-17 15:08:02 +02:00
|
|
|
},
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
console.warn(err);
|
|
|
|
this.openviduError = err;
|
|
|
|
if (err.name === 'SCREEN_EXTENSION_NOT_INSTALLED') {
|
2018-05-18 12:46:41 +02:00
|
|
|
this.dialog.open(ExtensionDialogComponent, {
|
2018-04-17 15:08:02 +02:00
|
|
|
data: { url: err.message },
|
|
|
|
disableClose: true,
|
|
|
|
width: '250px'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.subscribeToRemote) {
|
|
|
|
this.publisher.subscribeToRemote();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.session.publish(this.publisher);
|
|
|
|
}
|
|
|
|
|
|
|
|
asyncInitPublisher() {
|
|
|
|
this.OV.initPublisherAsync(
|
|
|
|
'local-vid-' + this.session.connection.connectionId,
|
|
|
|
{
|
|
|
|
audioSource: this.sendAudio ? undefined : false,
|
|
|
|
videoSource: this.sendVideo ? (this.optionsVideo === 'screen' ? 'screen' : undefined) : false,
|
|
|
|
publishAudio: this.activeAudio,
|
|
|
|
publishVideo: this.activeVideo,
|
|
|
|
resolution: '640x480',
|
|
|
|
frameRate: 30,
|
2018-04-27 11:08:03 +02:00
|
|
|
insertMode: VideoInsertMode.APPEND
|
2018-04-17 15:08:02 +02:00
|
|
|
})
|
|
|
|
.then(publisher => {
|
|
|
|
this.publisher = publisher;
|
|
|
|
if (this.subscribeToRemote) {
|
|
|
|
this.publisher.subscribeToRemote();
|
|
|
|
}
|
|
|
|
this.session.publish(this.publisher)
|
|
|
|
.then(() => {
|
|
|
|
console.log(this.publisher);
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
console.error(e);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
this.openviduError = err;
|
|
|
|
if (err.name === 'SCREEN_EXTENSION_NOT_INSTALLED') {
|
2018-05-18 12:46:41 +02:00
|
|
|
this.dialog.open(ExtensionDialogComponent, {
|
2018-04-17 15:08:02 +02:00
|
|
|
data: { url: err.message },
|
|
|
|
disableClose: true,
|
|
|
|
width: '250px'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
syncSubscribe(session: Session, event) {
|
2018-05-29 18:32:49 +02:00
|
|
|
this.subscribers.push(session.subscribe(event.stream, undefined));
|
2018-04-17 15:08:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
initGrayVideo(): void {
|
|
|
|
this.OV.getUserMedia(
|
|
|
|
{
|
|
|
|
videoSource: undefined,
|
|
|
|
resolution: '1280x720',
|
|
|
|
frameRate: 10,
|
|
|
|
}
|
|
|
|
)
|
2018-04-23 11:08:07 +02:00
|
|
|
.then((mediaStream: MediaStream) => {
|
|
|
|
const videoStreamTrack = mediaStream.getVideoTracks()[0];
|
|
|
|
const video = document.createElement('video');
|
|
|
|
video.srcObject = new MediaStream([videoStreamTrack]);
|
|
|
|
video.play();
|
|
|
|
const canvas = document.createElement('canvas') as any;
|
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
ctx.filter = 'grayscale(100%)';
|
|
|
|
|
|
|
|
video.addEventListener('play', () => {
|
|
|
|
const loop = () => {
|
|
|
|
if (!video.paused && !video.ended) {
|
|
|
|
ctx.drawImage(video, 0, 0, 300, 170);
|
|
|
|
setTimeout(loop, 100); // Drawing at 10fps
|
|
|
|
}
|
|
|
|
};
|
|
|
|
loop();
|
2018-04-17 15:08:02 +02:00
|
|
|
});
|
2018-04-23 11:08:07 +02:00
|
|
|
const grayVideoTrack = canvas.captureStream(30).getVideoTracks()[0];
|
|
|
|
this.OV.initPublisher(
|
|
|
|
document.body,
|
|
|
|
{
|
|
|
|
audioSource: false,
|
|
|
|
videoSource: grayVideoTrack,
|
2018-04-27 11:08:03 +02:00
|
|
|
insertMode: VideoInsertMode.APPEND
|
2018-04-23 11:08:07 +02:00
|
|
|
});
|
2018-04-17 15:08:02 +02:00
|
|
|
})
|
2018-04-23 11:08:07 +02:00
|
|
|
.catch(error => {
|
|
|
|
console.error(error);
|
|
|
|
});
|
2018-04-17 15:08:02 +02:00
|
|
|
}
|
|
|
|
|
2018-05-18 12:46:41 +02:00
|
|
|
openSessionPropertiesDialog() {
|
|
|
|
this.sessionProperties.customSessionId = this.sessionName;
|
|
|
|
const dialogRef = this.dialog.open(SessionPropertiesDialogComponent, {
|
|
|
|
data: this.sessionProperties,
|
|
|
|
width: '235px'
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogRef.afterClosed().subscribe((result: SessionPropertiesAPI) => {
|
|
|
|
if (!!result) {
|
|
|
|
this.sessionProperties = result;
|
|
|
|
if (!!this.sessionProperties.customSessionId) {
|
|
|
|
this.sessionName = this.sessionProperties.customSessionId;
|
|
|
|
}
|
|
|
|
}
|
2018-05-29 18:32:49 +02:00
|
|
|
document.getElementById('session-settings-btn-' + this.index).classList.remove('cdk-program-focused');
|
2018-05-18 12:46:41 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
openSessionApiDialog() {
|
|
|
|
const dialogRef = this.dialog.open(SessionApiDialogComponent, {
|
|
|
|
data: {
|
|
|
|
openVidu: new OpenViduAPI(this.openviduUrl, this.openviduSecret),
|
|
|
|
sessionId: !!this.session ? this.session.sessionId : this.sessionName
|
|
|
|
},
|
|
|
|
width: '280px'
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogRef.afterClosed().subscribe((result: string) => {
|
2018-05-29 18:32:49 +02:00
|
|
|
document.getElementById('session-api-btn-' + this.index).classList.remove('cdk-program-focused');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
openSessionEventsDialog() {
|
|
|
|
|
|
|
|
const oldValues = {
|
|
|
|
connectionCreated: this.sessionEvents.connectionCreated,
|
|
|
|
connectionDestroyed: this.sessionEvents.connectionDestroyed,
|
|
|
|
sessionDisconnected: this.sessionEvents.sessionDisconnected,
|
|
|
|
streamCreated: this.sessionEvents.streamCreated,
|
|
|
|
streamDestroyed: this.sessionEvents.streamDestroyed,
|
|
|
|
recordingStarted: this.sessionEvents.recordingStarted,
|
|
|
|
recordingStopped: this.sessionEvents.recordingStopped,
|
|
|
|
signal: this.sessionEvents.signal,
|
|
|
|
publisherStartSpeaking: this.sessionEvents.publisherStartSpeaking,
|
|
|
|
publisherStopSpeaking: this.sessionEvents.publisherStopSpeaking
|
|
|
|
};
|
|
|
|
|
|
|
|
const dialogRef = this.dialog.open(EventsDialogComponent, {
|
|
|
|
data: {
|
|
|
|
eventCollection: this.sessionEvents,
|
|
|
|
target: 'Session'
|
|
|
|
},
|
|
|
|
width: '280px',
|
|
|
|
autoFocus: false,
|
|
|
|
disableClose: true
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogRef.afterClosed().subscribe((result) => {
|
|
|
|
|
|
|
|
if (!!this.session && JSON.stringify(this.sessionEvents) !== JSON.stringify(oldValues)) {
|
|
|
|
this.updateSessionEvents(oldValues, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.sessionEvents = {
|
|
|
|
connectionCreated: result.connectionCreated,
|
|
|
|
connectionDestroyed: result.connectionDestroyed,
|
|
|
|
sessionDisconnected: result.sessionDisconnected,
|
|
|
|
streamCreated: result.streamCreated,
|
|
|
|
streamDestroyed: result.streamDestroyed,
|
|
|
|
recordingStarted: result.recordingStarted,
|
|
|
|
recordingStopped: result.recordingStopped,
|
|
|
|
signal: result.signal,
|
|
|
|
publisherStartSpeaking: result.publisherStartSpeaking,
|
|
|
|
publisherStopSpeaking: result.publisherStopSpeaking
|
|
|
|
};
|
|
|
|
document.getElementById('session-events-btn-' + this.index).classList.remove('cdk-program-focused');
|
2018-05-18 12:46:41 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getToken(): Promise<string> {
|
|
|
|
const OV_NodeClient = new OpenViduAPI(this.openviduUrl, this.openviduSecret);
|
|
|
|
if (!this.sessionProperties.customSessionId) {
|
|
|
|
this.sessionProperties.customSessionId = this.sessionName;
|
|
|
|
}
|
|
|
|
return OV_NodeClient.createSession(this.sessionProperties)
|
|
|
|
.then(session_NodeClient => {
|
|
|
|
return session_NodeClient.generateToken();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-29 18:32:49 +02:00
|
|
|
udpateEventFromChild(event) {
|
|
|
|
this.updateEventList(event.event, event.content);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSubscriberFromChild(newSubscriber: Subscriber) {
|
|
|
|
const oldSubscriber = this.subscribers.filter(sub => {
|
|
|
|
return sub.stream.streamId === newSubscriber.stream.streamId;
|
|
|
|
})[0];
|
|
|
|
this.subscribers[this.subscribers.indexOf(oldSubscriber)] = newSubscriber;
|
|
|
|
}
|
|
|
|
|
2017-09-28 19:13:29 +02:00
|
|
|
}
|