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aAAa,UAAU,YAAc,SAAU,GAC3C,KAAK,OAAO,iBAAiB,EACjC,EAEA,aAAa,UAAU,eAAiB,WACpC,OAAO,KAAK,OAAO,cAAgB,KAAK,OAAO,aAAa,EAChE,EAEA,aAAa,UAAU,gBAAkB,WACrC,KAAK,WAAW,KAAK,iBACrB,IAAI,EAAU,SAAS,eAAe,eAClC,EAAY,KAAK,0BAEjB,KAAK,OAAO,kBAAoB,GAAa,GAC7C,EAAU,YAAY,GAKtB,GACA,KAAK,KAAK,eAAgB,GAE1B,KAAK,kBACL,KAAK,OAAO,kBAEhB,KAAK,OAAO,MAAM,SAAQ,SAAU,GAC5B,EAAK,aACL,EAAK,KAEb,GACJ,EAEA,aAAa,UAAU,cAAgB,WACnC,IAAI,EAAO,KACP,KAAK,eACA,KAAK,OAAO,MAAM,OAAU,KAAK,OAAO,MAAM,MAExC,KAAK,OAAO,aAAa,OAAS,GACzC,EAAK,KAAK,cAAe,EAAK,WAAW,gBAFzC,EAAK,KAAK,cAAe,EAAK,WAAW,gBAKrD,EAEA,aAAa,UAAU,WAAa,SAAU,EAAM,GAChD,KAAK,SAAW,EACS,IAArB,UAAU,OACV,KAAK,WAAW,KAAK,SAAU,EAAM,GAErC,KAAK,WAAW,KAAK,SAAU,EAEvC,EAEA,aAAa,UAAU,SAAW,WAC9B,IAAK,cAAc,YACf,OAAO,KAAK,KAAK,QAAS,IAAI,MAAM,2BAG5C,EAEA,OAAO,QAAU","file":"/npm/simplewebrtc@3.0.2/src/simplewebrtc.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.37.0.\n * Original file: /npm/simplewebrtc@3.0.2/src/simplewebrtc.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","var WebRTC = require('./webrtc');\nvar WildEmitter = require('wildemitter');\nvar webrtcSupport = require('webrtcsupport');\nvar attachMediaStream = require('attachmediastream');\nvar mockconsole = require('mockconsole');\nvar SocketIoConnection = require('./socketioconnection');\n\nfunction SimpleWebRTC(opts) {\n    var self = this;\n    var options = opts || {};\n    var config = this.config = {\n            url: 'https://sandbox.simplewebrtc.com:443/',\n            socketio: {/* 'force new connection':true*/},\n            connection: null,\n            debug: false,\n            localVideoEl: '',\n            remoteVideosEl: '',\n            enableDataChannels: true,\n            autoRequestMedia: false,\n            autoRemoveVideos: true,\n            adjustPeerVolume: false,\n            peerVolumeWhenSpeaking: 0.25,\n            media: {\n                video: true,\n                audio: true\n            },\n            receiveMedia: {\n                offerToReceiveAudio: 1,\n                offerToReceiveVideo: 1\n            },\n            localVideo: {\n                autoplay: true,\n                mirror: true,\n                muted: true\n            }\n        };\n    var item, connection;\n\n    // We also allow a 'logger' option. It can be any object that implements\n    // log, warn, and error methods.\n    // We log nothing by default, following \"the rule of silence\":\n    // http://www.linfo.org/rule_of_silence.html\n    this.logger = function () {\n        // we assume that if you're in debug mode and you didn't\n        // pass in a logger, you actually want to log as much as\n        // possible.\n        if (opts.debug) {\n            return opts.logger || console;\n        } else {\n        // or we'll use your logger which should have its own logic\n        // for output. Or we'll return the no-op.\n            return opts.logger || mockconsole;\n        }\n    }();\n\n    // set our config from options\n    for (item in options) {\n        if (options.hasOwnProperty(item)) {\n            this.config[item] = options[item];\n        }\n    }\n\n    // attach detected support for convenience\n    this.capabilities = webrtcSupport;\n\n    // call WildEmitter constructor\n    WildEmitter.call(this);\n\n    // create default SocketIoConnection if it's not passed in\n    if (this.config.connection === null) {\n        connection = this.connection = new SocketIoConnection(this.config);\n    } else {\n        connection = this.connection = this.config.connection;\n    }\n\n    connection.on('connect', function () {\n        self.emit('connectionReady', connection.getSessionid());\n        self.sessionReady = true;\n        self.testReadiness();\n    });\n\n    connection.on('message', function (message) {\n        var peers = self.webrtc.getPeers(message.from, message.roomType);\n        var peer;\n\n        if (message.type === 'offer') {\n            if (peers.length) {\n                peers.forEach(function (p) {\n                    if (p.sid == message.sid) peer = p;\n                });\n                //if (!peer) peer = peers[0]; // fallback for old protocol versions\n            }\n            if (!peer) {\n                peer = self.webrtc.createPeer({\n                    id: message.from,\n                    sid: message.sid,\n                    type: message.roomType,\n                    enableDataChannels: self.config.enableDataChannels && message.roomType !== 'screen',\n                    sharemyscreen: message.roomType === 'screen' && !message.broadcaster,\n                    broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null\n                });\n                self.emit('createdPeer', peer);\n            }\n            peer.handleMessage(message);\n        } else if (peers.length) {\n            peers.forEach(function (peer) {\n                if (message.sid) {\n                    if (peer.sid === message.sid) {\n                        peer.handleMessage(message);\n                    }\n                } else {\n                    peer.handleMessage(message);\n                }\n            });\n        }\n    });\n\n    connection.on('remove', function (room) {\n        if (room.id !== self.connection.getSessionid()) {\n            self.webrtc.removePeers(room.id, room.type);\n        }\n    });\n\n    // instantiate our main WebRTC helper\n    // using same logger from logic here\n    opts.logger = this.logger;\n    opts.debug = false;\n    this.webrtc = new WebRTC(opts);\n\n    // attach a few methods from underlying lib to simple.\n    ['mute', 'unmute', 'pauseVideo', 'resumeVideo', 'pause', 'resume', 'sendToAll', 'sendDirectlyToAll', 'getPeers'].forEach(function (method) {\n        self[method] = self.webrtc[method].bind(self.webrtc);\n    });\n\n    // proxy events from WebRTC\n    this.webrtc.on('*', function () {\n        self.emit.apply(self, arguments);\n    });\n\n    // log all events in debug mode\n    if (config.debug) {\n        this.on('*', this.logger.log.bind(this.logger, 'SimpleWebRTC event:'));\n    }\n\n    // check for readiness\n    this.webrtc.on('localStream', function () {\n        self.testReadiness();\n    });\n\n    this.webrtc.on('message', function (payload) {\n        self.connection.emit('message', payload);\n    });\n\n    this.webrtc.on('peerStreamAdded', this.handlePeerStreamAdded.bind(this));\n    this.webrtc.on('peerStreamRemoved', this.handlePeerStreamRemoved.bind(this));\n\n    // echo cancellation attempts\n    if (this.config.adjustPeerVolume) {\n        this.webrtc.on('speaking', this.setVolumeForAll.bind(this, this.config.peerVolumeWhenSpeaking));\n        this.webrtc.on('stoppedSpeaking', this.setVolumeForAll.bind(this, 1));\n    }\n\n    connection.on('stunservers', function (args) {\n        // resets/overrides the config\n        self.webrtc.config.peerConnectionConfig.iceServers = args;\n        self.emit('stunservers', args);\n    });\n    connection.on('turnservers', function (args) {\n        // appends to the config\n        self.webrtc.config.peerConnectionConfig.iceServers = self.webrtc.config.peerConnectionConfig.iceServers.concat(args);\n        self.emit('turnservers', args);\n    });\n\n    this.webrtc.on('iceFailed', function (peer) {\n        // local ice failure\n    });\n    this.webrtc.on('connectivityError', function (peer) {\n        // remote ice failure\n    });\n\n\n    // sending mute/unmute to all peers\n    this.webrtc.on('audioOn', function () {\n        self.webrtc.sendToAll('unmute', {name: 'audio'});\n    });\n    this.webrtc.on('audioOff', function () {\n        self.webrtc.sendToAll('mute', {name: 'audio'});\n    });\n    this.webrtc.on('videoOn', function () {\n        self.webrtc.sendToAll('unmute', {name: 'video'});\n    });\n    this.webrtc.on('videoOff', function () {\n        self.webrtc.sendToAll('mute', {name: 'video'});\n    });\n\n    // screensharing events\n    this.webrtc.on('localScreen', function (stream) {\n        var item,\n            el = document.createElement('video'),\n            container = self.getRemoteVideoContainer();\n\n        el.oncontextmenu = function () { return false; };\n        el.id = 'localScreen';\n        attachMediaStream(stream, el);\n        if (container) {\n            container.appendChild(el);\n        }\n\n        self.emit('localScreenAdded', el);\n        self.connection.emit('shareScreen');\n\n        self.webrtc.peers.forEach(function (existingPeer) {\n            var peer;\n            if (existingPeer.type === 'video') {\n                peer = self.webrtc.createPeer({\n                    id: existingPeer.id,\n                    type: 'screen',\n                    sharemyscreen: true,\n                    enableDataChannels: false,\n                    receiveMedia: {\n                        offerToReceiveAudio: 0,\n                        offerToReceiveVideo: 0\n                    },\n                    broadcaster: self.connection.getSessionid(),\n                });\n                self.emit('createdPeer', peer);\n                peer.start();\n            }\n        });\n    });\n    this.webrtc.on('localScreenStopped', function (stream) {\n        if (self.getLocalScreen()) {\n            self.stopScreenShare();\n        }\n        /*\n        self.connection.emit('unshareScreen');\n        self.webrtc.peers.forEach(function (peer) {\n            if (peer.sharemyscreen) {\n                peer.end();\n            }\n        });\n        */\n    });\n\n    this.webrtc.on('channelMessage', function (peer, label, data) {\n        if (data.type == 'volume') {\n            self.emit('remoteVolumeChange', peer, data.volume);\n        }\n    });\n\n    if (this.config.autoRequestMedia) this.startLocalVideo();\n}\n\n\nSimpleWebRTC.prototype = Object.create(WildEmitter.prototype, {\n    constructor: {\n        value: SimpleWebRTC\n    }\n});\n\nSimpleWebRTC.prototype.leaveRoom = function () {\n    if (this.roomName) {\n        this.connection.emit('leave');\n        while (this.webrtc.peers.length) {\n            this.webrtc.peers[0].end();\n        }\n        if (this.getLocalScreen()) {\n            this.stopScreenShare();\n        }\n        this.emit('leftRoom', this.roomName);\n        this.roomName = undefined;\n    }\n};\n\nSimpleWebRTC.prototype.disconnect = function () {\n    this.connection.disconnect();\n    delete this.connection;\n};\n\nSimpleWebRTC.prototype.handlePeerStreamAdded = function (peer) {\n    var self = this;\n    var container = this.getRemoteVideoContainer();\n    var video = attachMediaStream(peer.stream);\n\n    // store video element as part of peer for easy removal\n    peer.videoEl = video;\n    video.id = this.getDomId(peer);\n\n    if (container) container.appendChild(video);\n\n    this.emit('videoAdded', video, peer);\n\n    // send our mute status to new peer if we're muted\n    // currently called with a small delay because it arrives before\n    // the video element is created otherwise (which happens after\n    // the async setRemoteDescription-createAnswer)\n    window.setTimeout(function () {\n        if (!self.webrtc.isAudioEnabled()) {\n            peer.send('mute', {name: 'audio'});\n        }\n        if (!self.webrtc.isVideoEnabled()) {\n            peer.send('mute', {name: 'video'});\n        }\n    }, 250);\n};\n\nSimpleWebRTC.prototype.handlePeerStreamRemoved = function (peer) {\n    var container = this.getRemoteVideoContainer();\n    var videoEl = peer.videoEl;\n    if (this.config.autoRemoveVideos && container && videoEl) {\n        container.removeChild(videoEl);\n    }\n    if (videoEl) this.emit('videoRemoved', videoEl, peer);\n};\n\nSimpleWebRTC.prototype.getDomId = function (peer) {\n    return [peer.id, peer.type, peer.broadcaster ? 'broadcasting' : 'incoming'].join('_');\n};\n\n// set volume on video tag for all peers takse a value between 0 and 1\nSimpleWebRTC.prototype.setVolumeForAll = function (volume) {\n    this.webrtc.peers.forEach(function (peer) {\n        if (peer.videoEl) peer.videoEl.volume = volume;\n    });\n};\n\nSimpleWebRTC.prototype.joinRoom = function (name, cb) {\n    var self = this;\n    this.roomName = name;\n    this.connection.emit('join', name, function (err, roomDescription) {\n        console.log('join CB', err, roomDescription);\n        if (err) {\n            self.emit('error', err);\n        } else {\n            var id,\n                client,\n                type,\n                peer;\n            for (id in roomDescription.clients) {\n                client = roomDescription.clients[id];\n                for (type in client) {\n                    if (client[type]) {\n                        peer = self.webrtc.createPeer({\n                            id: id,\n                            type: type,\n                            enableDataChannels: self.config.enableDataChannels && type !== 'screen',\n                            receiveMedia: {\n                                offerToReceiveAudio: type !== 'screen' && self.config.receiveMedia.offerToReceiveAudio ? 1 : 0,\n                                offerToReceiveVideo: self.config.receiveMedia.offerToReceiveVideo\n                            }\n                        });\n                        self.emit('createdPeer', peer);\n                        peer.start();\n                    }\n                }\n            }\n        }\n\n        if (cb) cb(err, roomDescription);\n        self.emit('joinedRoom', name);\n    });\n};\n\nSimpleWebRTC.prototype.getEl = function (idOrEl) {\n    if (typeof idOrEl === 'string') {\n        return document.getElementById(idOrEl);\n    } else {\n        return idOrEl;\n    }\n};\n\nSimpleWebRTC.prototype.startLocalVideo = function () {\n    var self = this;\n    this.webrtc.start(this.config.media, function (err, stream) {\n        if (err) {\n            self.emit('localMediaError', err);\n        } else {\n            attachMediaStream(stream, self.getLocalVideoContainer(), self.config.localVideo);\n        }\n    });\n};\n\nSimpleWebRTC.prototype.stopLocalVideo = function () {\n    this.webrtc.stop();\n};\n\n// this accepts either element ID or element\n// and either the video tag itself or a container\n// that will be used to put the video tag into.\nSimpleWebRTC.prototype.getLocalVideoContainer = function () {\n    var el = this.getEl(this.config.localVideoEl);\n    if (el && el.tagName === 'VIDEO') {\n        el.oncontextmenu = function () { return false; };\n        return el;\n    } else if (el) {\n        var video = document.createElement('video');\n        video.oncontextmenu = function () { return false; };\n        el.appendChild(video);\n        return video;\n    } else {\n        return;\n    }\n};\n\nSimpleWebRTC.prototype.getRemoteVideoContainer = function () {\n    return this.getEl(this.config.remoteVideosEl);\n};\n\nSimpleWebRTC.prototype.shareScreen = function (cb) {\n    this.webrtc.startScreenShare(cb);\n};\n\nSimpleWebRTC.prototype.getLocalScreen = function () {\n    return this.webrtc.localScreens && this.webrtc.localScreens[0];\n};\n\nSimpleWebRTC.prototype.stopScreenShare = function () {\n    this.connection.emit('unshareScreen');\n    var videoEl = document.getElementById('localScreen');\n    var container = this.getRemoteVideoContainer();\n\n    if (this.config.autoRemoveVideos && container && videoEl) {\n        container.removeChild(videoEl);\n    }\n\n    // a hack to emit the event the removes the video\n    // element that we want\n    if (videoEl) {\n        this.emit('videoRemoved', videoEl);\n    }\n    if (this.getLocalScreen()) {\n        this.webrtc.stopScreenShare();\n    }\n    this.webrtc.peers.forEach(function (peer) {\n        if (peer.broadcaster) {\n            peer.end();\n        }\n    });\n};\n\nSimpleWebRTC.prototype.testReadiness = function () {\n    var self = this;\n    if (this.sessionReady) {\n        if (!this.config.media.video && !this.config.media.audio) {\n            self.emit('readyToCall', self.connection.getSessionid());\n        } else if (this.webrtc.localStreams.length > 0) {\n            self.emit('readyToCall', self.connection.getSessionid());\n        }\n    }\n};\n\nSimpleWebRTC.prototype.createRoom = function (name, cb) {\n    this.roomName = name;\n    if (arguments.length === 2) {\n        this.connection.emit('create', name, cb);\n    } else {\n        this.connection.emit('create', name);\n    }\n};\n\nSimpleWebRTC.prototype.sendFile = function () {\n    if (!webrtcSupport.dataChannel) {\n        return this.emit('error', new Error('DataChannelNotSupported'));\n    }\n\n};\n\nmodule.exports = SimpleWebRTC;\n"]}