All video HTML elements deleted on session.disconnect()

pull/20/head
pabloFuente 2017-05-22 22:30:08 +02:00
parent b7e3c84be6
commit 3422b0f474
7 changed files with 134 additions and 120 deletions

View File

@ -191,9 +191,8 @@ A Java package that wraps the HTTP REST operations for making them even easier
``` ```
- Jar - Jar
```
https://github.com/OpenVidu/openvidu/tree/master/openvidu-backend-client/target/openvidu-backend-client.jar [```https://github.com/OpenVidu/openvidu/tree/master/openvidu-backend-client/target/openvidu-backend-client.jar```](https://github.com/OpenVidu/openvidu/tree/master/openvidu-backend-client/target/openvidu-backend-client.jar)
```
The usage is quite simple: import OpenVidu package and get an **OpenVidu** object. You need to provide to the constructor the IP of your OpenVidu Server and the secret shared with it (initialized by `openvidu.secret=MY_SECRET` property). Then just call the following methods to get a shiny new sessionId or token to be returned to your frontend. The usage is quite simple: import OpenVidu package and get an **OpenVidu** object. You need to provide to the constructor the IP of your OpenVidu Server and the secret shared with it (initialized by `openvidu.secret=MY_SECRET` property). Then just call the following methods to get a shiny new sessionId or token to be returned to your frontend.

File diff suppressed because one or more lines are too long

View File

@ -56,6 +56,13 @@ export class Session {
disconnect() { disconnect() {
this.openVidu.openVidu.close(false); this.openVidu.openVidu.close(false);
let s: Stream;
for (s of this.openVidu.openVidu.getRemoteStreams()){
s.removeVideo();
}
for (let streamId in this.connection.getStreams()) {
this.connection.getStreams()[streamId].removeVideo();
}
} }
publish(publisher: Publisher) { publish(publisher: Publisher) {
@ -161,25 +168,25 @@ export class Session {
onParticipantJoined(callback) { onParticipantJoined(callback) {
this.session.addEventListener("participant-joined", participantEvent => { this.session.addEventListener("participant-joined", participantEvent => {
callback(participantEvent.participant); callback(participantEvent.connection);
}); });
} }
onParticipantLeft(callback) { onParticipantLeft(callback) {
this.session.addEventListener("participant-left", participantEvent => { this.session.addEventListener("participant-left", participantEvent => {
callback(participantEvent.participant); callback(participantEvent.connection);
}); });
} }
onParticipantPublished(callback) { onParticipantPublished(callback) {
this.session.addEventListener("participant-published", participantEvent => { this.session.addEventListener("participant-published", participantEvent => {
callback(participantEvent.participant); callback(participantEvent.connection);
}); });
} }
onParticipantEvicted(callback) { onParticipantEvicted(callback) {
this.session.addEventListener("participant-evicted", participantEvent => { this.session.addEventListener("participant-evicted", participantEvent => {
callback(participantEvent.participant); callback(participantEvent.connection);
}); });
} }

View File

@ -31,7 +31,7 @@ export class Connection {
let streamOpts = { let streamOpts = {
id: streamOptions.id, id: streamOptions.id,
participant: this, connection: this,
recvVideo: ( streamOptions.recvVideo == undefined ? true : streamOptions.recvVideo ), recvVideo: ( streamOptions.recvVideo == undefined ? true : streamOptions.recvVideo ),
recvAudio: ( streamOptions.recvAudio == undefined ? true : streamOptions.recvAudio ), recvAudio: ( streamOptions.recvAudio == undefined ? true : streamOptions.recvAudio ),
audio: streamOptions.audio, audio: streamOptions.audio,

View File

@ -298,7 +298,7 @@ export class OpenViduInternal {
} }
} }
options.participant = this.session.getLocalParticipant(); options.connection = this.session.getLocalParticipant();
this.camera = new Stream(this, true, this.session, options); this.camera = new Stream(this, true, this.session, options);
return this.camera; return this.camera;
}; };

View File

@ -73,15 +73,15 @@ export class SessionInternal {
let length = exParticipants.length; let length = exParticipants.length;
for (let i = 0; i < length; i++) { for (let i = 0; i < length; i++) {
let participant = new Connection(this.openVidu, false, this, let connection = new Connection(this.openVidu, false, this,
exParticipants[i]); exParticipants[i]);
participant.creationTime = new Date().getTime(); connection.creationTime = new Date().getTime();
this.participants[participant.getId()] = participant; this.participants[connection.getId()] = connection;
roomEvent.participants.push(participant); roomEvent.participants.push(connection);
let streams = participant.getStreams(); let streams = connection.getStreams();
for (let key in streams) { for (let key in streams) {
roomEvent.streams.push(streams[key]); roomEvent.streams.push(streams[key]);
if (this.subscribeToStreams) { if (this.subscribeToStreams) {
@ -99,7 +99,7 @@ export class SessionInternal {
// Own connection created event // Own connection created event
this.ee.emitEvent('connectionCreated', [{ connection: this.localParticipant }]); this.ee.emitEvent('connectionCreated', [{ connection: this.localParticipant }]);
// One connection created event for each existing participant in the session // One connection created event for each existing connection in the session
for (let part of roomEvent.participants) { for (let part of roomEvent.participants) {
this.ee.emitEvent('connectionCreated', [{ connection: part }]); this.ee.emitEvent('connectionCreated', [{ connection: part }]);
} }
@ -204,21 +204,21 @@ export class SessionInternal {
options.metadata = this.participants[options.id].data; options.metadata = this.participants[options.id].data;
let participant = new Connection(this.openVidu, false, this, options); let connection = new Connection(this.openVidu, false, this, options);
let pid = participant.getId(); let pid = connection.getId();
if (!(pid in this.participants)) { if (!(pid in this.participants)) {
console.info("Publisher not found in participants list by its id", pid); console.info("Publisher not found in participants list by its id", pid);
} else { } else {
console.log("Publisher found in participants list by its id", pid); console.log("Publisher found in participants list by its id", pid);
} }
//replacing old participant (this one has streams) //replacing old connection (this one has streams)
participant.creationTime = this.participants[pid].creationTime; connection.creationTime = this.participants[pid].creationTime;
this.participants[pid] = participant; this.participants[pid] = connection;
this.ee.emitEvent('participant-published', [{ participant }]); this.ee.emitEvent('participant-published', [{ connection }]);
let streams = participant.getStreams(); let streams = connection.getStreams();
for (let key in streams) { for (let key in streams) {
let stream = streams[key]; let stream = streams[key];
@ -233,42 +233,42 @@ export class SessionInternal {
onParticipantJoined(msg) { onParticipantJoined(msg) {
let participant = new Connection(this.openVidu, false, this, msg); let connection = new Connection(this.openVidu, false, this, msg);
participant.creationTime = new Date().getTime(); connection.creationTime = new Date().getTime();
let pid = participant.getId(); let pid = connection.getId();
if (!(pid in this.participants)) { if (!(pid in this.participants)) {
console.log("New participant to participants list with id", pid); console.log("New participant to participants list with id", pid);
this.participants[pid] = participant; this.participants[pid] = connection;
} else { } else {
//use existing so that we don't lose streams info //use existing so that we don't lose streams info
console.info("Participant already exists in participants list with " + console.info("Participant already exists in participants list with " +
"the same id, old:", this.participants[pid], ", joined now:", participant); "the same id, old:", this.participants[pid], ", joined now:", connection);
participant = this.participants[pid]; connection = this.participants[pid];
} }
this.ee.emitEvent('participant-joined', [{ this.ee.emitEvent('participant-joined', [{
participant: participant connection: connection
}]); }]);
this.ee.emitEvent('connectionCreated', [{ this.ee.emitEvent('connectionCreated', [{
connection: participant connection: connection
}]); }]);
} }
onParticipantLeft(msg) { onParticipantLeft(msg) {
let participant = this.participants[msg.name]; let connection = this.participants[msg.name];
if (participant !== undefined) { if (connection !== undefined) {
delete this.participants[msg.name]; delete this.participants[msg.name];
this.ee.emitEvent('participant-left', [{ this.ee.emitEvent('participant-left', [{
participant: participant connection: connection
}]); }]);
let streams = participant.getStreams(); let streams = connection.getStreams();
for (let key in streams) { for (let key in streams) {
this.ee.emitEvent('stream-removed', [{ this.ee.emitEvent('stream-removed', [{
stream: streams[key], stream: streams[key],
@ -283,10 +283,10 @@ export class SessionInternal {
this.openVidu.getRemoteStreams().splice(index, 1); this.openVidu.getRemoteStreams().splice(index, 1);
} }
participant.dispose(); connection.dispose();
this.ee.emitEvent('connectionDestroyed', [{ this.ee.emitEvent('connectionDestroyed', [{
connection: participant connection: connection
}]); }]);
} else { } else {
@ -328,15 +328,15 @@ export class SessionInternal {
sdpMLineIndex: msg.sdpMLineIndex sdpMLineIndex: msg.sdpMLineIndex
} }
let participant = this.participants[msg.endpointName]; let connection = this.participants[msg.endpointName];
if (!participant) { if (!connection) {
console.error("Participant not found for endpoint " + console.error("Participant not found for endpoint " +
msg.endpointName + ". Ice candidate will be ignored.", msg.endpointName + ". Ice candidate will be ignored.",
candidate); candidate);
return; return;
} }
let streams = participant.getStreams(); let streams = connection.getStreams();
for (let key in streams) { for (let key in streams) {
let stream = streams[key]; let stream = streams[key];
stream.getWebRtcPeer().addIceCandidate(candidate, function (error) { stream.getWebRtcPeer().addIceCandidate(candidate, function (error) {
@ -421,18 +421,18 @@ export class SessionInternal {
disconnect(stream: Stream) { disconnect(stream: Stream) {
let participant = stream.getParticipant(); let connection = stream.getParticipant();
if (!participant) { if (!connection) {
console.error("Stream to disconnect has no participant", stream); console.error("Stream to disconnect has no participant", stream);
return; return;
} }
delete this.participants[participant.getId()]; delete this.participants[connection.getId()];
participant.dispose(); connection.dispose();
if (participant === this.localParticipant) { if (connection === this.localParticipant) {
console.log("Unpublishing my media (I'm " + participant.getId() + ")"); console.log("Unpublishing my media (I'm " + connection.getId() + ")");
delete this.localParticipant; delete this.localParticipant;
this.openVidu.sendRequest('unpublishVideo', function (error, response) { this.openVidu.sendRequest('unpublishVideo', function (error, response) {
if (error) { if (error) {
@ -449,18 +449,18 @@ export class SessionInternal {
unpublish(stream: Stream) { unpublish(stream: Stream) {
let participant = stream.getParticipant(); let connection = stream.getParticipant();
if (!participant) { if (!connection) {
console.error("Stream to disconnect has no participant", stream); console.error("Stream to disconnect has no participant", stream);
return; return;
} }
if (participant === this.localParticipant) { if (connection === this.localParticipant) {
delete this.participants[participant.getId()]; delete this.participants[connection.getId()];
participant.dispose(); connection.dispose();
console.log("Unpublishing my media (I'm " + participant.getId() + ")"); console.log("Unpublishing my media (I'm " + connection.getId() + ")");
delete this.localParticipant; delete this.localParticipant;
this.openVidu.sendRequest('unpublishVideo', function (error, response) { this.openVidu.sendRequest('unpublishVideo', function (error, response) {
if (error) { if (error) {

View File

@ -33,7 +33,7 @@ function hide(id: string) {
export interface StreamOptions { export interface StreamOptions {
id: string; id: string;
participant: Connection; connection: Connection;
recvVideo: any; recvVideo: any;
recvAudio: any; recvAudio: any;
video: boolean; video: boolean;
@ -49,6 +49,8 @@ export interface VideoOptions {
export class Stream { export class Stream {
public connection: Connection;
private ee = new EventEmitter(); private ee = new EventEmitter();
private wrStream: any; private wrStream: any;
private wp: any; private wp: any;
@ -56,7 +58,6 @@ export class Stream {
private video: HTMLVideoElement; private video: HTMLVideoElement;
private videoElements: VideoOptions[] = []; private videoElements: VideoOptions[] = [];
private elements: HTMLDivElement[] = []; private elements: HTMLDivElement[] = [];
private participant: Connection;
private speechEvent: any; private speechEvent: any;
private recvVideo: any; private recvVideo: any;
private recvAudio: any; private recvAudio: any;
@ -81,7 +82,7 @@ export class Stream {
this.id = "webcam"; this.id = "webcam";
} }
this.participant = options.participant; this.connection = options.connection;
this.recvVideo = options.recvVideo; this.recvVideo = options.recvVideo;
this.recvAudio = options.recvAudio; this.recvAudio = options.recvAudio;
this.dataChannel = options.data || false; this.dataChannel = options.data || false;
@ -313,12 +314,12 @@ export class Stream {
} }
getParticipant() { getParticipant() {
return this.participant; return this.connection;
} }
getId() { getId() {
if (this.participant) { if (this.connection) {
return this.participant.getId() + "_" + this.id; return this.connection.getId() + "_" + this.id;
} else { } else {
return this.id + "_webcam"; return this.id + "_webcam";
} }
@ -330,7 +331,7 @@ export class Stream {
requestCameraAccess(callback: Callback<Stream>) { requestCameraAccess(callback: Callback<Stream>) {
this.participant.addStream(this); this.connection.addStream(this);
let constraints = this.mediaConstraints; let constraints = this.mediaConstraints;
@ -424,7 +425,7 @@ export class Stream {
let options: any = { let options: any = {
videoStream: this.wrStream, videoStream: this.wrStream,
mediaConstraints: userMediaConstraints, mediaConstraints: userMediaConstraints,
onicecandidate: this.participant.sendIceCandidate.bind(this.participant), onicecandidate: this.connection.sendIceCandidate.bind(this.connection),
} }
if (this.dataChannel) { if (this.dataChannel) {
@ -461,7 +462,7 @@ export class Stream {
console.log("Constraints of generate SDP offer (subscribing)", console.log("Constraints of generate SDP offer (subscribing)",
offerConstraints); offerConstraints);
let options = { let options = {
onicecandidate: this.participant.sendIceCandidate.bind(this.participant), onicecandidate: this.connection.sendIceCandidate.bind(this.connection),
connectionConstraints: offerConstraints connectionConstraints: offerConstraints
} }
this.wp = new kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly(options, error => { this.wp = new kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly(options, error => {