cjb/serverless-webrtc

Sending unparsed data to fileReceiver

kruherson1337 opened this issue · 5 comments

When you are sending data to fileReceiver you are sending unparsed object "e.data" not json parsed "data" variable. File transfer doesn't work, because it is expecting json parsed object.

cjb commented

@kruherson1337 Hm, do you have a fix in mind? That description doesn't sound quite right -- there's an if/else there, and in the else path we do JSON parse data before passing it over, and the else path is the common one.

@cjb Well, yes, but look at the code :)

dc1.onmessage = function (e) {
console.log('Got message (pc1)', e.data)
      if (e.data.size) {
        fileReceiver1.receive(e.data, {})
      } else {
        if (e.data.charCodeAt(0) == 2) {
          return
        }
        console.log(e)
        var data = JSON.parse(e.data)
        if (data.type === 'file') {
          fileReceiver1.receive(e.data, {})
        } else {
          writeToChatLog(data.message, 'text-info')
          $('#chatlog').scrollTop($('#chatlog')[0].scrollHeight)
        }
}

fileReceiver1.receive(e.data, {}) must be fileReceiver1.receive(data, {})

By the way, why is file transfer so slow?

cjb commented

fileReceiver1.receive(e.data, {}) must be fileReceiver1.receive(data, {})

Hm, I just tried this and it didn't seem to change any behavior on Chrome. Did it work for you?

By the way, why is file transfer so slow?

Dunno! I didn't put any effort into making it fast.

Yes, it works for me. I am not well experienced in Javascript, but e.data contain a string, which is JSON string, not parsed JSON object.

Fixed the speed and added progress bar :) thank you.

cjb commented

Could you open a PR with your changes, please?