How to use the webrtc-adapter.browserDetails function in webrtc-adapter

To help you get started, we’ve selected a few webrtc-adapter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webcom-components / reach / src / definitions / Browser.js View on Github external
import adapter from 'webrtc-adapter';
import Webcom from 'webcom/webcom';

/**
 * The current browser's infos
 * @typedef {Object} Browser
 * @property {string} name - current browser's name
 * @property {number} [version] - current browser's version
 * @property {number} [minVersion] - current browser's minimum supported version
 * @property {boolean} compatible - is current browser supported ?
 */
const browser = Object.assign({
  compatible: !/\s/.test(adapter.browserDetails.browser)
    && (!adapter.browserDetails.minVersion
      || adapter.browserDetails.version >= adapter.browserDetails.minVersion)
}, adapter.browserDetails);

const version = `Reach v${SDK_VERSION} | Schema ${SCHEMA_VERSION} | Webcom v${Webcom.SDK_VERSION}`; // eslint-disable-line no-undef
let message = '';
if (browser.version === null) {
  message = 'Unsupported browser: browser must support WebRTC Peer-to-peer connections to use Reach';
} else if (browser.minVersion && browser.minVersion > browser.version) {
  message = `Unsupported browser: browser is outdated, update to latest version (${browser.minVersion}+)`;
} else if (!adapter.browserShim) {
  message = 'No shim for your browser. There might a problem with your package.';
}

// Log browser status & SDKs versions on load
let args = [`${version} ${message}`];
if (/^(chrome|firefox)$/.test(browser.browser)) {
github flashphoner / flashphoner_client / src / webrtc-media-provider.js View on Github external
connection.setRemoteDescription(rtcSdp).then(function () {
                    //use in edge for ice
                    if (adapter.browserDetails.browser == "edge") {
                        // var sdpArray = sdp.split("\n");
                        // var i;
                        // for (i = 0; i < sdpArray.length; i++) {
                        //     if (sdpArray[i].indexOf("m=video") == 0) {
                        //         break;
                        //     }
                        //     if (sdpArray[i].indexOf("a=candidate:1 1") == 0 || sdpArray[i].indexOf("a=candidate:2 1") == 0) {
                        //         var rtcIceCandidate = new RTCIceCandidate({
                        //             candidate: sdpArray[i],
                        //             sdpMid: "audio",
                        //             sdpMLineIndex: 0
                        //         });
                        //         connection.addIceCandidate(rtcIceCandidate);
                        //     }
                        // }
                        // var video = false;
github sjkummer / janus-gateway-js / src / webrtc / media-devices-shim.js View on Github external
MediaDevicesShim.getSharedScreen = function(constraints) {
  if (window.location.protocol !== 'https:') {
    return Promise.reject(new Error('Screen sharing only works on HTTPS, try the https:// version of this page'));
  }

  if ('chrome' == webrtc.browserDetails.browser) {
    return this._getSharedScreenChrome(constraints);
  } else if ('firefox' == webrtc.browserDetails.browser) {
    return this._getSharedScreenFirefox(constraints);
  }
};
github otalk / getScreenMedia / getscreenmedia.js View on Github external
module.exports = function (constraints, cb) {
    var hasConstraints = arguments.length === 2;
    var callback = hasConstraints ? cb : constraints;
    var error;

    if ('getDisplayMedia' in window.navigator.mediaDevices) { // prefer spec getDisplayMedia
        window.navigator.mediaDevices.getDisplayMedia(constraints)
        .then(function (stream) {
            callback(null, stream);
        }).catch(function (err) {
            callback(err);
        });
    } else if (adapter.browserDetails.browser === 'chrome') {
        if (sessionStorage.getScreenMediaJSExtensionId) {
            // check that the extension is installed by looking for a
            // sessionStorage variable that contains the extension id
            // this has to be set after installation unless the content
            // script does that
            chrome.runtime.sendMessage(sessionStorage.getScreenMediaJSExtensionId,
                {type:'getScreen', id: 1}, null,
                function (data) {
                    if (!data || data.sourceId === '') { // user canceled
                        var error = new Error('NavigatorUserMediaError');
                        error.name = 'NotAllowedError';
                        callback(error);
                    } else {
                        constraints = (hasConstraints && constraints) || {audio: false, video: {
                            mandatory: {
                                chromeMediaSource: 'desktop',
github sjkummer / janus-gateway-js / src / webrtc / media-devices-shim.js View on Github external
MediaDevicesShim._getSharedScreenChrome = function(constraints) {
  var chromever = webrtc.browserDetails.version;
  var maxver = 33;
  if (window.navigator.userAgent.match('Linux')) {
    maxver = 35;
  }	// "known" crash in chrome 34 and 35 on linux
  if (chromever >= 26 && chromever <= maxver) {
    // Chrome 26->33 requires some awkward chrome://flags manipulation
    constraints = Helpers.extend({}, constraints, {
      video: {
        mandatory: {
          googLeakyBucket: true,
          maxWidth: window.screen.width,
          maxHeight: window.screen.height,
          maxFrameRate: 3,
          chromeMediaSource: 'screen'
        }
      }
github otalk / getScreenMedia / getscreenmedia.js View on Github external
}
                    }};
                    constraints.video.mandatory.chromeMediaSourceId = sourceId;
                    window.navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
                        callback(null, stream);
                    }).catch(function (err) {
                        callback(err);
                    });
                }
            });
        } else {
            error = new Error('Screensharing is not supported');
            error.name = 'NotSupportedError';
            callback(error);
        }
    } else if (adapter.browserDetails.browser === 'firefox' && adapter.browserDetails.version >= 33) {
        constraints = (hasConstraints && constraints) || {
            video: {
                mediaSource: 'window'
            }
        };
        window.navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
            callback(null, stream);
        }).catch(function (err) {
            callback(err);
        });
    } else {
        error = new Error('Screensharing is not supported');
        error.name = 'NotSupportedError';
        callback(error);
    }
};
github ksocha / twilio-screensharing / client / src / components / App / AppContainer.js View on Github external
componentDidMount() {
    if (adapter.browserDetails.browser === "firefox") {
      adapter.browserShim.shimGetDisplayMedia(window, "screen");
    }
  }
github mattermost / mattermost-webapp / client / webrtc_session.jsx View on Github external
const callbacks = cbs || {};
        callbacks.success = (typeof cbs.success == 'function') ? cbs.success : this.client.noop;
        callbacks.error = (typeof cbs.error == 'function') ? cbs.error : this.client.noop;

        const pluginHandle = this.pluginHandles[handleId];
        if (!pluginHandle || !pluginHandle.webrtcStuff) {
            this.client.warn('Invalid handle');
            callbacks.error('Invalid handle');
            return;
        }

        const config = pluginHandle.webrtcStuff;
        this.client.log('Creating answer (iceDone=' + config.iceDone + ')');

        let mediaConstraints = null;
        const browser = adapter.browserDetails.browser;
        if (browser === 'firefox' || browser === 'edge') {
            mediaConstraints = {
                offerToReceiveAudio: this.isAudioRecvEnabled(media),
                offerToReceiveVideo: this.isVideoRecvEnabled(media)
            };
        } else {
            mediaConstraints = {
                mandatory: {
                    OfferToReceiveAudio: this.isAudioRecvEnabled(media),
                    OfferToReceiveVideo: this.isVideoRecvEnabled(media)
                }
            };
        }
        this.client.debug(mediaConstraints);
        config.pc.createAnswer(
            (answer) => {
github flashphoner / flashphoner_client / src / temasys-media-provider.js View on Github external
getScreenDeviceId(constraints).then(function (screenSharingConstraints) {
                //copy constraints
                for (var prop in screenSharingConstraints) {
                    if (screenSharingConstraints.hasOwnProperty(prop)) {
                        constraints.video[prop] = screenSharingConstraints[prop];
                    }
                }
                if (webrtcAdapter.browserDetails.browser == "chrome") {
                    delete constraints.video.frameRate;
                    delete constraints.video.height;
                    delete constraints.video.width;
                }
                getAccess(constraints);
            }, reject);
        } else {
github otalk / attachMediaStream / attachmediastream.js View on Github external
if (opts.disableContextMenu) {
        element.oncontextmenu = function (e) {
            e.preventDefault();
        };
    }

    if (opts.autoplay) element.autoplay = 'autoplay';
    element.muted = !!opts.muted;
    if (!opts.audio) {
        ['', 'moz', 'webkit', 'o', 'ms'].forEach(function (prefix) {
            var styleName = prefix ? prefix + 'Transform' : 'transform';
            element.style[styleName] = opts.mirror ? 'scaleX(-1)' : 'scaleX(1)';
        });
    }

    if (adapter.browserDetails.browser === 'safari') {
        element.setAttribute('playsinline', true);
    }

    element.srcObject = stream;
    return element;
};

webrtc-adapter

A shim to insulate apps from WebRTC spec changes and browser prefix differences

BSD-3-Clause
Latest version published 9 months ago

Package Health Score

75 / 100
Full package analysis

Similar packages