ContentHub - Content Hub JS API

# Content Hub JS API: ContentHub

API Docs for: 0.1

#### Class ContentHub

Class defined in: `content-hub.js:568`

The ContentHub object.

`ContentHub`( `` )
`content-hub.js:568`

- Methods
- Properties

`api.importContent`( `type, peer, transferOptions, onError, onSuccess` )
`content-hub.js:914`

Creates a ContentStore object for the given ContentPeer.

Parameters:

- `type` <ContentType>

  type of the content to import

- `peer` <ContentPeer>

  peer who's content should be imported

- `transferOptions` <Object>

  a dictionary of transfer options. The options are the following:

  - multipleFiles {Bool}: specified if a transfer should involve multiple files or not
  - scope {ContentScope}: specifies the location where the transferred files should be copied to
- `onError` <Function(reason:)>

  called when the transfer has failed

- `onSuccess` <Function(Array of ContentItem>

  )} called when the transfer has been a success and items are available

`getPeers`( `filters, callback` )
`content-hub.js:782`

Creates a ContentPeer object for the given source type.

Parameters:

- `filters` <Object>

  A dictionary of parameters to filter the result. The filtering keys are:

  - contentType: desired ContentType
  - handler: desired ContentHandler
- `callback` <Function(List of ContentPeer objects)>

  Callback that receives the result or null

`getStore`( `scope, callback` )
`content-hub.js:798`

Creates a ContentStore object for the given scope type.

Parameters:

- `scope` <ContentScope>

  The content scope for the store

- `callback` <Function(ContentStore)>

  Callback that receives the result or null

`launchContentPeerPicker`( `filters, onPeerSelected, onCancelPressed` )
`content-hub.js:811`

Launches the content peer picker ui that allows the user to select a peer.

Parameters:

- `filters` <Object>

  A dictionary of parameters to filter the result. The filtering keys are:

  - contentType: desired ContentType
  - handler: desired ContentHandler
  - showTitle: boolean value indicating if the title should be visible
- `onPeerSelected` <Function(ContentPeer)>

  Called when the user has selected a peer

- `onCancelPressed` <Function()>

  Called when the user has pressed cancel

`onExportRequested`( `callback` )
`content-hub.js:827`

Sets a handler that is to be called when the current application is the target of an export request.

Parameters:

- `callback` <Function(ContentTransfer)>

  Function when one requests a resource to be exported. The corresponding ContentTransfer is provided as a parameter.

##### Example

           var api = external.getUnityObject(1.0);
                           var hub = api.ContentHub;

                           var transferState = hub.ContentTransfer.State;

                           function _exportRequested(transfer) {
                             var url = window.location.href;
                             url = url.substr(0, url.lastIndexOf('/')+1) + 'img/ubuntuone-music.png';

                             transfer.setItems([{name: 'Ubuntu One', url: url}],
                               function() {
                                 transfer.setState(hub.ContentTransfer.State.Charged);
                               });
                             };

                           hub.onExportRequested(_exportRequested);

`onImportRequested`( `callback` )
`content-hub.js:886`

Sets a handler that is to be called when the current application is the target of an import request.

Parameters:

- `callback` <Function(ContentTransfer)>

  Function when one requests a resource to be imported. The corresponding ContentTransfer is provided as a parameter.

##### Example

           var api = external.getUnityObject(1.0);
                           var hub = api.ContentHub;

                           var transferState = hub.ContentTransfer.State;

                           function _importRequested(transfer) {
                           };

                           hub.onImportRequested(_importRequested);

`onShareRequested`( `callback` )
`content-hub.js:860`

Sets a handler that is to be called when the current application is the target of an share request.

Parameters:

- `callback` <Function(ContentTransfer)>

  Function when one requests a resource to be shared. The corresponding ContentTransfer is provided as a parameter.

##### Example

           var api = external.getUnityObject(1.0);
                           var hub = api.ContentHub;

                           var transferState = hub.ContentTransfer.State;

                           function _shareRequested(transfer) {
                           };

                           hub.onShareRequested(_shareRequested);

`ContentHandler` <String> (static)
`content-hub.js:614`

ContentHandler is an enumeration of well known content handlers.

Values:

Source

Destination

Share

`ContentScope` <String> (static)
`content-hub.js:634`

ContentScope is an enumeration of well known scope types.

Values:

System

User

App

`ContentTransfer.Direction` <String> (static)
`content-hub.js:736`

ContentTransfer.Direction is an enumeration of the directions of a given ContentTransfer.

Values:

Import

Export

Share

`ContentTransfer.SelectionType` <String> (static)
`content-hub.js:761`

ContentTransfer.SelectionType is an enumeration of the directions of a given ContentTransfer.

Values:

Single: Transfer should contain a single item

Multiple: Transfer can contain multiple items

`ContentTransfer.State` <String> (static)
`content-hub.js:656`

ContentTransfer.State is an enumeration of the state of a given ongoing ContentTransfer.

Values:

Created: Transfer created, waiting to be initiated.

Initiated: Transfer has been initiated.

InProgress: Transfer is in progress.

Charged: Transfer is charged with items and ready to be collected.

Collected: Items in the transfer have been collected.

Aborted: Transfer has been aborted.

Finalized: Transfer has been finished and cleaned up.

Downloaded: Download specified by downloadId has completed.

Downloading: Transfer is downloading item specified by downloadId.

##### Example

var api = external.getUnityObject('1.0'); var hub = api.ContentHub;

var transferState = hub.ContentTransfer.State; var pictureContentType = hub.ContentType.Pictures;

hub.importContentForPeer( pictureContentType, peer, function(transfer) { hub.defaultStoreForType(pictureContentType, function(store) { transfer.setStore(store, function() { transfer.start(function(state) { if (transferState.Aborted === state) { [...] } [...] }); }); }); });

`ContentType` <String> (static)
`content-hub.js:576`

ContentType is an enumeration of well known content types.

Values:

    Pictures

                    Documents

                    Music

                    Contacts

                    Videos

                    Links

##### Example

var api = external.getUnityObject('1.0'); var hub = api.ContentHub;

var pictureContentType = hub.ContentType.Pictures;