Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var webrtc = new SimpleWebRTC({
- remoteVideosEl: 'remotesVideos',
- localVideoEl: 'localVideo',
- autoRequestMedia: true,
- detectSpeakingEvents: true,
- autoAdjustMic: false,
- url: 'https://www.hokucode.com/',
- socketio: {
- path: "/signal/socket.io"
- },
- media: {
- video: false,
- audio: true
- },
- debug: false
- });
- var thisNumRand;
- var pir;
- if (location.protocol == "http:") {
- alert("Please use https://www. on our page, otherwise RTC will not function.")
- }
- function showVolume(el, volume) {
- if (!el) {
- return
- }
- if (volume < -45) {
- volume = -45
- }
- if (volume > -20) {
- volume = -20
- }
- el.value = volume
- }
- function track(name, info) {
- if (webrtc && webrtc.connection) {
- webrtc
- .connection
- .emit('metrics', name, info || {})
- }
- }
- webrtc.on('createdPeer', function (peer) {
- pir=pir+1;
- var pyd = peer.id.substring(0, 6);
- for (var i = 0; i < 6; i += 1) {
- var strout = 0;
- var alphabet = [
- "a",
- "b",
- "c",
- "d",
- "e",
- "f",
- "g",
- "h",
- "i",
- "j",
- "k",
- "l",
- "m",
- "n",
- "o",
- "p",
- "q",
- "r",
- "s",
- "t",
- "u",
- "v",
- "w",
- "x",
- "y",
- "z",
- "A",
- "B",
- "C",
- "D",
- "E",
- "F",
- "G",
- "H",
- "I",
- "J",
- "K",
- "L",
- "M",
- "N",
- "O",
- "P",
- "Q",
- "R",
- "S",
- "T",
- "U",
- "V",
- "W",
- "X",
- "Y",
- "Z",
- "1",
- "2",
- "3",
- "4",
- "5",
- "6",
- "7",
- "8",
- "9",
- "0",
- "-"
- ];
- var letter = pyd[i];
- var letterPosition = alphabet.indexOf(letter) + 1;
- strout = strout + letterPosition;
- if (i == 0) {
- thisNumRand = strout * 26291
- }
- }
- var remotes = document.getElementById('remotes');
- if (!remotes) {
- return
- }
- var container = document.createElement('div');
- container.className = 'peerContainer';
- container.id = 'container_' + webrtc.getDomId(peer);
- var tri = document.createElement('tr');
- var th = document.createElement('th');
- var name = document.createElement('h3');
- name.style.color = "#" + thisNumRand;
- txn = document.createTextNode("Anon " + thisNumRand);
- name.appendChild(txn);
- th.appendChild(name);
- var thi = document.createElement('th');
- var thii = document.createElement('th');
- var img = document.createElement('img');
- img.src = "speaker.png";
- img.height = 50;
- img.width = 50;
- var mute = document.createElement('a');
- var vol = document.createElement('meter');
- vol.id = 'volume_' + peer.id;
- vol.className = 'volume';
- vol.min = -45;
- vol.max = -20;
- vol.low = -40;
- vol.high = -25;
- thi.appendChild(mute);
- mute.appendChild(img);
- thii.appendChild(vol);
- tri.appendChild(thi);
- tri.appendChild(th);
- tri.appendChild(thii);
- container.appendChild(tri);
- remotes.appendChild(container);
- var xnte = 0;
- mute.onclick = function () {
- var cli = "#" + webrtc.getDomId(peer);
- xnte = xnte + 1;
- if (xnte % 2 == 0) {
- $(cli).prop('muted', true);
- img.src = 'muted.png';
- webrtc.sendDirectlyToAll('channelMessage','chat', "m")
- } else {
- $(cli).prop('muted', false);
- img.src = 'speaker.png';
- webrtc.sendDirectlyToAll('channelMessage','chat', "u")
- }
- };
- if (peer && peer.pc) {
- peer.firsttime = true;
- peer
- .pc
- .on('iceConnectionStateChange', function (event) {
- var state = peer.pc.iceConnectionState;
- container.className = 'peerContainer p2p' + state
- .substr(0, 1)
- .toUpperCase() + state.substr(1);
- switch (state) {
- case 'connected':
- case 'completed':
- mute.style.visibility = 'visible';
- if (peer.firsttime) {
- peer.firsttime = false;
- track('iceSuccess', {
- session: peer.sid,
- peerprefix: peer.browserPrefix,
- prefix: webrtc.capabilities.prefix,
- version: webrtc.capabilities.browserVersion
- })
- }
- pir=pir-1;
- break;
- case 'closed':container.remove();
- break
- }
- })
- }
- remotes.appendChild(container)
- });
- webrtc.on('volumeChange', function (volume, threshold) {
- showVolume(document.getElementById('localVolume'), volume)
- });
- webrtc.on('remoteVolumeChange', function (peer, volume) {
- showVolume(document.getElementById('volume_' + peer.id), volume)
- });
- webrtc.on('videoRemoved', function (videoEL, peer) {pir=pir-1});
- var totalSeconds = 0;
- setInterval(setTime, 1000);
- function setTime() {
- totalSeconds += 1;
- if (totalSeconds > 300) {
- pir=pir-1;
- webrtc.leaveRoom();
- rmc("ind")
- }
- }
- var px = 0;
- function mute() {
- px = px + 1;
- if (px % 2 == 0) {
- webrtc.unmute();
- $("#urimg").attr("src", "speaker.png")
- } else {
- webrtc.mute();
- $("#urimg").attr("src", "muted.png")
- }
- }
- var rba;
- window.addEventListener('load', function () {
- rmc("ind")
- }, false);
- function rmc(rme) {
- if (rme != "ind") {
- webrtc.leaveRoom();
- webrtc.joinRoom(rme);
- rba=rme;
- $('#bdrp').text(rme);
- vxt("v")
- } else {
- webrtc.stopLocalVideo();
- webrtc.leaveRoom();
- vxt("i")
- }
- }
- function tsh() {
- $('#tos').css('display', 'inline')
- }
- function vxt(val) {
- if (val == "i") {
- $('#indiv').css('display', 'none');
- $('#cdiv').css('display', 'inline')
- } else {
- $('#indiv').css('display', 'inline');
- $('#cdiv').css('display', 'none')
- }
- }
- webrtc.on('channelMessage', function (peer, label , data) {
- if(data.type === 'chat'){
- var pmu;
- if(data=="m"){pmu=pmu+1;}else if(data=="u"){pmu=pmu-1;}
- if(pmu>pir){
- webrtc.stopLocalVideo();
- webrtc.leaveRoom();
- }else{
- console.log(pmu+"_"+pir);
- }
- }
- });
- //All code here excluding jquery and the swrtc library is the property of JST.
Advertisement
Add Comment
Please, Sign In to add comment