【问题标题】:XMPP file transfer using Strophe library使用 Strophe 库进行 XMPP 文件传输
【发布时间】:2011-09-05 05:10:36
【问题描述】:

谁能告诉我在 XMPP 中使用 strophe 实现文件传输 图书馆

【问题讨论】:

  • 你已经在stackoverflow.com/questions/6965303/…stackoverflow.com/questions/7291483/… 两次问过这个问题,但没有可用的反馈,我知道。一遍又一遍地问同样的问题是没有意义的。据我所知,Strophe.js 不支持 Jingle 文件传输 (XEP-0234),但可以为 Strophe.js 编写扩展 - 如何做到这一点阅读 Jack Moffit 的书“Professional XMPP Programming with JavaScript and jQuery”或写他在twitter.com/#metajack
  • 非常感谢你的建议,其实我是新来的。假设问题未发布,我两次发布了相同的问题

标签: jquery xmpp strophe


【解决方案1】:

我建议您使用XEP-0065: SOCKS5 Bytestreams,您需要自己编写代码,恐怕...

【讨论】:

    【解决方案2】:

    有一个 strophe si-filetransfer 插件可用。 您将不得不研究代码并按照以下方式添加处理程序:

    connection.si_filetransfer.(addhandler);
    

    然后使用它:

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

    我之前尝试过,但由于某种原因它终止了我的 strophe 连接,因此没有成功。也许你有更好的运气=)

    【讨论】:

      【解决方案3】:

      你可以使用 si-filetransfer,我用它来发送文件,但它似乎没有我想要的那么快。它在绑定中发送文件数据,所以会有点慢,也许应该考虑 SOCKET5 字节流(out-bind),但我之前没有尝试过。

      发送文件演示,send() 方法的参数略有不同,因为我更改它以适合我的应用程序,但大部分相同。像这样的框架

          // 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 对象来保存数据,这可能会让您感到困惑。简单的框架就够了

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-12
        • 1970-01-01
        • 1970-01-01
        • 2012-08-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多