BLUSHIF

Untitled

Jul 30th, 2018
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.13 KB | None | 0 0
  1. var webrtc = new SimpleWebRTC({
  2. remoteVideosEl: 'remotesVideos',
  3. localVideoEl: 'localVideo',
  4. autoRequestMedia: true,
  5. detectSpeakingEvents: true,
  6. autoAdjustMic: false,
  7. url: 'https://www.hokucode.com/',
  8. socketio: {
  9. path: "/signal/socket.io"
  10. },
  11. media: {
  12. video: false,
  13. audio: true
  14. },
  15. debug: false
  16. });
  17. var thisNumRand;
  18. var pir;
  19. if (location.protocol == "http:") {
  20. alert("Please use https://www. on our page, otherwise RTC will not function.")
  21. }
  22. function showVolume(el, volume) {
  23. if (!el) {
  24. return
  25. }
  26. if (volume < -45) {
  27. volume = -45
  28. }
  29. if (volume > -20) {
  30. volume = -20
  31. }
  32. el.value = volume
  33. }
  34. function track(name, info) {
  35. if (webrtc && webrtc.connection) {
  36. webrtc
  37. .connection
  38. .emit('metrics', name, info || {})
  39. }
  40. }
  41. webrtc.on('createdPeer', function (peer) {
  42. pir=pir+1;
  43. var pyd = peer.id.substring(0, 6);
  44. for (var i = 0; i < 6; i += 1) {
  45. var strout = 0;
  46. var alphabet = [
  47. "a",
  48. "b",
  49. "c",
  50. "d",
  51. "e",
  52. "f",
  53. "g",
  54. "h",
  55. "i",
  56. "j",
  57. "k",
  58. "l",
  59. "m",
  60. "n",
  61. "o",
  62. "p",
  63. "q",
  64. "r",
  65. "s",
  66. "t",
  67. "u",
  68. "v",
  69. "w",
  70. "x",
  71. "y",
  72. "z",
  73. "A",
  74. "B",
  75. "C",
  76. "D",
  77. "E",
  78. "F",
  79. "G",
  80. "H",
  81. "I",
  82. "J",
  83. "K",
  84. "L",
  85. "M",
  86. "N",
  87. "O",
  88. "P",
  89. "Q",
  90. "R",
  91. "S",
  92. "T",
  93. "U",
  94. "V",
  95. "W",
  96. "X",
  97. "Y",
  98. "Z",
  99. "1",
  100. "2",
  101. "3",
  102. "4",
  103. "5",
  104. "6",
  105. "7",
  106. "8",
  107. "9",
  108. "0",
  109. "-"
  110. ];
  111. var letter = pyd[i];
  112. var letterPosition = alphabet.indexOf(letter) + 1;
  113. strout = strout + letterPosition;
  114. if (i == 0) {
  115. thisNumRand = strout * 26291
  116. }
  117. }
  118. var remotes = document.getElementById('remotes');
  119. if (!remotes) {
  120. return
  121. }
  122. var container = document.createElement('div');
  123. container.className = 'peerContainer';
  124. container.id = 'container_' + webrtc.getDomId(peer);
  125. var tri = document.createElement('tr');
  126. var th = document.createElement('th');
  127. var name = document.createElement('h3');
  128. name.style.color = "#" + thisNumRand;
  129. txn = document.createTextNode("Anon " + thisNumRand);
  130. name.appendChild(txn);
  131. th.appendChild(name);
  132. var thi = document.createElement('th');
  133. var thii = document.createElement('th');
  134. var img = document.createElement('img');
  135. img.src = "speaker.png";
  136. img.height = 50;
  137. img.width = 50;
  138. var mute = document.createElement('a');
  139. var vol = document.createElement('meter');
  140. vol.id = 'volume_' + peer.id;
  141. vol.className = 'volume';
  142. vol.min = -45;
  143. vol.max = -20;
  144. vol.low = -40;
  145. vol.high = -25;
  146. thi.appendChild(mute);
  147. mute.appendChild(img);
  148. thii.appendChild(vol);
  149. tri.appendChild(thi);
  150. tri.appendChild(th);
  151. tri.appendChild(thii);
  152. container.appendChild(tri);
  153. remotes.appendChild(container);
  154. var xnte = 0;
  155. mute.onclick = function () {
  156. var cli = "#" + webrtc.getDomId(peer);
  157. xnte = xnte + 1;
  158. if (xnte % 2 == 0) {
  159. $(cli).prop('muted', true);
  160. img.src = 'muted.png';
  161. webrtc.sendDirectlyToAll('channelMessage','chat', "m")
  162. } else {
  163. $(cli).prop('muted', false);
  164. img.src = 'speaker.png';
  165. webrtc.sendDirectlyToAll('channelMessage','chat', "u")
  166. }
  167. };
  168. if (peer && peer.pc) {
  169. peer.firsttime = true;
  170. peer
  171. .pc
  172. .on('iceConnectionStateChange', function (event) {
  173. var state = peer.pc.iceConnectionState;
  174. container.className = 'peerContainer p2p' + state
  175. .substr(0, 1)
  176. .toUpperCase() + state.substr(1);
  177. switch (state) {
  178. case 'connected':
  179. case 'completed':
  180. mute.style.visibility = 'visible';
  181. if (peer.firsttime) {
  182. peer.firsttime = false;
  183. track('iceSuccess', {
  184. session: peer.sid,
  185. peerprefix: peer.browserPrefix,
  186. prefix: webrtc.capabilities.prefix,
  187. version: webrtc.capabilities.browserVersion
  188. })
  189. }
  190. pir=pir-1;
  191. break;
  192. case 'closed':container.remove();
  193. break
  194. }
  195. })
  196. }
  197. remotes.appendChild(container)
  198. });
  199. webrtc.on('volumeChange', function (volume, threshold) {
  200. showVolume(document.getElementById('localVolume'), volume)
  201. });
  202. webrtc.on('remoteVolumeChange', function (peer, volume) {
  203. showVolume(document.getElementById('volume_' + peer.id), volume)
  204. });
  205. webrtc.on('videoRemoved', function (videoEL, peer) {pir=pir-1});
  206. var totalSeconds = 0;
  207. setInterval(setTime, 1000);
  208. function setTime() {
  209. totalSeconds += 1;
  210. if (totalSeconds > 300) {
  211. pir=pir-1;
  212. webrtc.leaveRoom();
  213. rmc("ind")
  214. }
  215. }
  216. var px = 0;
  217. function mute() {
  218. px = px + 1;
  219. if (px % 2 == 0) {
  220. webrtc.unmute();
  221. $("#urimg").attr("src", "speaker.png")
  222. } else {
  223. webrtc.mute();
  224. $("#urimg").attr("src", "muted.png")
  225. }
  226. }
  227. var rba;
  228. window.addEventListener('load', function () {
  229. rmc("ind")
  230. }, false);
  231. function rmc(rme) {
  232. if (rme != "ind") {
  233. webrtc.leaveRoom();
  234. webrtc.joinRoom(rme);
  235. rba=rme;
  236. $('#bdrp').text(rme);
  237. vxt("v")
  238. } else {
  239. webrtc.stopLocalVideo();
  240. webrtc.leaveRoom();
  241. vxt("i")
  242. }
  243. }
  244. function tsh() {
  245. $('#tos').css('display', 'inline')
  246. }
  247. function vxt(val) {
  248. if (val == "i") {
  249. $('#indiv').css('display', 'none');
  250. $('#cdiv').css('display', 'inline')
  251. } else {
  252. $('#indiv').css('display', 'inline');
  253. $('#cdiv').css('display', 'none')
  254. }
  255. }
  256. webrtc.on('channelMessage', function (peer, label , data) {
  257. if(data.type === 'chat'){
  258. var pmu;
  259. if(data=="m"){pmu=pmu+1;}else if(data=="u"){pmu=pmu-1;}
  260. if(pmu>pir){
  261. webrtc.stopLocalVideo();
  262. webrtc.leaveRoom();
  263. }else{
  264. console.log(pmu+"_"+pir);
  265. }
  266. }
  267. });
  268. //All code here excluding jquery and the swrtc library is the property of JST.
Advertisement
Add Comment
Please, Sign In to add comment