cjb / serverless-webrtc

A demo of using WebRTC with no signaling server.
Other
1.54k stars 239 forks source link

Sending unparsed data to fileReceiver #26

Open kruherson1337 opened 8 years ago

kruherson1337 commented 8 years ago

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 8 years ago

@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.

kruherson1337 commented 8 years ago

@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 8 years ago

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.

kruherson1337 commented 8 years ago

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 8 years ago

Could you open a PR with your changes, please?