https://github.com/strophe/strophejs-plugin-ibb
https://github.com/strophe/strophejs-plugin-ibb
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/strophe/strophejs-plugin-ibb
- Owner: strophe
- Created: 2017-01-25T13:40:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-06T12:27:27.000Z (over 9 years ago)
- Last Synced: 2025-06-19T05:08:36.176Z (11 months ago)
- Size: 2.93 KB
- Stars: 2
- Watchers: 13
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
XEP-0047: In-Band Bytestreams
=============================
http://xmpp.org/extensions/xep-0047.html
> This specification defines an XMPP protocol extension that enables any two entities to establish a one-to-one bytestream between themselves, where the data is broken down into smaller chunks and transported in-band over XMPP.
Usage
-----
Include the stream initiation and ibb plugins in the head.
``` html
```
Add handlers to listen for stream initiations and files, or use the api to send files of your own.
``` javascript
var connection = new Strophe.Connection();
var fileHandler = function(from, sid, filename, size, mime) {
// received a stream initiation
// save to data and be prepared to receive the file.
};
connection.si_filetransfer.addFileHandler(fileHandler);
var ibbHandler = function (type, from, sid, data, seq) {
switch(type) {
case "open":
// new file, only metadata
break;
case "data":
// data
break;
case "close":
// and we're done
default:
throw new Error("shouldn't be here.")
}
};
connection.ibb.addIBBHandler(ibbHandler);
// send a stream initiation
connection.si_filetransfer.send(to, sid, filename, filesize, mime, function (err) {
if (err) {
return console.log(err);
}
// successfully initiated the transfer, now open the band
connection.ibb.open(to, sid, chunksize, function (err) {
if (err) {
return console.log(err);
}
// stream is open, start sending chunks of data
connection.ibb.data(to, sid, seq, msg, function (err) {
if (err) {
return console.log(err);
}
// ... repeat calling data
// keep sending until you're ready you've reached the end of the file
connection.ibb.close(to, sid, function (err) {
if (err) {
return console.log(err);
}
// done
});
});
});
});
```