Seshi API 0.1

Seshi is a web api which wrapps WebRTC & IndexedDB features from the html5 spec. It allows the decentralised storage of large files in the browser (IndexedDB), you can then send files direct to peers (WebRTC) and playback the files within the browser (e.g. Video and audio).

We (will be) launching Seshi BETA to the public soon, please register your interest to get early access when we release Seshi pro (whatever pro means these days) to fund further development.

This API is subject to change, so please be ready for some of the API calls to change, or be removed in some way as the application matures.

  • Storage: IndexedDB
  • Peer to Peer File Transfer: WebRTC Data channel
  • Media playback: Any browser supported format
  • Chat: WebRTC Data channel

TODO: Add complete example for creating peer connection using API.

API Calls

All api calls are prefixed with Seshi.<api call>

Call Seshi.help() at any time in console to view the list of Seshi commands.

Settings Related API Calls

Storage operations

Peer to Peer operations

Media operations


.help()

Display the help menu.

.store(StoreReqObject)

Store data into Seshi's IndexedDB database.

Seshi can store data into its database directly from the users file system via an <input type="file" multiple> or receive and store data coming from a connected peer over the RTCdatachannel piece by piece.

Storing files from a file input:
var StoreReqObject =
{
    'dataSource':'fileSystem',
    'data':this.files
}

this.files should be File object from the <input type=file ...> Seshi will then:

  • Loop through each file the user has specified
  • Split it into small chunks
  • Store each chunk into IndexedDB.

Store data coming from a connected peer

var StoreReqObject =
{
    'dataSource':'seshiChunk',
    'data':chunk
};
Seshi.store(StoreReqObject);

Chunk must be a single Seshi chunk taken from the IndexedDB of a connected peer. This is then stored in the receiving peers' Seshi database.

.connectionStatus

Returns object containing iceConnectionState1 & dataChannelState2

To get the iceConnectionState query: Seshi.connectionStatus.iceConnectionState()

To get the DataChannel State query:
Seshi.connectionStatus.dataChannelState()

.storeProgress

Use this call to query the progess of files being stored into Seshi. Storing a file takes time, because Seshi chunks files into ~65k chunks.

.storeProgress Is an array of files currently being stored into Seshi indexed by their unique FileId.

You can query the keys of this array to find out the store progress of each file:

var keys = Object.keys(Seshi.storeProgress)

For example:
Seshi.storeProgress['b5ece06f-4b0a-4158-95dc-e24618a647bd'] where the index is a known FileId.

It's output is a list of the code above shows the names of files being stored and their progress:

//Output 
{
    fileName: "video.ogv",
    currentChunk: 629, 
    totalNumChunks: 729, 
    complete: false
}

.deleteFile(fileId)

Remove a file from Seshi's database.

Seshi.deleteFile(fildId);

Get the list of fileIds currently in the database by calling:

Seshi.localFileList();

.localFileList is a cached list of all files in Seshi's database. This makes it quicker to retrieve a list of all files in the database. To refresh this cache, call Seshi.updateLocalFilesList()

.localFileList()

Returns an array of objects, one for each file. This is a cached list of file names in Seshi's data store for speed. To update the file list cache call Seshi.updateLocalFilesList()

Usage:

var list = Seshi.localFileList();

Returns array of objects containing information about each file stores in Seshi:

[Object, Object, Object...];
console.log(list[0]); //Object:

Object {
    fileId: "086059ca-f03e-42a5-9ff4-0e80baab2a8c", 
boxId: "myBoxID", 
fileName: "Happy Birthday.flac", 
fileType: "audio/mp3"
}

.updateLocalFilesList()

Refreshes Seshi's cached .localFileList() call. It quires the entire IndexedDB for every FilId, and then reports back to Seshi.localFileList() with the most up-to-date list of files in the Data store.

This api call is intensive because it looks at every chunk in the Data Store.

The implementation of this is subject to change to improve its speed. An index will probably be added on 'FileName' of each chunk to make this faster in the future.3

.generateKey()

A key is needed for two peers to exchange their Candidate Addresses4 via a signalling server. A candidate address is basically an IP address & Port Number that a client might be able to be reached upon. This could be a local address, public IP address, Natted address, or the address of a TURN server to relay connections when a peer-to-peer connection cannot be established. See 3

Both peers send their candidate addresses to the signalling server, so that each peer can learn the candidate addresses of each other.

var key = Seshi.generateKey();
console.log(key); //xyz
Seshi.connect(key); //See docs