mirror of https://github.com/OpenVidu/openvidu.git
All video HTML elements deleted on session.disconnect()
parent
b7e3c84be6
commit
3422b0f474
|
@ -191,9 +191,8 @@ A Java package that wraps the HTTP REST operations for making them even easier
|
|||
```
|
||||
|
||||
- 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.
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -56,6 +56,13 @@ export class Session {
|
|||
|
||||
disconnect() {
|
||||
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) {
|
||||
|
@ -161,25 +168,25 @@ export class Session {
|
|||
|
||||
onParticipantJoined(callback) {
|
||||
this.session.addEventListener("participant-joined", participantEvent => {
|
||||
callback(participantEvent.participant);
|
||||
callback(participantEvent.connection);
|
||||
});
|
||||
}
|
||||
|
||||
onParticipantLeft(callback) {
|
||||
this.session.addEventListener("participant-left", participantEvent => {
|
||||
callback(participantEvent.participant);
|
||||
callback(participantEvent.connection);
|
||||
});
|
||||
}
|
||||
|
||||
onParticipantPublished(callback) {
|
||||
this.session.addEventListener("participant-published", participantEvent => {
|
||||
callback(participantEvent.participant);
|
||||
callback(participantEvent.connection);
|
||||
});
|
||||
}
|
||||
|
||||
onParticipantEvicted(callback) {
|
||||
this.session.addEventListener("participant-evicted", participantEvent => {
|
||||
callback(participantEvent.participant);
|
||||
callback(participantEvent.connection);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ export class Connection {
|
|||
|
||||
let streamOpts = {
|
||||
id: streamOptions.id,
|
||||
participant: this,
|
||||
connection: this,
|
||||
recvVideo: ( streamOptions.recvVideo == undefined ? true : streamOptions.recvVideo ),
|
||||
recvAudio: ( streamOptions.recvAudio == undefined ? true : streamOptions.recvAudio ),
|
||||
audio: streamOptions.audio,
|
||||
|
|
|
@ -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);
|
||||
return this.camera;
|
||||
};
|
||||
|
|
|
@ -73,15 +73,15 @@ export class SessionInternal {
|
|||
let length = exParticipants.length;
|
||||
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]);
|
||||
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) {
|
||||
roomEvent.streams.push(streams[key]);
|
||||
if (this.subscribeToStreams) {
|
||||
|
@ -99,7 +99,7 @@ export class SessionInternal {
|
|||
// Own connection created event
|
||||
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) {
|
||||
this.ee.emitEvent('connectionCreated', [{ connection: part }]);
|
||||
}
|
||||
|
@ -204,21 +204,21 @@ export class SessionInternal {
|
|||
|
||||
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)) {
|
||||
console.info("Publisher not found in participants list by its id", pid);
|
||||
} else {
|
||||
console.log("Publisher found in participants list by its id", pid);
|
||||
}
|
||||
//replacing old participant (this one has streams)
|
||||
participant.creationTime = this.participants[pid].creationTime;
|
||||
this.participants[pid] = participant;
|
||||
//replacing old connection (this one has streams)
|
||||
connection.creationTime = this.participants[pid].creationTime;
|
||||
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) {
|
||||
let stream = streams[key];
|
||||
|
||||
|
@ -233,42 +233,42 @@ export class SessionInternal {
|
|||
|
||||
onParticipantJoined(msg) {
|
||||
|
||||
let participant = new Connection(this.openVidu, false, this, msg);
|
||||
participant.creationTime = new Date().getTime();
|
||||
let connection = new Connection(this.openVidu, false, this, msg);
|
||||
connection.creationTime = new Date().getTime();
|
||||
|
||||
let pid = participant.getId();
|
||||
let pid = connection.getId();
|
||||
if (!(pid in this.participants)) {
|
||||
console.log("New participant to participants list with id", pid);
|
||||
this.participants[pid] = participant;
|
||||
this.participants[pid] = connection;
|
||||
} else {
|
||||
//use existing so that we don't lose streams info
|
||||
console.info("Participant already exists in participants list with " +
|
||||
"the same id, old:", this.participants[pid], ", joined now:", participant);
|
||||
participant = this.participants[pid];
|
||||
"the same id, old:", this.participants[pid], ", joined now:", connection);
|
||||
connection = this.participants[pid];
|
||||
}
|
||||
|
||||
this.ee.emitEvent('participant-joined', [{
|
||||
participant: participant
|
||||
connection: connection
|
||||
}]);
|
||||
|
||||
this.ee.emitEvent('connectionCreated', [{
|
||||
connection: participant
|
||||
connection: connection
|
||||
}]);
|
||||
|
||||
}
|
||||
|
||||
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];
|
||||
|
||||
this.ee.emitEvent('participant-left', [{
|
||||
participant: participant
|
||||
connection: connection
|
||||
}]);
|
||||
|
||||
let streams = participant.getStreams();
|
||||
let streams = connection.getStreams();
|
||||
for (let key in streams) {
|
||||
this.ee.emitEvent('stream-removed', [{
|
||||
stream: streams[key],
|
||||
|
@ -283,10 +283,10 @@ export class SessionInternal {
|
|||
this.openVidu.getRemoteStreams().splice(index, 1);
|
||||
}
|
||||
|
||||
participant.dispose();
|
||||
connection.dispose();
|
||||
|
||||
this.ee.emitEvent('connectionDestroyed', [{
|
||||
connection: participant
|
||||
connection: connection
|
||||
}]);
|
||||
|
||||
} else {
|
||||
|
@ -328,15 +328,15 @@ export class SessionInternal {
|
|||
sdpMLineIndex: msg.sdpMLineIndex
|
||||
}
|
||||
|
||||
let participant = this.participants[msg.endpointName];
|
||||
if (!participant) {
|
||||
let connection = this.participants[msg.endpointName];
|
||||
if (!connection) {
|
||||
console.error("Participant not found for endpoint " +
|
||||
msg.endpointName + ". Ice candidate will be ignored.",
|
||||
candidate);
|
||||
return;
|
||||
}
|
||||
|
||||
let streams = participant.getStreams();
|
||||
let streams = connection.getStreams();
|
||||
for (let key in streams) {
|
||||
let stream = streams[key];
|
||||
stream.getWebRtcPeer().addIceCandidate(candidate, function (error) {
|
||||
|
@ -421,18 +421,18 @@ export class SessionInternal {
|
|||
|
||||
disconnect(stream: Stream) {
|
||||
|
||||
let participant = stream.getParticipant();
|
||||
if (!participant) {
|
||||
let connection = stream.getParticipant();
|
||||
if (!connection) {
|
||||
console.error("Stream to disconnect has no participant", stream);
|
||||
return;
|
||||
}
|
||||
|
||||
delete this.participants[participant.getId()];
|
||||
participant.dispose();
|
||||
delete this.participants[connection.getId()];
|
||||
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;
|
||||
this.openVidu.sendRequest('unpublishVideo', function (error, response) {
|
||||
if (error) {
|
||||
|
@ -449,18 +449,18 @@ export class SessionInternal {
|
|||
|
||||
unpublish(stream: Stream) {
|
||||
|
||||
let participant = stream.getParticipant();
|
||||
if (!participant) {
|
||||
let connection = stream.getParticipant();
|
||||
if (!connection) {
|
||||
console.error("Stream to disconnect has no participant", stream);
|
||||
return;
|
||||
}
|
||||
|
||||
if (participant === this.localParticipant) {
|
||||
if (connection === this.localParticipant) {
|
||||
|
||||
delete this.participants[participant.getId()];
|
||||
participant.dispose();
|
||||
delete this.participants[connection.getId()];
|
||||
connection.dispose();
|
||||
|
||||
console.log("Unpublishing my media (I'm " + participant.getId() + ")");
|
||||
console.log("Unpublishing my media (I'm " + connection.getId() + ")");
|
||||
delete this.localParticipant;
|
||||
this.openVidu.sendRequest('unpublishVideo', function (error, response) {
|
||||
if (error) {
|
||||
|
|
|
@ -33,7 +33,7 @@ function hide(id: string) {
|
|||
|
||||
export interface StreamOptions {
|
||||
id: string;
|
||||
participant: Connection;
|
||||
connection: Connection;
|
||||
recvVideo: any;
|
||||
recvAudio: any;
|
||||
video: boolean;
|
||||
|
@ -49,6 +49,8 @@ export interface VideoOptions {
|
|||
|
||||
export class Stream {
|
||||
|
||||
public connection: Connection;
|
||||
|
||||
private ee = new EventEmitter();
|
||||
private wrStream: any;
|
||||
private wp: any;
|
||||
|
@ -56,7 +58,6 @@ export class Stream {
|
|||
private video: HTMLVideoElement;
|
||||
private videoElements: VideoOptions[] = [];
|
||||
private elements: HTMLDivElement[] = [];
|
||||
private participant: Connection;
|
||||
private speechEvent: any;
|
||||
private recvVideo: any;
|
||||
private recvAudio: any;
|
||||
|
@ -81,7 +82,7 @@ export class Stream {
|
|||
this.id = "webcam";
|
||||
}
|
||||
|
||||
this.participant = options.participant;
|
||||
this.connection = options.connection;
|
||||
this.recvVideo = options.recvVideo;
|
||||
this.recvAudio = options.recvAudio;
|
||||
this.dataChannel = options.data || false;
|
||||
|
@ -313,12 +314,12 @@ export class Stream {
|
|||
}
|
||||
|
||||
getParticipant() {
|
||||
return this.participant;
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
getId() {
|
||||
if (this.participant) {
|
||||
return this.participant.getId() + "_" + this.id;
|
||||
if (this.connection) {
|
||||
return this.connection.getId() + "_" + this.id;
|
||||
} else {
|
||||
return this.id + "_webcam";
|
||||
}
|
||||
|
@ -330,7 +331,7 @@ export class Stream {
|
|||
|
||||
requestCameraAccess(callback: Callback<Stream>) {
|
||||
|
||||
this.participant.addStream(this);
|
||||
this.connection.addStream(this);
|
||||
|
||||
let constraints = this.mediaConstraints;
|
||||
|
||||
|
@ -424,7 +425,7 @@ export class Stream {
|
|||
let options: any = {
|
||||
videoStream: this.wrStream,
|
||||
mediaConstraints: userMediaConstraints,
|
||||
onicecandidate: this.participant.sendIceCandidate.bind(this.participant),
|
||||
onicecandidate: this.connection.sendIceCandidate.bind(this.connection),
|
||||
}
|
||||
|
||||
if (this.dataChannel) {
|
||||
|
@ -461,7 +462,7 @@ export class Stream {
|
|||
console.log("Constraints of generate SDP offer (subscribing)",
|
||||
offerConstraints);
|
||||
let options = {
|
||||
onicecandidate: this.participant.sendIceCandidate.bind(this.participant),
|
||||
onicecandidate: this.connection.sendIceCandidate.bind(this.connection),
|
||||
connectionConstraints: offerConstraints
|
||||
}
|
||||
this.wp = new kurentoUtils.WebRtcPeer.WebRtcPeerRecvonly(options, error => {
|
||||
|
|
Loading…
Reference in New Issue