Remove the connection state listener.
This function should be called with identical parameters that were used when adding the connection state listener with hwc.addConnectionListener.
<static> removeConnectionListener( ConnectionStateListener, [containingObject] )
| Name | Type | Argument | Description |
| ConnectionStateListener | anonymous.ConnectionStateListener | Callback function with connection state changes | |
| containingObject | Object | (optional) | Optional Object containing definition of ConnectionStateListener |
// doSomething is a global function that gets called from the connection listener.
var doSomething = function()
{
alert("sample function that gets executed when the hwc becomes connected");
}
// connectionListener is the callback function that is given to addConnectionListener.
// When there is a connection event, connectionListener will be invoked with the details.
var connectionListener = function( event, errorCode, errorMessage )
{
if( event == hwc.CONNECTED )
{
doSomething();
}
}
hwc.addConnectionListener( connectionListener );
// At some other point if we want to remove the listener, we use the following line:
hwc.removeConnectionListener( connectionListener );
// connectionStateManager is an object that will contain the connection listener callback as well as
// a variable used by the callback.
var connectionStateManager = {};
// The connectionStateManager keeps track of whether the HWC is connected or not.
connectionStateManager.connected = false;
// A function called by the listener.
connectionStateManager.doSomething = function()
{
if( this.connected )
{
alert("this alert gets displayed if the hwc is connected");
}
}
// This is the callback function that will be passed to addConnectionListener. This callback references variables
// from the containing object (this.connected and this.doSomething), so when we call addConnectionListener we have
// to give the containing object as the second parameter.
connectionStateManager.listener = function( event, errorCode, errorMessage )
{
if( event == hwc.CONNECTED )
{
this.connected = true;
}
else
{
this.connected = false;
}
this.doSomething();
}
// Pass both the listener and the containing object. This enables the listener to refer to variables in the containing object when it is invoked.
hwc.addConnectionListener( connectionStateManager.listener, connectionStateManager );
// At some other point if we want to remove the listener, we use the following line:
hwc.removeConnectionListener( connectionStateManager.listener, connectionStateManager );