The Contact control interface can be used to control the state of the output contacts (VP330 / EVP380) and to retrieve the state of the input contacts.
The following API is asynchronous and is using Promise to return values.
To use this API, you first need to retrieve the contact control interface thanks to IDAL.getControlInterfaces().
Methods
addListener(listener): Promise.<boolean>
Attach an event handler to the Contact control interface.
- Since:
- firmware v1.08
This method was introduced with firmware version v1.08 to make it possible
to run the same code on the player or on a remote browser using IDAL.getRemoteControlInterfaces().
When running on the video player, this method is equivalent to window.addEventListener('idal-contact-event', function(e) {})
.
Example
var contact = ... // Get the Contact interface
contact.addListener(function(event) {
// Here the value of event.type is always 'idal-contact-event'
var info = event.detail;
if (info.type == 'input-change' || !info.type) { // Testing !info.type for compatibility with firmware < v1.08
console.log("Input contact name: " + info.name);
for (var i = 0 ; i < info.values.length ; i++) {
console.log("Contact " + i + ": " + info.values[i]);
}
}
});
Parameters
Name | Type | Description |
---|---|---|
listener |
Listener | The function to run when a contact event occurs. |
Returns
A promise resolved with a boolean
value.
- Type
- Promise.<boolean>
getInputByName(name): Promise.<InputContactInfo> | Promise.<ErrorStatus>
Get the current state of the input contacts.
Input contacts are identified by a name:
- "standalone" for the single contact available on all players.
- "combined" for the 8 input contacts available on VP330 and EVP380.
You can also retrieve the contact states in real time thanks to the InputContactEvent event.
Parameters
Name | Type | Description |
---|---|---|
name |
string | Input contact name ("standalone" or "combined"). |
Returns
-
A promise resolved with an InputContactInfo.
- Type
- Promise.<InputContactInfo>
-
A promise rejected with an ErrorStatus.
- Type
- Promise.<ErrorStatus>
removeListener(listener): Promise.<boolean>
Removes an event handler that has been attached to the Contact interface.
- Since:
- firmware v1.08
Parameters
Name | Type | Description |
---|---|---|
listener |
Listener | The function previously attached with addListener() |
Returns
A promise resolved with a boolean
value.
- Type
- Promise.<boolean>
setInputConfiguration(config): Promise.<boolean> | Promise.<ErrorStatus>
Set the input contacts configuration (control mode).
Input contact combinations are binded to actions ("play folder" by default)
which are automatically managed by the video playback engine.
If you need to override this behavior and control the input contacts from the
HTML/JavaScript layer, you have to call this method with config.controller
set to 'browser'
.
The configuration can be automatically reverted to the default depending on the value of config.lifetime
.
This method can also be used to map input contact events to regular keyboard events. It makes it possible to use input contacts as a keyboard and use generic key event handlers such as keyup and keydown.
Example
Usage of input contacts to keyboard events mapping.
// In this example, 'contact' is the variable referencing the contact control interface..
// Configuring input contacts to act as arrows, enter and escape keys...
// The configuration will be reverted when a new page is loaded.
var config = {
controller: "browser",
lifetime: "url",
keymaps: {
combined: [
"ArrowLeft",
"ArrowRight",
"ArrowUp",
"ArrowDown",
"Enter",
"Escape"
]
}
};
contact.setInputConfiguration(config)
.then(function(e) {
// Do what you need here
})
.catch(function(e) {
// Handle error here
});
// Install keyboard event handler
window.addEventListener("keydown", function(e) {
console.log("Key down: key=" + e.key + ", code=" + e.code + ", keyCode=" + e.keyCode);
});
Parameters
Name | Type | Description |
---|---|---|
config |
InputContactConfig | The configuration to apply to input contacts. |
Returns
-
A promise resolved with a
boolean
value.- Type
- Promise.<boolean>
-
A promise rejected with an ErrorStatus.
- Type
- Promise.<ErrorStatus>
setOutputById(id, value): Promise.<boolean> | Promise.<ErrorStatus>
Set a single output contact state using its identifier.
Parameters
Name | Type | Description |
---|---|---|
id |
number | The contact identifier is a value between 0 and 7. |
value |
number | boolean | The new contact state:
|
Returns
-
A promise resolved with a
boolean
value.- Type
- Promise.<boolean>
-
A promise rejected with an ErrorStatus.
- Type
- Promise.<ErrorStatus>
setOutputByMask(value, mask): Promise.<boolean> | Promise.<ErrorStatus>
Set many output contacts at once.
Parameters
Name | Type | Description |
---|---|---|
value |
number | The bitmask of all the output contact values. |
mask |
number | The bitmask of the contacts to actually set. |
Returns
-
A promise resolved with a
boolean
value.- Type
- Promise.<boolean>
-
A promise rejected with an ErrorStatus.
- Type
- Promise.<ErrorStatus>
Type Definitions
InputContactConfig
Configuration to set on input contacts.
It defines the entity responsible for managing the input contacts: the browser or the video player.
It is also possible to configure the input contact keyboard mapping.
Properties
Name | Type | Attributes | Default | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
controller |
'browser' | 'videoplayer' | The name of input contact controller. |
||||||||||||||
lifetime |
'url' | 'site' | 'session' | 'scenario' |
<optional> |
'url'
|
The configuration lifetime can be set when the controller is the web browser.
|
||||||||||||
keymaps |
Object |
<optional> |
Can only be used when controller is set to Properties
|
List of available key codes
Hover the mouse over the keys to see their names.
InputContactInfo
A InputContactInfo contains the states of one or more input contacts.
Properties
Name | Type | Description |
---|---|---|
name |
string | The logical name of the input contact group. |
values |
Array.<boolean> | An array of input contact values. |
Events
InputContactEvent
InputContactEvent are fired when the state of the input contacts is modified.
- Tutorials:
Properties
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
type |
'idal-contact-event' | The contact event type. |
||||||||||||
detail |
Object |
Properties
|
This event shall be registered using Contact.addListener().
It can also be registered using window.addEventListener()
as defined by the DOM specification.
if you plan to use the remote control interfaces, the later method must be avoided.
Type
Example
// Preferred method: registration using Contact.addListener()
var contact = ... // Get the Contact control interface
contact.addListener(function(e) {
var info = e.detail;
if (info.type == 'input-change' || !info.type) { // Testing !info.type for compatibility with firmware < v1.08
console.log("Input contact name: " + info.name);
for (var i = 0 ; i < info.values.length ; i++) {
console.log("Contact " + i + ": " + info.values[i]);
}
}
});