Header_Audio_APIHeader_Audio_API

Develop apps to control Sony's latest home audio devices

Using WebSockets with Sony's Audio Control API

Here you'll find a tutorial to help you understand how to use WebSockets when working with the Audio Control API.

WebSocket example:

1Step 1: Requirements

To follow this example, you must have Node.js installed. For more information and instructions, see https://nodejs.org/en/ and https://en.wikipedia.org/wiki/Node.js.

We will also use the WebSocket Node.js library, which can be installed with npm.

2Step 2: Setup

  • Create a new folder, open a terminal, and go to the newly created directory.
  • In the newly created directory initialize Node.js and accept defaults.
  • Install the WebSocket library.

3Step 3: Get playing content info notifications

  • Create a playing_content_info.js file, and include the following code:
  • Note: you will have to change the IP address and port number in the last line. To find the {ipaddress} and {port} number see X_ScalarWebAPI_BaseURL in Discovery Process, for example, for Home Audio products the port is usually 10000 and for Personal Audio products, 54480. The {ipaddress} is the IP address of the audio product.To get the playing content info notifications, you must enable the notifyPlayingContentInfo notification via the switchNotifications method.
  • Enter the following code in the terminal or command prompt to run the code.
  • The output should be similar to the following:

Note: A new Received message should be posted in the terminal every time the input source is changed.