BLUSHIF

Untitled

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