You can send a message in the form of a JavaScript Object Notation (JSON) object from a game or app that runs on an Xbox One console to a SmartGlass-enabled device by calling the SmartGlassHtmlSurface::SubmitMessageAsync (SmartGlassHtmlSurface.submitMessageAsync in JavaScript) method.
In the code for your game or app, create a JSON object that specifies the message that you want to send.
C++
Platform::String^ message =
Utils::FormatString(L"{ \"message\": \"Hello, SmartGlass-enabled device.\" }");
var message =
{
message: "Hello, SmartGlass-enabled device."
};
Call the SmartGlassHtmlSurface::SubmitMessageAsync (SmartGlassHtmlSurface.submitMessageAsync in JavaScript) method to send the message.
C++
_device->HtmlSurface->SubmitMessageAsync(message);
trace("Sending message: " + JSON.stringify(message) + " to device " +
device.id);
// To send a JSON message to the client, use the HtmlSurface and
// make sure that the message format is actually JSON. A good practice is to
// always pass an object to the send function and then call JSON.stringify
// for the object just before you send it.
// The client does not require that the active surface is an HtmlSurface to
// send and receive messages.
device.htmlSurface.submitMessageAsync(JSON.stringify(message));
In the code for your SmartGlass companion or Native app, include code that receives and processes messages from the Xbox One console.
For information about how to receive from the Xbox One console in a SmartGlass companion, see “Receiving Messages from an Xbox One Console in a SmartGlass Companion” in the SmartGlass Companion SDK documentation. For information about how to receive messages from the Xbox One console in a Native app, see “Receiving Messages from an Xbox One Console in a Native SDK App” in the SmartGlass Native SDK documentation.
Receiving Messages from a SmartGlass-Enabled Device in an Xbox One Game or App