mirror of https://github.com/OpenVidu/openvidu.git
getDevices, once, off. SubscriberTokBox, PublisherTokBox
parent
b726b9604f
commit
f98194b261
|
@ -208,7 +208,15 @@ export class Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
addEventListener(eventName, listener) {
|
addEventListener(eventName, listener) {
|
||||||
this.ee.addListener(eventName, listener);
|
this.ee.on(eventName, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
addOnceEventListener(eventName, listener) {
|
||||||
|
this.ee.once(eventName, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeListener(eventName, listener) {
|
||||||
|
this.ee.off(eventName, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
emitEvent(eventName, eventsArray) {
|
emitEvent(eventName, eventsArray) {
|
||||||
|
@ -216,10 +224,14 @@ export class Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
subscribe( stream ) {
|
subscribe(stream: Stream) {
|
||||||
stream.subscribe();
|
stream.subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsuscribe(stream) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
onParticipantPublished(options) {
|
onParticipantPublished(options) {
|
||||||
|
|
||||||
let participant = new Participant(this.openVidu, false, this, options);
|
let participant = new Participant(this.openVidu, false, this, options);
|
||||||
|
|
|
@ -326,11 +326,18 @@ export class Stream {
|
||||||
this.wrStream = userStream;
|
this.wrStream = userStream;
|
||||||
this.emitSrcEvent(this.wrStream);
|
this.emitSrcEvent(this.wrStream);
|
||||||
|
|
||||||
|
this.ee.emitEvent('camera-access-changed', [{
|
||||||
|
accessAllowed: true
|
||||||
|
}]);
|
||||||
|
|
||||||
callback(undefined, this);
|
callback(undefined, this);
|
||||||
})
|
})
|
||||||
.catch(function (e) {
|
.catch(error => {
|
||||||
console.error("Access denied", e);
|
console.error("Access denied", error);
|
||||||
callback(e, undefined);
|
this.ee.emitEvent('camera-access-changed', [{
|
||||||
|
accessAllowed: false
|
||||||
|
}]);
|
||||||
|
callback(error, undefined);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +360,7 @@ export class Stream {
|
||||||
} else {
|
} else {
|
||||||
this.room.emitEvent('stream-published', [{
|
this.room.emitEvent('stream-published', [{
|
||||||
stream: this
|
stream: this
|
||||||
}])
|
}]);
|
||||||
this.processSdpAnswer(response.sdpAnswer);
|
this.processSdpAnswer(response.sdpAnswer);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -65,7 +65,7 @@ export class OpenViduTokBox {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new PublisherTokBox(this.openVidu.initPublisherTagged(parentId, cameraOptions, callback));
|
return new PublisherTokBox(this.openVidu.initPublisherTagged(parentId, cameraOptions, callback), parentId);
|
||||||
} else {
|
} else {
|
||||||
alert("Browser not supported");
|
alert("Browser not supported");
|
||||||
}
|
}
|
||||||
|
@ -80,4 +80,13 @@ export class OpenViduTokBox {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDevices(callback) {
|
||||||
|
navigator.mediaDevices.enumerateDevices().then((deviceInfos) => {
|
||||||
|
callback(null, deviceInfos);
|
||||||
|
}).catch((error) => {
|
||||||
|
console.log("Error getting devices: " + error);
|
||||||
|
callback(error, null);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,34 @@ import { Stream, StreamOptions, VideoOptions } from '../OpenVidu/Stream';
|
||||||
import { OpenViduTokBox } from './OpenViduTokBox';
|
import { OpenViduTokBox } from './OpenViduTokBox';
|
||||||
import { SessionTokBox } from './SessionTokBox';
|
import { SessionTokBox } from './SessionTokBox';
|
||||||
|
|
||||||
|
import EventEmitter = require('wolfy87-eventemitter');
|
||||||
|
|
||||||
export class PublisherTokBox {
|
export class PublisherTokBox {
|
||||||
|
|
||||||
stream: Stream;
|
private ee = new EventEmitter();
|
||||||
|
|
||||||
|
accessAllowed = false;
|
||||||
|
element: Element;
|
||||||
|
id: string;
|
||||||
|
stream: Stream;
|
||||||
|
session: SessionTokBox;
|
||||||
|
|
||||||
|
constructor(stream: Stream, parentId: string) {
|
||||||
|
this.accessAllowed = false;
|
||||||
|
|
||||||
|
this.ee.on('camera-access-changed', (event) => {
|
||||||
|
this.accessAllowed = event.accessAllowed;
|
||||||
|
if (this.accessAllowed) {
|
||||||
|
this.ee.emitEvent('accessAllowed');
|
||||||
|
} else {
|
||||||
|
this.ee.emitEvent('accessDenied');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
constructor(stream: Stream) {
|
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
|
if (document.getElementById(parentId) != null) {
|
||||||
|
this.element = document.getElementById(parentId)!!;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
publishAudio(value: boolean) {
|
publishAudio(value: boolean) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ export class SessionTokBox {
|
||||||
}
|
}
|
||||||
|
|
||||||
publish(publisher: PublisherTokBox) {
|
publish(publisher: PublisherTokBox) {
|
||||||
|
publisher.session = this;
|
||||||
publisher.stream.publish();
|
publisher.stream.publish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +39,10 @@ export class SessionTokBox {
|
||||||
let realEventName = '';
|
let realEventName = '';
|
||||||
switch (eventName) {
|
switch (eventName) {
|
||||||
case 'streamCreated':
|
case 'streamCreated':
|
||||||
realEventName = 'stream-added'
|
realEventName = 'stream-added';
|
||||||
break;
|
break;
|
||||||
case 'streamDestroyed':
|
case 'streamDestroyed':
|
||||||
realEventName = 'stream-removed'
|
realEventName = 'stream-removed';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (realEventName != '') {
|
if (realEventName != '') {
|
||||||
|
@ -53,6 +54,42 @@ export class SessionTokBox {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
once(eventName: string, callback) {
|
||||||
|
let realEventName = '';
|
||||||
|
switch (eventName) {
|
||||||
|
case 'streamCreated':
|
||||||
|
realEventName = 'stream-added';
|
||||||
|
break;
|
||||||
|
case 'streamDestroyed':
|
||||||
|
realEventName = 'stream-removed';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (realEventName != '') {
|
||||||
|
this.session.addOnceEventListener(realEventName, event => {
|
||||||
|
callback(event);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.warn("That is not a supported event!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
off(eventName: string, eventHandler) {
|
||||||
|
let realEventName = '';
|
||||||
|
switch (eventName) {
|
||||||
|
case 'streamCreated':
|
||||||
|
realEventName = 'stream-added';
|
||||||
|
break;
|
||||||
|
case 'streamDestroyed':
|
||||||
|
realEventName = 'stream-removed';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (realEventName != '') {
|
||||||
|
this.session.removeListener(realEventName, eventHandler);
|
||||||
|
} else {
|
||||||
|
console.warn("That is not a supported event!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
subscribe(stream: Stream, htmlId: string, videoOptions: any);
|
subscribe(stream: Stream, htmlId: string, videoOptions: any);
|
||||||
subscribe(stream: Stream, htmlId: string);
|
subscribe(stream: Stream, htmlId: string);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { Stream, StreamOptions, VideoOptions } from '../OpenVidu/Stream';
|
||||||
|
import { OpenViduTokBox } from './OpenViduTokBox';
|
||||||
|
import { SessionTokBox } from './SessionTokBox';
|
||||||
|
|
||||||
|
export class SubscriberTokBox {
|
||||||
|
|
||||||
|
element: Element;
|
||||||
|
id: string;
|
||||||
|
stream: Stream;
|
||||||
|
|
||||||
|
constructor(stream: Stream, parentId: string) {
|
||||||
|
this.stream = stream;
|
||||||
|
if (document.getElementById(parentId) != null) {
|
||||||
|
this.element = document.getElementById(parentId)!!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
export * from './OpenViduTokBox';
|
export * from './OpenViduTokBox';
|
||||||
export * from './PublisherTokBox';
|
export * from './PublisherTokBox';
|
||||||
export * from './SessionTokBox';
|
export * from './SessionTokBox';
|
||||||
|
export * from './SubscriberTokBox';
|
||||||
|
|
Loading…
Reference in New Issue