XMPP file transfer using Strophe library

喜夏-厌秋 提交于 2019-12-19 23:25:23

问题


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


回答1:


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




回答2:


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 =)




回答3:


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



来源:https://stackoverflow.com/questions/7304078/xmpp-file-transfer-using-strophe-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!