Samsung Electronics logo

Connecting to the AllShare Framework Service

Table of Contents


To use AllShare-related APIs in Samsung Web APIs, an application must connect to the AllShare Framework service using createServiceProvider(). If the application connects successfully, the AllShare Framework service notifies the results with ServiceProviderCreateSuccessCallback callback. The application can then get services using the ServiceProvider instance that came with the ServiceProviderCreateSuccessCallback callback. Using ServiceProvider, an application can get the DeviceFinder instance, which provides the AllShare device finder service. The usage of DeviceFinder is described in 'Discovering AllShare Devices' section in detail.

When there is no need to communicate with the AllShare Framework service, an application can disconnect from the service by calling deleteServiceProvider(); it gets the result from the SuccessCallback callback.

 
/**
* Connect and get service provider of AllShare Framework.
*/
//Define success callback for creating ServiceProvider
var sCB = function(serviceProvider){
    // Framework Service is successfully connected.
    // Service provider has obtained.
};

//Define error callback for creating ServiceProvider.		
var eCB = function(e, state){
	// Connecting to framework service has failed.
	// WebAPIError and ServiceState instances that indicate why connection to the framework service failed,
	// and the current service state will be received.  
	console.log("createServiceProvider error: " + e.message + ", state: "+ state);
};

webapis.allshare.serviceconnector.createServiceProvider(sCB, eCB);
			

The following table shows APIs that are used to connect and disconnect.

Interface Method/Attribute Description
ServiceConnector void createServiceProvider(ServiceProviderCreateSuccessCallback successCallback, ServiceProviderErrorCallback errorCallback) Create a ServiceProvider object.
void deleteServiceProvider(SuccessCallback successCallback, ServiceProviderErrorCallback errorCallback) Delete ServiceProvider object.