Strophe.js文件传输的完整示例 [英] Complete example of Strophe.js file transfer
问题描述
我正在使用Strophe.js开发一个聊天Web客户端(基于XMPP)。在服务器端,我有一个Openfire服务器。
I'm developing a chat web client (XMPP based) using Strophe.js. On server side I have an Openfire server.
我正在寻找一个完整(和工作)的文件传输示例( xep-0096 )使用Strophe.js。
I'm looking for a complete (and working) example of file transfer (xep-0096) using Strophe.js.
我知道有一个插件,名为 si-filetransfer ,它应该有助于实现此功能,但缺少文档。所以要理解它是如何工作的并不容易。
I know there is a plugin, named si-filetransfer, which should help in implementing this feature but documentation is missing. So it is not easy to understand how it works.
在StackOverflow上,我发现只有一些不完整的帖子与此事有关,例如:从xmpp strophe si-filetransfer中保存收到的文件
Here on StackOverflow I found only some incomplete post relating the matter, as for example: Save received files from xmpp Strophe si-filetransfer
同样在网络上,我找不到任何完整的解决方案来满足我的需求。
Also on the web I didn't find any complete solution to my needs.
如果还有其他解决方案可以实现上述目标(文件传输到一个使用XMPP协议的JS客户端)欢迎!
If there is another solution to achieve the above goal (file transfer in a JS client using XMPP protocol) it 's welcome!
推荐答案
以下是使用编写的一个非常简单的聊天演示文件传输 jQuery 和 StropheJS 特征。文件传输的实现基于这两个Strophe.js插件:
Here below is a very simple chat demo written using jQuery and StropheJS with file transfer features. Implementation of file transfer is based on these two Strophe.js plugins:
https://github.com/strophe/strophejs-plugins/tree/master/si-filetransfer: it allows to send and receive stream initiations
https://github.com/strophe/strophejs-plugins/tree/master/ibb 。它提供了一种传输机制(带内字节流)
https://github.com/strophe/strophejs-plugins/tree/master/ibb. it provides a transport mechanism (In-Band Bytestream)
此外,为了允许更大的文件传输除了65535字节之外,它还使用了一个分块算法。
In addition, in order to allow the transfer of files greater than 65535 bytes it is also used a chunking algorithm.
这是Plunker: http://plnkr.co/edit/fYpXo1mFRWPxrLlgr123
Here is the Plunker: http://plnkr.co/edit/fYpXo1mFRWPxrLlgr123
PS:您必须部署自己的XMPP服务器并调整以下代码行根据您的配置:
P.S.: you have to deploy your own XMPP server and adapt the following code lines according to your configuration:
var server = 'mydomain.com';
var BOSH_SERVICE = 'http://127.0.0.1:7070/http-bind/';
这篇关于Strophe.js文件传输的完整示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!