↑ www.RTCMultiConnection.org

RTCMultiConnection Docs | Demos!

HOME © Muaz Khan . @WebRTCWeb . Github . Latest issues . What's New?

  1. Getting Started Guide
  2. API Reference

    1. constructor
      var connection = new RTCMultiConnection();
      
    2. socketURL property
      connection.socketURL = 'https://onlyChangingPort.com:8888/';
      connection.socketURL = 'https://separateDomain.com:443/';
      connection.socketURL = '/'; // same domain
      
      // or a free signaling server
      connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';
      
    3. enableLogs property
      // to disable logs
      connection.enableLogs = false;
      
    4. getAllParticipants method
      connection.getAllParticipants().forEach(function(participantId) {
          // typeof participantId === 'string'
          var peer = connection.peers[participantId];
          console.log(peer.connection, peer.userid, peer.streams, peer.channels);
      });
      
    5. session object
      connection.session = {
           audio:     true, // by default, it is true
           video:     true, // by default, it is true
           screen:    false,
           
           data:      false,
           
           oneway:    false,
           broadcast: false
      };
      
    6. open method
      connection.open( 'room-id' );
      
      // or
      connection.open( 'room-id', function() {
          alert('Room has been created.');
      });
      
      // or
      var isPublicRoom = true;
      connection.open( 'room-id', isPublicRoom );
      
    7. join method
      connection.join( 'room-id' );
      
      // or
      var password = 'xyz';
      connection.join( 'room-id', password );
      
    8. openOrJoin method
      connection.openOrJoin( 'room-id' );
      
      // or
      connection.openOrJoin( 'room-id', function(isRoomExists, roomid) {
          alert(isRoomExists ? 'You joined room' : 'You created room');
      });
      
    9. checkPresence method
      connection.checkPresence( 'room-id', function(isRoomExists, roomid) {
          if(isRoomExists) {
              connection.join(roomid);
          }
          else {
              connection.open(roomid);
          }
      });
      
    10. connectSocket method
      connection.connectSocket();
      
      // or
      connection.connectSocket( function() {
          alert('Successfully connected to socket.io server.');
      
          connection.socket.emit('howdy', 'hello');
      });
      
    11. disconnectWith method
      connection.disconnectWith( 'remote-userid' );
      
    12. onUserStatusChanged event
      connection.onUserStatusChanged = function(event) {
          var isOnline = event.status === 'online';
          var isOffline = event.status === 'offline';
      
          var targetUserId = event.userid;
          var targetUserExtraInfo = event.extra;
      };
      
    13. onstream event
      connection.onstream = function(event) {
          if (event.isScreen) {
              // screenVideo.src = event.blobURL;
              screenDiv.appendChild(event.mediaElement);
          }
      
          if (event.isAudio) {
              audioOnlyTag.src = event.blobURL;
          }
      
          if (event.isVideo) {
              // audioPlusVideo.src = event.blobURL;
              // videoOnly.src = event.blobURL;
              videoDiv.appendChild(event.mediaElement);
          }
      };
      
    14. onstreamended event
      connection.onstreamended = function (e) {
          // e.mediaElement (audio or video element)
          // e.stream     native MediaStream object
          // e.streamid   unique identifier of the stream synced from stream sender
          // e.session {audio: true, video: true}
          // e.blobURL
          // e.type     "local" or "remote"
          // e.extra
          // e.userid   the person who shared stream with you!
          
          // easiest way to remove relevant element!
          e.mediaElement.parentNode.removeChild(e.mediaElement);
          
          // e.isVideo ---- if it is a  Video stream
          // e.isAudio ---- if it is an Audio stream
      }
      
    15. setCustomSocketHandler method
      // link => /dev/globals.js
      // link => /dev/FirebaseConnection.js
      
      // below line replaces FirebaseConnection
      connection.setCustomSocketHandler(FirebaseConnection);
      
    16. updateExtraData method
      connection.updateExtraData();
      
    17. onExtraDataUpdated event
      connection.onExtraDataUpdated = function(event) {
          var extra = event.extra;
          var targetUserId = event.userid;
      };
      
    18. becomePublicModerator method
      connection.becomePublicModerator();
      
    19. getPublicModerators method
      connection.getPublicModerators( function(arrayOfModerators) {
          arrayOfModerators.forEach(function(moderator) {
              // moderator.extra
              connection.join(moderator.userid);
          });
      });
      
    20. socketCustomParameters property
      // starts with "&"
      // &fullName=Muaz
      // &meetingId=xyz
      connection.socketCustomParameters = '&fullName=Muaz&country=PK&meetingId=xyz';
      
    21. isInitiator
      if(connection.isInitiator) {
          connection.close(); // close entire session
      }
      
    22. onNewSession
      var sessions = {};
      connection.onNewSession = function (session) {
          if (sessions[session.sessionid]) return;
          sessions[session.sessionid] = session;
      
          connection.join();
      };
      
    23. connect method
      connection.connect('room-id');
      
    24. channel-id
      // via constructor
      var connect = new RTCMultiConnection('channel-id');
      
      // via open/connect methods
      connection.open('channel-id');
      
      connection.connect('channel-id');
      
    25. sessionid
      connection.sessionid = 'unique-room-id';
      
    26. userid
      connection.userid = 'custom-user-id';
      
    27. send
      connection.send(file || data || 'logest-text-message');
      
    28. captureUserMedia
      var session = {
          audio: true
      };
      
      connection.captureUserMedia(function (mediaStream) { }, session);
      
    29. direction
      connection.direction = 'one-to-one';
      connection.direction = 'one-way';
      
    30. getDevices
      connection.getDevices(function(devices){
          for (var device in devices) {
              device = devices[device];
              
              // device.kind == 'audio' || 'video'
              console.log(device.id, device.label);
          }
      });
      
    31. selectDevices
      connection.selectDevices(firstDeviceID, secondDeviceID);
      
    32. interval
      connection.interval = 3000;
      
    33. transmitRoomOnce
      connection.transmitRoomOnce = false;
      
    34. maxParticipantsAllowed
      connection.maxParticipantsAllowed = 256;
      
    35. onspeaking
      connection.onspeaking = function (e) {
          // e.streamid, e.userid, e.stream, etc.
          e.mediaElement.style.border = '1px solid red';
      };
      
    36. onsilence
      
      connection.onsilence = function (e) {
          // e.streamid, e.userid, e.stream, etc.
          e.mediaElement.style.border = '';
      };
      
    37. openSignalingChannel
      connection.openSignalingChannel = function(config) {};
      
    38. session-initiator
    39. session-participant
    40. renegotiation
    41. disableDtlsSrtp
      connection.disableDtlsSrtp = false;
      
    42. addStream
      connection.addStream({
          audio: true,
          video: true
      });
      
    43. removeStream
      connection.removeStream('stream-id');
      
      // remove all screen streams.
      // you can use "remove all video streams" by passing "video"
      // or "remove all audio streams" by passing "audio"
      connection.removeStream('screen');
      
      // remove-all but multiple streams
      // i.e. remove all audio and video streams
      // or remove all audio and screen streams
      connection.removeStream({
          screen: true,
          audio: true
      });
      
    44. attachStreams
      connection.attachStreams.push(mediaStream1, mediaStream2);
      
    45. startRecording
      connection.streams['stream-id'].startRecording({
          audio: true,
          video: true
      });
      
    46. stopRecording
      // stop single audio stream
      connection.streams['stream-id'].stopRecording(function (blob) {
          // POST "Blob" to PHP/other server using FormData/XHR2
      }, {audio:true});
      
      // stop single video stream
      connection.streams['stream-id'].stopRecording(function (blob) {
          // POST "Blob" to PHP/other server using FormData/XHR2
      }, {video:true});
      
      // stop both audio/video streams
      connection.streams['stream-id'].stopRecording(function (audioBlob, videoBlob) {
          // POST both audio/video "Blobs" to PHP/other server using single FormData/XHR2
      }, {audio:true, video:true} );
      
    47. detachStreams
      connection.detachStreams.push(streamid1, streamid2);
      
    48. dontAttachStream
      connection.dontAttachStream = false;
      
    49. dontCaptureUserMedia
      connection.dontCaptureUserMedia = false;
      
    50. autoCloseEntireSession
      connection.autoCloseEntireSession = false;
      
    51. autoSaveToDisk
      connection.autoSaveToDisk = false;
      
    52. bandwidth
      connection.bandwidth = {
          audio: 50,
          video: 256,
          data: 1638400
      };
      
    53. body
      <div class="container"></div>
      connection.body = document.querySelector('.container');
      
    54. candidates
      connection.candidates = {
           turn:     true,
           stun:     false,
           host:     false
      };
      
    55. channels
      connection.channels['user-id'].send(file || data || 'text');
      
    56. close
      connection.close();
      
    57. leave
      connection.leave();
      
    58. eject
      connection.eject(userid);
      
    59. onleave
      connection.onleave = function(e) {
          // e.userid
          // e.extra
      };
      
    60. onMediaError
      connection.onMediaError = function (error) {
          console.error(error);
      }
      
    61. devices
      for (var device in connection.devices) {
          device = connection.devices[device];
      
          // device.kind == 'audio' || 'video'
          console.log(device.id, device.label);
      }
      
    62. extra
      connection.extra = {
          username: 'muazkh',
          fullname: 'Muaz Khan',
          email: 'muazkh@gmail.com'
      };
      
    63. fileQueue
    64. media
      // Enjoy full-hd video streaming
      connection.media.min(1920,1080);
      connection.media.max(1920,1080);
      
      // Enjoy hd video streaming
      connection.media.min(1280,720);
      connection.media.max(1280,720);
      
      // other possible values
      connection.media.min(960,720);
      connection.media.min(640,360); // -------- it is default
      connection.media.min(640,480);
      connection.media.min(320,240);
      connection.media.min(320,180);
      
      connection.media.minAspectRatio = 1.77;
      
    65. mediaConstraints
      connection.mediaConstraints.mandatory = {
          minWidth: 1280,
          maxWidth: 1280,
          minHeight: 720,
          maxHeight: 720,
          minFrameRate: 30
      };
      
      // it is same like "connection.session={audio:false}"
      connection.mediaConstraints.audio = false;
      
    66. sdpConstraints
      connection.sdpConstraints.mandatory = {
          OfferToReceiveAudio: false,
          OfferToReceiveVideo: false,
          VoiceActivityDetection: false,
          IceRestart: true
      };
      
    67. mute
      connection.streams['stream-id'].mute({
          audio: true,
          video: true
      });
      
    68. unmute
      connection.streams['stream-id'].unmute({
          audio: true,
          video: true
      });
      
    69. stop
      // stop all local media streams
      connection.streams.stop('local');
      
      // stop all remote media streams
      connection.streams.stop('remote');
      
      // stop all media streams
      connection.streams.stop();
      
    70. onmute
      connection.onmute = function(e) {
         e.mediaElement.setAttribute('poster', 'photo.jpg');
      };
      
    71. onunmute
      connection.onunmute = function(e) {
         e.mediaElement.removeAttribute('poster');
      };
      
    72. onmessage
      connection.onmessage = function(e) {
         // e.data
         // e.userid
         // e.extra
      };
      
    73. onopen
      connection.onopen = function(e) {
         // e.userid
         // e.extra
      };
      
    74. onclose
      connection.onclose = function(e) {
         // e.userid
         // e.extra
      };
      
    75. onerror
      connection.onerror = function(e) {
         // e.userid
         // e.extra
      };
      
    76. onFileStart
    77. onFileEnd
    78. onFileProgress
    79. peers
      // add new stream to existing peer connection
      connection.peers['user-id'].addStream({
          screen: true,
          oneway: true
      });
      
      // renegotiate while adding external media streams
      connection.peers['user-id'].renegotiate(Custom_MediaStream);
      
      // renegotiate while no media stream is added
      connection.peers['user-id'].renegotiate();
      
      // change bandwidth at runtime
      connection.peers['user-id'].changeBandwidth({
          audio: 20,
          video: 30,
          data: 50
      });
      
      // send private message to target user; privacy is guaranteed!
      connection.peers['user-id'].sendCustomMessage('private-message');
      connection.peers['user-id'].onCustomMessage = function(privateMessage) {
          console.log('private custom message', privateMessage);
      };
      
      // to drop call; same like skype!
      connection.peers['user-id'].drop();
      
      // to hold call; same like skype!
      connection.peers['user-id'].hold();
      
      // to unhold call; same like skype!
      connection.peers['user-id'].unhold();
      
    80. preferSCTP
      // prefer RTP and disable SCTP
      connection.preferSCTP = false;
      
    81. streams
      connection.streams.mute();
      connection.streams.unmute();
      
    82. skipRTCMultiConnectionLogs
      // You can disable all logs by setting "window.skipRTCMultiConnectionLogs" to true.
      window.skipRTCMultiConnectionLogs = true;
      
    83. firebase
      connection.firebase = 'chat';
      
    84. Admin/Guest Scenarios
      var you = new RTCMultiConnection();
      var he = new RTCMultiConnection();
      
      you.onRequest = function (his_id) {
          // you're "quickly" accepting his invitation
          // you can show a dialog-box too; to allow 
          // user accept/reject invitation
          you.accept(his_id);
      };
      
      // he is inviting you
      he.request(your_id);
      
      // following lines are necessary because we need to 
      // set signaling gateways
      you.connect();
      he.connect();
      
    85. onRequest
      connection.onRequest = function (request) {
          // 2nd parameter "extra" is optional
          connection.accept(request);
      };
      
    86. request
      // use "user-id" to invite a user
      connection.request('userid');
      
    87. accept
      connection.onRequest = function (request) {
          connection.accept(request);
      };
      
    88. reject
      connection.onRequest = function (request) {
          connection.reject(request);
      };
      
    89. onstats
      connection.onstats = function (stats, callee) {
          // callee is busy
          if (stats == 'busy') {}
          
          // callee rejected the request
          if (stats == 'rejected') {}
      
          // callee accepted caller's request
          if (stats == 'accepted') {}
          
          // callee.userid || callee.extra
      };
      
    90. userType
      // if you want to set "admin"
      connection.userType = 'admin';
      
      // if you want to set "guest"
      connection.userType = 'guest';
      
    91. onAdmin
      connection.onAdmin = function (admin) {
          // Lets call admin using his userid
          connection.request(admin.userid);
      };
      
    92. onGuest
      connection.onGuest = function (guest) {
          // Lets call guest using his userid
          connection.request(guest.userid);
      };
      
    93. takeSnapshot
      connection.takeSnapshot('userid', function(snapshot) {
          image.src = snapshot;
      });
      
    94. snapshots
      // iterate over all snapshots/
      for(var snapshot in connection.snapshots) {
          snapshot = connection.snapshots[snapshot];
      }
      
      // or, to access individual snapshot later
      image.src = connection.snapshots['userid'];
      
    95. getStats
      connection.getStats(function(stat) {
          // stat.numberOfConnectedUsers
      });
      
    96. stats
      for(var stat in connection.stats) {
          console.log(stat, connection.stats[stat]);
      }
      
      // you can directly access "numberOfConnectedUsers" later like this:
      console.log(connection.stats.numberOfConnectedUsers);
      
    97. caniuse
      console.log( connection.caniuse.RTCPeerConnection );
      console.log( connection.caniuse.getUserMedia );
      console.log( connection.caniuse.AudioContext );
      console.log( connection.caniuse.ScreenSharing );
      console.log( connection.caniuse.RtpDataChannels );
      console.log( connection.caniuse.SctpDataChannels );
      
      
      connection.caniuse.checkIfScreenSharingFlagEnabled(function (isFlagEnabled, warning) {
          if (isFlagEnabled) {
              console.error('Multi-capturing of screen is not allowed. Capturing process is denied. Try chrome >= M31.');
          }
      
          if (warning) console.error(warning);
      
          else if (!isFlagEnabled) {
              console.error('It seems that "Enable screen capture support in getUserMedia" flag is not enabled.');
          }
      });
      
    98. iceServers
      var iceServers = [];
      
      // STUN server
      iceServers.push({
          url: 'stun:23.21.150.121:3478'
      });
      
      // TURN server
      iceServers.push({
          url: 'turn:turn.bistri.com:80',
          credential: 'homeo',
          username: 'homeo'
      });
      
      connection.iceServers = iceServers;
      
    99. optionalArgument
      connection.optionalArgument = {
          optional: [{
              DtlsSrtpKeyAgreement: true
          }, {
              googImprovedWifiBwe: true
          }, {
              googScreencastMinBitrate: 300
          }],
          mandatory: {}
      };
      
    100. dataChannelDict
      connection.dataChannelDict = {
          maxRetransmits: 0,
          ordered: false,
          outOfOrderAllowed: false
      };
      
    101. drop
      connection.drop();
      
    102. ondrop
      // "ondrop" is fired; if media-connection is droppped by other user
      connection.ondrop = function() { };
      
    103. sendCustomMessage
      connection.sendCustomMessage(any_kind_of_data |or| string_message);
      
    104. onCustomMessage
      connection.onCustomMessage = function(message) { };
      
    105. remove
      connection.remove('user-id');
      
    106. refresh
      connection.refresh();
      
    107. chunkSize
      // for chrome-to-chrome data streaming only!
      connection.chunkSize = 64 * 1000;
      
      // default value is 15k because Firefox's receiving limit is 16k!
      connection.chunkSize = 15 * 1000;
      
    108. chunkInterval
      // for RTP-data channels; chunk-interval is 500
      connection.chunkInterval = 500;
      
      // for SCTP-data channels; chunk-interval is 100
      connection.chunkInterval = 100;
      
    109. renegotiate
      // renegotiate with/without media streams!
      connection.renegotiate(Custom_MediaStream);
      
    110. onhold
      // hold call same like skype
      connection.peers['user-id'].hold();
      
      // fired if call is on hold
      connection.onhold = function(e) {
      	// e.mediaElement
      };
      
    111. onunhold
      // unhold call same like skype
      connection.peers['user-id'].unhold();
      
      // fired if call is resumed from hold state
      connection.onunhold = function(e) {
      	// e.mediaElement
      };
      
    112. saveToDisk
      // "fileName" is optional
      connection.saveToDisk(fileURL, fileName);
      
      // you can save recorded blob to disk like this:
      connection.streams['stream-id'].stopRecording(function (audioBlob, videoBlob) {
          connection.saveToDisk(audioBlob);
          connection.saveToDisk(videoBlob);
      }, {audio:true, video:true} );
      
    113. Translator
      connection.Translator.TranslateText(textToConvert, function(convertedText) {
           console.log(convertedText);
      });
      
    114. autoTranslateText
      connection.autoTranslateText = true;
      
    115. language
      connection.language = 'ja'; // prefer Japanese
      
    116. token
      var randomString = rtcMultiConnection.token();
      rtcMultiConnection.userid = rtcMultiConnection.token();
      
    117. UA
      connection.UA.isChrome
      connection.UA.isFirefox
      connection.UA.isIE
      connection.UA.isOpera
      connection.UA.isSafari
      connection.UA.isMobileDevice
      connection.UA.version
      
    118. fakeDataChannels
      // audio+video and fake data connection
      connection.fakeDataChannels = true;
      connection.session = { audio: true, video: true };
      
      // only fake data connection; no audio; no video; no WebRTC data channel!
      connection.fakeDataChannels = true;
      connection.session = { };
      
    119. onMediaFile
      // receive WebM files
      connection.onMediaFile = function(e) {
          // e.mediaElement (it is video-element)
          // e.userid
          // e.extra
          
          yourExistingVideoElement.src = e.mediaElement.src;
          
          // or
          document.body.appendChild(e.mediaElement);
      };
      
    120. shareMediaFile
      // select WebM file to share as pre-recorded media!
      document.querySelector('input[type=file]').onchange = function() {
          connection.shareMediaFile( this.files[0] );
      };
      
    121. autoReDialOnFailure
      // by default, it is "false"
      // it is false because workaround that is used to capture connections' failures
      // affects renegotiation scenarios!
      connection.autoReDialOnFailure = true;
      
    122. isAcceptNewSession
      // Using "isAcceptNewSession", you can allow single user to join multiple rooms from the same channel:
      connection.onstream = function(event) {
          if(event.type == 'remote') {
              // set "isAcceptNewSession=true" so this user can get and join new session i.e. room
              // it means that "onNewSession" will be fired for this user as soon as other room is available!
              connection.isAcceptNewSession = true;
          }
      };
      
    123. askToShareParticipants
      // Useful in multi-broadcasters and many viewers scenarios!
      connection.onstream = function (e) {
          if (e.type == 'remote' && role == 'Anonymous Viewer') {
              // because "viewer" joined room as "oneway:true"
              // initiator will NEVER share participants
              // to manually ask for participants;
              // call "askToShareParticipants" method.
              connection.askToShareParticipants();
          }
      
          // if you're moderator
          // if stream-type is 'remote'
          // if target user is broadcaster!
          if (connection.isInitiator && e.type == 'remote' && !e.session.oneway) {
              // call "shareParticipants" to manually share participants with all connected users!
              connection.shareParticipants({
                  dontShareWith: e.userid
              });
          }
      };
      
    124. dontOverrideSession
      // dont-override-session allows you force RTCMultiConnection
      // to not override default session of participants;
      // by default, session is always overridden and set to the session coming from initiator!
      connection.dontOverrideSession = true;
      
    125. redial
      // to recreate offers/answers
      connection.peers['target-userid'].redial();
      
    126. leaveOnPageUnload boolean
      // if you want to prevent/override/bypass default behaviour
      connection.leaveOnPageUnload = false;
      
      // display a notification box
      window.addEventListener('beforeunload', function () {
          return 'Are you want to leave?';
      }, false);
      
      // leave here
      window.addEventListener('unload', function () {
          connection.leave();
      }, false);
      
    127. DetectRTC object
      if(connection.DetectRTC.hasMicrophone) {
          // seems current system has at least one audio input device
      }
      
      if(connection.DetectRTC.hasSpeakers) {
          // seems current system has at least one audio output device
      }
      
      if(connection.DetectRTC.hasWebcam) {
          // seems current system has at least one video input device
      }
      
      // to iterate over all available media devices
      connection.getDevices(function() {
          connection.DetectRTC.MediaDevices.forEach(function(device) {
              // device.deviceId
              // device.kind == 'audioinput' || 'audiooutput' || 'audio'
              
              connection.selectDevices(device.deviceId);
          });
      });
      
      // set type of capturing API
      connection.DetectRTC.screen.chromeMediaSource = 'desktop'; // screen || desktop
      
      connection.DetectRTC.screen.isChromeExtensionAvailable(function(available){
          // available == true or false
      });
      
      var extensionid = 'ajhifddimkapgcifgcodmmfdlknahffk';
      connection.DetectRTC.screen.getChromeExtensionStatus(extensionid, function(status) {
          if(status == 'installed-enabled') {
              // chrome extension is installed & enabled.
          }
          
          if(status == 'installed-disabled') {
              // chrome extension is installed but disabled.
          }
          
          if(status == 'not-installed') {
              // chrome extension is not installed
          }
          
          if(status == 'not-chrome') {
              // using non-chrome browser
          }
      });
      
      // if following function is defined, it will be called if screen capturing extension seems available
      connection.DetectRTC.screen.onScreenCapturingExtensionAvailable = function() {
          // hide inline-install button
      };
      
    128. onstatechange event
      connection.onstatechange = function (state) {
          // state.userid == 'target-userid' || 'browser'
          // state.extra  == 'target-user-extra-data' || {}
          // state.name  == 'short name'
          // state.reason == 'longer description'
          if(state.name == 'stop-request-denied') {
              alert(state.reason);
          }
      };
      
    129. onSessionClosed event
      connection.onSessionClosed = function(e) {
          // entire session is closed
          
          // e.userid
          // e.extra
          // e.isSessionClosed
          
          // e.session == connection.sessionDescription
          // e.session.sessionid
          // e.session.userid --- initiator id
          // e.session.session -- {audio:true, video:true}
      };
      
    130. sharePartOfScreen method
      connection.sharePartOfScreen({
          element: '#elementToShare',
          interval: 500
      });
      
    131. stopSharingPartOfScreen method
      // stop part of screen between all users
      connection.stopPartOfScreenSharing();
      
      // or, stop part of screen between two users
      connection.peers['target-userid'].stopPartOfScreenSharing = true;
      
    132. pausePartOfScreenSharing method
      // pause part of screen between all users
      connection.pausePartOfScreenSharing();
      
      // or, pause part of screen between two users
      connection.peers['target-userid'].pausePartOfScreenSharing = true;
      
    133. resumePartOfScreenSharing method
      // resume part of screen between all users
      connection.resumePartOfScreenSharing();
      
      // or, resume part of screen between two users
      connection.peers['target-userid'].pausePartOfScreenSharing = false;
      connection.partOfScreen.sharing = true; // necessary
      
    134. onpartofscreen
      var image = document.getElementById('preview-image');
      connection.onpartofscreen = function (event) {
          image.src = event.screenshot;
          
          // event.userid --- sender id
          // event.extra  --- extra data from sender
      };
      
    135. setDefaultEventsForMediaElement method
      // You can override setDefaultEventsForMediaElement to prevent 
      // default mute/unmute handlers on media elements:
      connection.setDefaultEventsForMediaElement = false;
      
    136. processSdp method
      connection.processSdp = function(sdp) {
          sdp = remove_vp8_codecs(sdp);
          sdp = prefer_opus (sdp);
          sdp = use_maxaveragebitrate(sdp);
          return sdp;
      };
      
    137. onstreamid event
      // on getting remote stream's clue
      connection.onstreamid = function (e) {
          var mediaElement = document.createElement(e.isAudio ? 'audio' : 'video');
          mediaElement.controls = true;
          mediaElement.poster = connection.resources.muted;
          mediaElement.id = e.streamid;
          connection.body.appendChild(mediaElement);
      };
      
    138. privileges
      // set it "false" if you want to restrict user to stop/mute remote stream
      // if user will try to programmatically invoke "stop" or "mute" method,
      // you'll be informed in the "onstatechange" event.
      connection.privileges = {
          canStopRemoteStream: true, // user can stop remote streams
          canMuteRemoteStream: true  // user can mute remote streams
      };
      
      connection.onstatechange = function(state) {
          if(state.name == 'stop-request-denied') {
              alert(state.reason);
          }
          
          if(state.name == 'mute-request-denied') {
              alert(state.reason);
          }
      };
      
    139. mute
      // mute all remote audio-only streams.
      connection.streams.mute({
          isAudio: true,
          remote: true
      });
      
      // unmute all local screen streams.
      connection.streams.unmute({
          isScreen: true,
          local: true
      });
      
    140. preferJSON
      // Remember: it doesn't applies to file sharing.
      // it applies to all other kinds of data.
      connection.preferJSON = false;
      
      // send array buffer
      connection.send( new ArrayBuffer(10) );
      
      // get array buffer
      connection.onmessage =  function(event) {
          var buffer = event.data;
      };
      
    141. getExternalIceServers
      // if you want to use XirSys-based STUN/TURN servers
      connection.getExternalIceServers = true;
      
    142. waitUntilRemoteStreamStartsFlowing
      // It allows you override default 
      // Wait-Until-Remote-Stream-starts-flowing behaviour.
      connection.waitUntilRemoteStreamStartsFlowing = false;
      
    143. switchStream
      // remove all old streams and add screen in oneway.
      connection.switchStream({
          screen: true,
          oneway: true
      });
      
    144. disconnect
      // it means that:
      // 1) close all sockets
      // 2) close all peers
      // 3) clear all data
      // 4) refresh everything
      // Note: local streams will be kept in "localStreams" object if "keepStreamsOpened" boolean is used.
      connection.disconnect();
      
      // it fires: 
      connection.ondisconnected = function(event) {
          if(event.isSocketsDisconnected == true) { }
      };
      
    145. stop
      // stop any single stream: audio or video or screen
      connection.streams.stop('screen');
      
      // stop multiple streams
      connection.streams.stop({
          remote: true,
          video: true,
          screen: true
      });
      
    146. localStreams
      // All local streams are always kept in this object even 
      // if session is closed. Look at above section 
      // i.e. keepStreamsOpened.
      var stream = connection.localStreams['streamid'];
      
      // or
      connection.onSessionClosed = function() {
          var stream = connection.localStreams['streamid'];
      };
      
      // or
      for(var streamid in connection.localStreams) {
          var stream = connection.localStreams[streamid];
      }
      
    147. keepStreamsOpened
      // if you want to keep local streams to be opened
      // even if entire session is closed
      connection.keepStreamsOpened = true;
      
    148. "log" and "onlog"
      // if you want to disable logs
      connection.log = false;
      
      connection.onlog = function(log) {
          var div = document.createElement('div');
          div.innerHTML = JSON.stringify(log, null, '
      '); document.documentElement.appendChild(div); };
    149. onconnected
      connection.onconnected = function (event) {
          log('Peer connection has been established between you and', event.userid);
          
          // event.peer.addStream || event.peer.removeStream || event.peer.changeBandwidth
          // event.peer == connection.peers[event.userid]
          
          event.peer.getConnectionStats(function (result) {
              // many useful statistics here
          });
      };
      
    150. ondisconnected
      connection.ondisconnected = function(event) {
          // connection has been disconnected between you
          // and event.userid
      };
      
    151. getConnectionStats
      connection.peers['target-userid'].peer.getConnectionStats(function (result) {
          // many useful statistics here
      });
      
    152. onfailed
      connection.onfailed = function (event) {
          event.peer.renegotiate();
          // or event.peer.redial();
          // event.targetuser.browser == 'firefox' || 'chrome'
      };
      
    153. iceProtocols
      connection.iceProtocols = {
          tcp: true, // prefer using TCP-candidates
          udp: true  // prefer using UDP-candidates
      };
      
    154. preventSSLAutoAllowed
      connection.preventSSLAutoAllowed = true;
      
    155. resources
      connection.resources = {
          RecordRTC: 'https://www.webrtc-experiment.com/RecordRTC.js',
          PreRecordedMediaStreamer: 'https://www.rtcmulticonnection.org/PreRecordedMediaStreamer.js',
          customGetUserMediaBar: 'https://www.webrtc-experiment.com/navigator.customGetUserMediaBar.js',
          html2canvas: 'https://www.webrtc-experiment.com/screenshot.js',
          hark: 'https://www.rtcmulticonnection.org/hark.js',
          firebase: 'https://www.rtcmulticonnection.org/firebase.js',
          firebaseio: 'https://chat.firebaseIO.com/',
          muted: 'https://www.webrtc-experiment.com/images/muted.png'
      };
      
    156. enumerateDevices
      connection.enumerateDevices(function(devices) {
          devices.forEach(function(device) {
              // device.deviceId
              // device.kind == 'audioinput' || 'audiooutput' || 'audio'
              
              connection.selectDevices(device.deviceId);
          });
      });
      
    157. captureUserMediaOnDemand
      // it is "disabled" by default
      // captureUserMediaOnDemand means that "getUserMedia" API for initiator will 
      // be invoked only when required.
      // i.e. when first participant is detected.
      
      // you can enable it by setting it to "true"
      connection.open({
          captureUserMediaOnDemand: true
      });
      
    158. onMediaCaptured
      connection.open({
          onMediaCaptured: function() {
              // initiator enable camera/microphone
              // you can share "sessionDescription" with other users
              // and they can quickly join initiator!
          }
      });
      
    159. onScreenCapturingExtensionAvailable
      connection.onScreenCapturingExtensionAvailable = function() {
          btnInlineInstallButton.disabled = true;
      };
      
    160. onMediaError
      connection.onMediaError = function(error) {
          if(error.name == 'PermissionDeniedError') {
              alert(error.message);
          }
      };
      
    161. trickleIce
      // to ask RTCMultiConnection to wait until all ICE candidates
      // are gathered; and all ice are merged in the SDP
      // you JUST need to share that SDP "only"!
      connection.trickleIce = false;
      
    162. dontOverrideSession
      // dont-override-session allows you force RTCMultiConnection
      // to not override default session of participants;
      // by default, session is always overridden and set to the session coming from initiator!
      connection.dontOverrideSession = true;
      
    163. autoReDialOnFailure
      // by default, it is "false" for v1.9 or earlier
      // it is true for v2.0 or newer
      // it is false because workaround that is used to capture connections' failures
      // affects renegotiation scenarios!
      connection.autoReDialOnFailure = true;
      
    164. rtcConfiguration
      connection.rtcConfiguration = {
          iceServers: [],
          iceTransports: 'all'
      };
      
    165. attachExternalStream
      navigator.webkitGetUserMedia({
          video: {
              chromeMediaSource: 'screen'
          }
      }, function(stream) {
          connection.attachExternalStream(stream, true);
      }, function(error) {
          alert(JSON.stringify(error));
      };
      


Latest Issues

Want to ask a Question?

You can include your email for private conversation!

Latest Updates