使用Strophe库传输XMPP文件 [英] XMPP file transfer using Strophe library

查看:147
本文介绍了使用Strophe库传输XMPP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能让我知道使用Strophe在XMPP中进行文件传输的实现 图书馆

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

推荐答案

您可以使用si-filetransfer,我曾用它来发送文件,但它似乎没有我想要的那么快.它以绑定方式发送文件数据,因此速度会有些慢,也许应该考虑使用SOCKET5字节流(绑定),但是我之前没有尝试过.

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()方法的参数几乎没有什么不同,因为我将其更改为适合我的应用程序,但基本相同.这样的框架

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

并接收

_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.");
      }
},

抱歉,无法提供完整的代码,因为它包含其他代码,例如用于保存数据的某些JSON对象,这可能会使您感到困惑.只是简单的框架就足够了

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

这篇关于使用Strophe库传输XMPP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆