UNPKG

kurento-group-call

Version:

Simple javascript library used to initiate a group call (many to many video and audio call) using Kurento Media Server

90 lines (75 loc) 2.73 kB
/* * (C) Copyright 2014 Kurento (http://kurento.org/) * * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser General Public License * (LGPL) version 2.1 which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl-2.1.html * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * */ const PARTICIPANT_MAIN_CLASS = 'participant main'; const PARTICIPANT_CLASS = 'participant'; /** * Creates a video element for a new participant * * @param {String} name - the name of the new participant, to be used as tag * name of the video element. * The tag of the new element will be 'video<name>' * @return */ function Participant(name) { this.name = name; var container = document.createElement('div'); container.className = isPresentMainParticipant() ? PARTICIPANT_CLASS : PARTICIPANT_MAIN_CLASS; container.id = name; var span = document.createElement('span'); var video = document.createElement('video'); var rtcPeer; container.appendChild(video); container.appendChild(span); container.onclick = switchContainerClass; document.getElementById('participants').appendChild(container); span.appendChild(document.createTextNode(name)); video.id = 'video-' + name; video.autoplay = true; video.controls = false; this.getElement = function() { return container; } this.getVideoElement = function() { return video; } function switchContainerClass() { if (container.className === PARTICIPANT_CLASS) { var elements = Array.prototype.slice.call(document.getElementsByClassName(PARTICIPANT_MAIN_CLASS)); elements.forEach(function(item) { item.className = PARTICIPANT_CLASS; }); container.className = PARTICIPANT_MAIN_CLASS; } else { container.className = PARTICIPANT_CLASS; } } function isPresentMainParticipant() { return ((document.getElementsByClassName(PARTICIPANT_MAIN_CLASS)).length != 0); } this.offerToReceiveVideo = function(offerSdp, wp){ console.log('Invoking SDP offer callback function'); var msg = { id : "receiveVideoFrom", sender : name, sdpOffer : offerSdp }; sendMessage(msg); } Object.defineProperty(this, 'rtcPeer', { writable: true}); this.dispose = function() { console.log('Disposing participant ' + this.name); this.rtcPeer.dispose(); container.parentNode.removeChild(container); }; }