A simple wrapper for the BitTorrent Sync API, based at node-bittorrent-sync. Demonstration page (Only works with enabled api).
To enable the API, you must run BitTorrent Sync with the config file. All official BitTorrent Sync clients will support the API. By using the config file, you will have the ability to run Sync silently without installation, allowing improved integration with your app.
On Mac and Linux, run the Sync executable with --config path_to_file argument. On Windows, use /config path_to_file. The config file may be located in any directory on your drive.
Sync uses JSON format for the configuration file. Here is a sample config file that you can use to enable API:
{
// path to folder where Sync will store its internal data,
// folder must exist on disk
"storage_path" : "/Users/user/.SyncAPI",
// run Sync in GUI-less mode
"use_gui" : false,
"webui" : {
// IP address and port to access HTTP API
"listen" : "127.0.0.1:8888",
// login and password for HTTP basic authentication
// authentication is optional, but it's recommended to use some
// secret values unique for each Sync installation
"login" : "api",
"password" : "secret",
// replace xxx with API key received from BitTorrent
"api_key" : "xxx"
}
}getFoldersGet foldersaddFolderAdd folderremoveFolderRemove foldergetFilesGet filessetFilePrefsSet file preferencesgetFolderPeersGet folder peersgetSecretsGet secretsgetFolderPrefsGet folder preferencessetFolderPrefsSet folder preferencesgetFolderHostsGet folder hostssetFolderHostsSet folder hostsgetPrefsGet preferencessetPrefsSet preferencesgetOsGet OS namegetVersionGet versiongetSpeedGet speedshutdownShutdown
$(document).ready(function () {
'use strict';
var btsync = new BTSync({
host: '127.0.0.1',
port: 8888,
username: 'api',
password: 'secret'
});
btsync.on('authRequired', function () {
// Show message if not authorized
});
// ----------------------------------------
//
// ----------------------------------------
var promiseFolders = btsync.getFolders();
promiseFolders.done(function (res) {
// all good
}).fail(function (e) {
// something wrong
});
// ----------------------------------------
//
// ----------------------------------------
btsync.getFiles({secret:'secret'}).done(function (res) { return res; });
// ----------------------------------------
//
// ----------------------------------------
var callback = function (res) {
return res;
}
btsync['getOs']().done(res);
btsync['setPrefs']({
'params': {
'device_name': 'calculator'
}
}).done(res);
});jQuery BitTorrent Sync is licensed under the MIT License.