HoneySam
HoneySam

Reputation: 147

XMPP file transfer using Strophe library

Can anyone let me know the implementation of file transfer in XMPP using strophe library

Upvotes: 4

Views: 2657

Answers (3)

linxingyang
linxingyang

Reputation: 31

you can use si-filetransfer, i was used it to send file , but it seem's not as fast as i want. it send file data in-bind so will be little slowly, maybe should consider SOCKET5 bytestream(out-bind),but i did't try it before.

send file demo, the send() method's parameter is little different because i change it to fit my application, but mostly the same. the frame like this

    // get Strohe.Connection
    getStropheConnection().si_filetransfer.send(file.id, 
        fullJid, sid, file.filename, file.size, filetype, function(err) {

        if(err) {
            // err happen
            return;
        } 

        // when codes comes here,mean your peer agree to receive your file
        // and we will use open to tell your peer you are going to send file
        // open: function (to, sid, bs, cb) 
        getStropheConnection().ibb.open(fullJid, sid, '4096', function(err) {

            if(err) {
                // err happen with open 
                return;
            }

            // code comes here, you can send data
            // call data method to send every peach of your file data
            // data: function (to, sid, seq, data, cb) 

            file.seq = 0; // the file sequence
            getStropheConnection().ibb.data(fullJid, sid, file.seq, d0, function(err) {

                if(err) {
                    // err happen  with data
                    return;
                }

                // repeat sending data util finish
                // call close tell your peer the file sending is finish
                // close: function (to, sid, cb) 
                getStropheConnection().ibb.close(fullJid, sid, function(err) {
                    if(err) {
                        // err happen with close
                        return;
                    }
                }.bind(this));
            }.bind(this));
        }.bind(this));
    }.bind(this));

and receive

_ibbReceiveFileCb : function(type, from, sid, data, seq, blocksize) {


    switch(type) {
        case "open":


          break;
        case "data":


          break;
        case "close":
            // every data through base64 encode, and 3 byte turn to 4 byte
            // compare receive size and file size make sure receive all data
            var resize = Math.ceil(file.blocksize * (file.seq + 1) / 4) * 3;
            var size = file.size; 
            if(resize >= size) {
                // receive all data
            } else {
                // not receive all data
            }
            break;
        default:
          throw new Error("shouldn't be here.");
      }
},

sorry for can not give the full code because it contains other code like some JSON obejct to hold data which may make you feel confuse. just the simple frame is enough

Upvotes: 2

Havihavi
Havihavi

Reputation: 672

theres a strophe si-filetransfer plugin available. You will have to study the code and add the handler along the lines of:

connection.si_filetransfer.(addhandler);

Then use it with :

   connection.si_filetransfer.send(to, sid, filename, size, mime, cb);

I tried it out earlier, but was unsuccessful as it killed my strophe connection for some reason. Maybe you have better luck =)

Upvotes: 2

Nyco
Nyco

Reputation: 136

I would recommand to use the XEP-0065: SOCKS5 Bytestreams that you will need to code by yourself, I'm afraid...

Upvotes: 2

Related Questions