To receive messages from a SmartGlass-enabled device in an Xbox One console game or app, create an event handler that you want to run to process the messages when the SmartGlassHtmlSurface::MessageReceived (SmartGlassHtmlSurface.onmessagereceived in JavaScript) event occurs and attach that event handler to the event.
Create an event handler that you want to use to process that message when the SmartGlassHtmlSurface::MessageReceived (SmartGlassHtmlSurface.onmessagereceived in JavaScript) event occurs.
C++
void SGDevice::OnMessageReceived(SmartGlassHtmlSurface^ /*pHtmlSurface*/,
SmartGlassMessageReceivedEventArgs^ /*pValue*/)
{
// Process messages from the SmartGlass device here.
}
// This anonymous function is assigned to the onMessageReceived event in
// the statement in step 2.
function (args)
{
// Show the message that was sent from the device.
trace("Message from the device: " + args.message);
// Convert the message to an object.
var obj = JSON.parse(args.message);
// Process the properties of the object as needed here.
}
Attach the event handler that you defined in step 1 to the SmartGlassHtmlSurface::MessageReceived (SmartGlassHtmlSurface.onmessagereceived in JavaScript) event.
C++
device->HtmlSurface->MessageReceived += ref new
TypedEventHandler<SmartGlassHtmlSurface^,
SmartGlassMessageReceivedEventArgs^>(this,
&SGDevice::OnMessageReceived);
// Note that the anonymous function from step 1 is assigned to the
// onmesssagerecevied event here.
device.htmlSurface.onmessagereceived = function (args)
{
// Show the message that was sent from the device.
trace("Message from the device: " + args.message);
// Convert the message to an object.
var obj = JSON.parse(args.message);
// Process the properties of the object as needed here.
};
Sending Messages from an Xbox One Console to a SmartGlass-Enabled Device