Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. var options = {
  2. hosts: {
  3. domain: 'hristo.jitsi.net',
  4. muc: 'conference.hristo.jitsi.net', // FIXME: use XEP-0030
  5. bridge: 'jitsi-videobridge.hristo.jitsi.net', // FIXME: use XEP-0030
  6. },
  7. bosh: '//hristo.jitsi.net/http-bind', // FIXME: use xep-0156 for that
  8. clientNode: 'http://jitsi.org/jitsimeet', // The name of client node advertised in XEP-0115 'c' stanza
  9. }
  10. var confOptions = {
  11. openSctp: true
  12. }
  13. /**
  14. * Handles local tracks.
  15. * @param tracks Array with JitsiTrack objects
  16. */
  17. function onLocalTracks(tracks)
  18. {
  19. localTracks = tracks;
  20. for(var i = 0; i < localTracks.length; i++)
  21. {
  22. localTracks[i].addEventListener(JitsiMeetJS.events.track.TRACK_AUDIO_LEVEL_CHANGED,
  23. function (audioLevel) {
  24. console.debug("Audio Level local: " + audioLevel);
  25. });
  26. localTracks[i].addEventListener(JitsiMeetJS.events.track.TRACK_MUTE_CHANGED,
  27. function () {
  28. console.debug("local track muted");
  29. });
  30. localTracks[i].addEventListener(JitsiMeetJS.events.track.TRACK_STOPPED,
  31. function () {
  32. console.debug("local track stoped");
  33. });
  34. if(localTracks[i].getType() == "video") {
  35. $("body").append("<video autoplay='1' id='localVideo" + i + "' />");
  36. localTracks[i].attach($("#localVideo" + i ));
  37. } else {
  38. $("body").append("<audio autoplay='1' id='localAudio" + i + "' />");
  39. localTracks[i].attach($("#localAudio" + i ));
  40. }
  41. }
  42. }
  43. /**
  44. * Handles remote tracks
  45. * @param track JitsiTrack object
  46. */
  47. function onRemoteTrack(track) {
  48. if(track.isLocal())
  49. return;
  50. var participant = track.getParticipantId();
  51. if(!remoteTracks[participant])
  52. remoteTracks[participant] = [];
  53. var idx = remoteTracks[participant].push(track);
  54. track.addEventListener(JitsiMeetJS.events.track.TRACK_AUDIO_LEVEL_CHANGED,
  55. function (audioLevel) {
  56. console.debug("Audio Level remote: " + audioLevel);
  57. });
  58. track.addEventListener(JitsiMeetJS.events.track.TRACK_MUTE_CHANGED,
  59. function () {
  60. console.debug("remote track muted");
  61. });
  62. track.addEventListener(JitsiMeetJS.events.track.TRACK_STOPPED,
  63. function () {
  64. console.debug("remote track stoped");
  65. });
  66. var id = participant + track.getType() + idx;
  67. if(track.getType() == "video") {
  68. $("body").append("<video autoplay='1' id='" + participant + "video" + idx + "' />");
  69. } else {
  70. $("body").append("<audio autoplay='1' id='" + participant + "audio' />");
  71. }
  72. track.attach($("#" + id));
  73. }
  74. /**
  75. * That function is executed when the conference is joined
  76. */
  77. function onConferenceJoined () {
  78. console.log("conference joined!");
  79. for(var i = 0; i < localTracks.length; i++)
  80. room.addTrack(localTracks[i]);
  81. }
  82. function onUserLeft(id) {
  83. if(!remoteTracks[id])
  84. return;
  85. var tracks = remoteTracks[id];
  86. for(var i = 0; i< tracks.length; i++)
  87. tracks[i].detach($("#" + id + tracks[i].getType()))
  88. }
  89. /**
  90. * That function is called when connection is established successfully
  91. */
  92. function onConnectionSuccess(){
  93. room = connection.initJitsiConference("conference2", confOptions);
  94. room.on(JitsiMeetJS.events.conference.TRACK_ADDED, onRemoteTrack);
  95. room.on(JitsiMeetJS.events.conference.TRACK_REMOVED, function (track) {
  96. console.debug("track removed!!!" + track);
  97. });
  98. room.on(JitsiMeetJS.events.conference.CONFERENCE_JOINED, onConferenceJoined);
  99. room.on(JitsiMeetJS.events.conference.USER_JOINED, function(id){ remoteTracks[id] = [];});
  100. room.on(JitsiMeetJS.events.conference.USER_LEFT, onUserLeft);
  101. room.on(JitsiMeetJS.events.conference.TRACK_MUTE_CHANGED, function (track) {
  102. console.debug(track.getType() + " - " + track.isMuted());
  103. });
  104. room.on(JitsiMeetJS.events.conference.DISPLAY_NAME_CHANGED, function (userID, displayName) {
  105. console.debug(userID + " - " + displayName);
  106. });
  107. room.on(JitsiMeetJS.events.conference.TRACK_AUDIO_LEVEL_CHANGED,
  108. function(userID, audioLevel){
  109. console.log(userID + " - " + audioLevel);
  110. });
  111. room.join();
  112. };
  113. /**
  114. * This function is called when the connection fail.
  115. */
  116. function onConnectionFailed(){console.error("Connection Failed!")};
  117. /**
  118. * This function is called when we disconnect.
  119. */
  120. function disconnect(){
  121. console.log("disconnect!");
  122. connection.removeEventListener(JitsiMeetJS.events.connection.CONNECTION_ESTABLISHED, onConnectionSuccess);
  123. connection.removeEventListener(JitsiMeetJS.events.connection.CONNECTION_FAILED, onConnectionFailed);
  124. connection.removeEventListener(JitsiMeetJS.events.connection.CONNECTION_DISCONNECTED, disconnect);
  125. }
  126. function unload() {
  127. // room.leave();
  128. connection.disconnect();
  129. }
  130. $(window).bind('beforeunload', unload);
  131. $(window).bind('unload', unload);
  132. // JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.ERROR);
  133. var initOptions = {
  134. disableAudioLevels: true,
  135. // Desktop sharing method. Can be set to 'ext', 'webrtc' or false to disable.
  136. desktopSharingChromeMethod: 'ext',
  137. // The ID of the jidesha extension for Chrome.
  138. desktopSharingChromeExtId: 'mbocklcggfhnbahlnepmldehdhpjfcjp',
  139. // The media sources to use when using screen sharing with the Chrome
  140. // extension.
  141. desktopSharingChromeSources: ['screen', 'window'],
  142. // Required version of Chrome extension
  143. desktopSharingChromeMinExtVersion: '0.1',
  144. // The ID of the jidesha extension for Firefox. If null, we assume that no
  145. // extension is required.
  146. desktopSharingFirefoxExtId: null,
  147. // Whether desktop sharing should be disabled on Firefox.
  148. desktopSharingFirefoxDisabled: true,
  149. // The maximum version of Firefox which requires a jidesha extension.
  150. // Example: if set to 41, we will require the extension for Firefox versions
  151. // up to and including 41. On Firefox 42 and higher, we will run without the
  152. // extension.
  153. // If set to -1, an extension will be required for all versions of Firefox.
  154. desktopSharingFirefoxMaxVersionExtRequired: -1,
  155. // The URL to the Firefox extension for desktop sharing.
  156. desktopSharingFirefoxExtensionURL: null
  157. }
  158. JitsiMeetJS.init(initOptions).then(function(){
  159. connection = new JitsiMeetJS.JitsiConnection(null, null, options);
  160. connection.addEventListener(JitsiMeetJS.events.connection.CONNECTION_ESTABLISHED, onConnectionSuccess);
  161. connection.addEventListener(JitsiMeetJS.events.connection.CONNECTION_FAILED, onConnectionFailed);
  162. connection.addEventListener(JitsiMeetJS.events.connection.CONNECTION_DISCONNECTED, disconnect);
  163. connection.connect();
  164. JitsiMeetJS.createLocalTracks({devices: ["audio", "video"]}).
  165. then(onLocalTracks).catch(function (error) {
  166. console.log(error);
  167. });
  168. }).catch(function (error) {
  169. console.log(error);
  170. });
  171. var connection = null;
  172. var room = null;
  173. var localTracks = [];
  174. var remoteTracks = {};