Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending unparsed data to fileReceiver #26

Open
kruherson1337 opened this issue Sep 8, 2016 · 5 comments
Open

Sending unparsed data to fileReceiver #26

kruherson1337 opened this issue Sep 8, 2016 · 5 comments

Comments

@kruherson1337
Copy link

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
Copy link
Owner

cjb commented Sep 8, 2016

@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
Copy link
Author

kruherson1337 commented Sep 9, 2016

@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
Copy link
Owner

cjb commented Sep 9, 2016

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
Copy link
Author

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
Copy link
Owner

cjb commented Sep 14, 2016

Could you open a PR with your changes, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants