electron-webrtc icon indicating copy to clipboard operation
electron-webrtc copied to clipboard

Error when creating second DataChannel.

Open t-mullen opened this issue 6 years ago • 2 comments

Trying to create 2 datachannels in a row fails with an error.

var wrtc = require('electron-webrtc')()
var pc = new wrtc.RTCPeerConnection({})
 
pc.createDataChannel('label1', {})
pc.createDataChannel('label2', {})
Error: Error evaluating "
        var pc = conns["0"]
        var dc = pc.dataChannels[65535]

        var id = 'dc:' + "0" + ':' + dc.id
        dc.onopen = function () {
          send(id, {
            type: 'open',
            state: {
              ordered: dc.ordered,
              protocol: dc.protocol,
              maxPacketLifeType: dc.maxPacketLifeType,
              maxRetransmits: dc.maxRetransmits,
              negotiated: dc.negotiated,
              reliable: dc.reliable
            }
          })
        }
        dc.onmessage = function (e) {
          send(id, {
            type: 'message',
            event: {
              data: e.data instanceof ArrayBuffer ? arrayBufferToBase64(e.data) : e.data,
              origin: e.origin
            },
            dataType: e.data instanceof ArrayBuffer ? 'binary' : 'string'
          })
        }
        dc.onbufferedamountlow = function () {
          send(id, { type: 'bufferedamountlow' })
        }
        dc.onclose = function () {
          delete pc.dataChannels[dc.id]
          send(id, { type: 'close' })
        }
        dc.onerror = function () {
          send(id, { type: 'error' })
        }
        if (dc.readyState === 'open') dc.onopen()
        for (var i = 0; i < dc.msgQueue.length; i++) {
          dc.onmessage(dc.msgQueue[i])
        }
        dc.msgQueue = null
      " in "window": Cannot read property 'length' of null
    at Daemon.<anonymous> (/Users/Mullen/Desktop/Projects/Web/Working/simple-peer/node_modules/electron-eval/lib/index.js:81:21)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at Daemon.emit (events.js:211:7)

t-mullen avatar Jun 14 '18 03:06 t-mullen

dc.id is always 65535, which is leading to a conflict.

t-mullen avatar Jun 15 '18 17:06 t-mullen

It looks like the non-uniqueness of ids is normal. (Happens in Chrome and Firefox too).

Since they aren't unique, using them for the pc._dataChannels map is incorrect.

t-mullen avatar Jun 15 '18 17:06 t-mullen