'streamCreated', 'accessAllowed', 'accessDenied' emitted by Publisher

pull/20/head
pabloFuente 2017-05-31 17:31:26 +02:00
parent 17910bf252
commit 88ff95e24f
5 changed files with 8200 additions and 8120 deletions

File diff suppressed because one or more lines are too long

View File

@ -23,7 +23,7 @@ export class Publisher {
constructor(stream: Stream, parentId: string) {
this.stream = stream;
this.ee.on('camera-access-changed', (event) => {
this.stream.addEventListener('camera-access-changed', (event) => {
this.accessAllowed = event.accessAllowed;
if (this.accessAllowed) {
this.ee.emitEvent('accessAllowed');
@ -62,8 +62,8 @@ export class Publisher {
element: this.stream.getVideoElement()
}]);
} else {
this.stream.addEventListener('video-element-created-by-stream', element => {
console.warn("Publisher emitting videoElementCreated");
this.stream.addEventListener('video-element-created-by-stream', (element) => {
console.warn('Publisher emitting videoElementCreated');
this.id = element.id;
this.ee.emitEvent('videoElementCreated', [{
element: element
@ -71,5 +71,33 @@ export class Publisher {
});
}
}
if (eventName == 'streamCreated') {
if (this.stream.isReady) {
this.ee.emitEvent('streamCreated', [{ stream: this.stream }]);
} else {
this.stream.addEventListener('stream-created-by-publisher', () => {
console.warn('Publisher emitting streamCreated');
this.ee.emitEvent('streamCreated', [{ stream: this.stream }]);
});
}
}
if (eventName == 'accessAllowed') {
if (this.stream.accessIsAllowed) {
this.ee.emitEvent('accessAllowed');
} else {
this.stream.addEventListener('access-allowed-by-publisher', () => {
this.ee.emitEvent('accessAllowed');
});
}
}
if (eventName == 'accessDenied') {
if (this.stream.accessIsDenied) {
this.ee.emitEvent('accessDenied');
} else {
this.stream.addEventListener('access-denied-by-publisher', () => {
this.ee.emitEvent('accessDenied');
});
}
}
}
}

View File

@ -104,7 +104,9 @@ export class OpenViduInternal {
getOpenViduServerURL() {
return 'https://' + this.wsUri.split("wss://")[1].split("/room")[0];
}
getRoom() {
return this.session;

View File

@ -177,7 +177,7 @@ export class SessionInternal {
this.ee.off(eventName, listener);
}
removeEvent(eventName){
removeEvent(eventName) {
this.ee.removeEvent(eventName);
}
@ -258,7 +258,7 @@ export class SessionInternal {
this.ee.emitEvent('connectionCreated', [{
connection: connection
}]);
}
onParticipantLeft(msg) {
@ -369,7 +369,10 @@ export class SessionInternal {
onLostConnection() {
if (!this.connected) {
console.warn('Not connected to room, ignoring lost connection notification');
console.warn('Not connected to room: if you are not debugging, this is probably a certificate error');
if (window.confirm('If you are not debugging, this is probably a certificate error at \"' + this.openVidu.getOpenViduServerURL() + '\"\n\nClick OK to navigate and accept it')) {
location.assign(this.openVidu.getOpenViduServerURL());
};
return;
}

View File

@ -73,6 +73,8 @@ export class Stream {
private videoSrc: string;
private parentId: string;
public isReady: boolean = false;
public accessIsAllowed: boolean = false;
public accessIsDenied: boolean = false;
constructor(private openVidu: OpenViduInternal, private local: boolean, private room: SessionInternal, options: StreamOptions) {
@ -276,6 +278,8 @@ export class Stream {
element: this.video
}]);
this.ee.emitEvent('stream-created-by-publisher');
this.isReady = true;
return this.video;
@ -349,24 +353,25 @@ export class Stream {
navigator.mediaDevices.getUserMedia(constraints)
.then(userStream => {
this.accessIsAllowed = true;
this.accessIsDenied = false;
this.ee.emitEvent('access-allowed-by-publisher');
userStream.getAudioTracks()[0].enabled = this.sendAudio;
userStream.getVideoTracks()[0].enabled = this.sendVideo;
this.wrStream = userStream;
this.emitSrcEvent(this.wrStream);
this.ee.emitEvent('camera-access-changed', [{
accessAllowed: true
}]);
callback(undefined, this);
})
.catch(error => {
this.accessIsDenied = true;
this.accessIsAllowed = false;
this.ee.emitEvent('access-denied-by-publisher');
console.error("Access denied", error);
this.ee.emitEvent('camera-access-changed', [{
accessAllowed: false
}]);
callback(error, undefined);
callback(error, this);
});
}