Freebox SDK JS
Fast and secure Freebox OS requests.
Simplify Freebox login process and build a remote secure HTTPS connection to your Freebox server for your Javascript applications. You just have to do some configuration for your app's first login.
Prerequisities
- Freebox Revolution or newer
Installation
$ npm install freebox-sdk-js
Usage
After the configuration setup, you can request your Freebox server as the following.
Your best friend is the official API documentation: https://dev.freebox.fr/sdk/os
Example:
const Freebox = ; async { const freebox = ; await freebox; // Get the current Wi-Fi global configuration: https://dev.freebox.fr/sdk/os/wifi const response = await freebox; await freebox; const wifiConfig = responsedataresult; console;};/*{ "enabled": true, "mac_filter_state": "blacklist"}*/
Setup configuration
For a NodeJS server
Our goal here is to complete the configuration to be able to connect securely to your Freebox server from anywhere.
- Initialize configuration file
Createfreebox.config.json
at your project root (same lvl aspackage.json
) with the following and fill app properties. Fillapp_token
only if you already have one. It will be your Freebox's app identity.
// ~/freebox.config.json
- Getting
app_token
&discovery
Getting yourapp_token
&discovery
part is easy withlogin
method !
-
app_token
You just have to confirm your application's access manually on your Freebox Server's screen. It will register your app to your Freebox using yourapp
informations in the config file. -
discovery
It will also getdiscovery
data if they are missing. This is used to establish a secure app HTTPS connection with your Freebox. It's really recommanded by the Freebox OS dev team.
const Freebox = ; async { const freebox = ; await freebox;};
Congratulations, your configuration file is now complete ! Check it out:
// ~/freebox.config.json
- Enjoy !
Let's check if our configuration works with an example Freebox request.
const Freebox = ; async { const freebox = ; await freebox; // Retrieve a Download task: https://dev.freebox.fr/sdk/os/download/ const response = await freebox; const downloads = responsedataresult; console;};/*[{ rx_bytes: 1520000000, tx_bytes: 0, download_dir: 'L0Rpc3F1ZJBkdXIvKkFMTA==', archive_password: '', eta: 0, status: 'done', io_priority: 'normal', type: 'http', piece_length: 0, queue_pos: 1, id: 1532, info_hash: '', created_ts: 1519648735, stop_ratio: 0, tx_rate: 0, name: 'Clean.Bandit.Rather-Be.mp4', tx_pct: 10000, rx_pct: 10000, rx_rate: 0, error: 'none', size: 1520000000 }, {...}]*/
For Browser
For security purpose, I recommand to use it only if you host your JavaScript application in a local web server. You need an app_token
corresponding at your app_id
(you can get it by following the NodeJS guide above).
// freebox.jsvar Freebox = ; // You will have to complete the missing fields// Check your console while doing the first loginvar config = app: app_id: "fbx.my-browser-app-example" app_name: "Browser App example" app_version: "1.0.0" device_name: "My Server" app_token: null discovery: ...; var baseURL = "http://mafreebox.freebox.fr"; async { var freebox = config baseURL ; // Check your console to get app_token and discovery part for next connections. await freebox; // Let's check if our configuration works with an example Freebox request // Retrieve a Download task: https://dev.freebox.fr/sdk/os/download/ var response = await freebox; await freebox; var downloads = responsedataresult; console;};
FAQ
I want to use a custom configuration file path
const Freebox = ; const configPath = __dirname + "/path/to/config/file.json";const freebox = config: configPath ;
I want to use a configuration object
const Freebox = ; const config = app: app_id: "fbx.my-app-example" app_name: "App example" app_version: "1.0.0" device_name: "My PC" app_token: null discovery: ...; const freebox = config ;
For the first login, I want to use another domain to access my Freebox Server
If you already know another domain to access your Freebox server, use baseURL
option.
Once discovery
part filled, you can remove baseURL
option.
By default, baseURL
is the local domain: "http://mafreebox.free.fr"
.
const Freebox = ;const freebox = baseURL: "https://mydomain.freeboxos.fr:3129" ;
License
MIT License Copyright (c) 2018 Mathieu Schimmerling.
Crafted with ❤️