MessageTransmittedHandler delegate

Applies to Windows and Windows Phone

Describes the method that will handle the event that's fired when a published message has been transmitted.

Syntax


var messageTransmittedHandler = function(sender, messageId) {
 /* Your code */
}

Attributes

[Version(0x06020000)]

Parameters

sender

Type: ProximityDevice

The proximity device that published the message.

messageId

Type: Number [JavaScript] | System.Int64 [.NET] | int64 [C++]

The publication ID of the message.

Remarks

Messages continue to be published until the StopPublishingMessage method is called or the ProximityDevice on the publishing computer is released. Messages are delivered to all apps that have subscribed for the same message type.

When using the PublishMessage method, the only supported message type is one that begins with "Windows.". To publish messages using another message type, such as "WindowsMime." or "NDEF:WriteTag", you must use the PublishBinaryMessage method.

The MessageTransmittedHandler delegate is called each time a message is successfully transmitted to a device, regardless of whether any apps were subscribed to the message on that device.

Examples


function id(elementId) {
    return document.getElementById(elementId);
}

var proximityDevice;
var publishedMessageId = -1;
var subscribedMessageId = -1;

function initializeProximityDevice() {
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.getDefault();

    if (proximityDevice) {
        id("publishMessageButton").addEventListener("click", publishMessage);
        id("subscribeForMessageButton").addEventListener("click", subscribeForMessage);
id("stopSubscribingForMessageButton").addEventListener("click", 
    stopSubScribingForMessage);
id("stopPublishingMessageButton").addEventListener("click", 
    stopPublishingMessage);
    }
    else {
        id("messageDiv").innerHTML += "Failed to initialized proximity device.<br />";
    }
}

function publishMessage() {
    // Stop publishing the current message.
    if (publishedMessageId != -1) {
        proximityDevice.stopPublishingMessage(publishedMessageId);
    }

    publishedMessageId = 
proximityDevice.publishMessage("Windows.SampleMessage", id("messageText").value,
                                       messagePublished);
}

    function messagePublished(sender, messageId) {
// The message has been successfully published.
}

function subscribeForMessage() {
    // Only subscribe for the message one time.
    if (subscribedMessageId === -1) {
        subscribedMessageId = 
    proximityDevice.subscribeForMessage("Windows.SampleMessage", messageReceived);
    }
}

function messageReceived(device, message) {
    id("messageDiv").innerHTML += "Message received: " + message.dataAsString + "<br />";
}

    function stopSubscribingForMessage() {
proximityDevice.stopSubscribingForMessage(subscribedMessageId);
    subscribedMessageId = -1;
    }

    function stopPublishingMessage() {
proximityDevice.stopPublishingMessage(publishedMessageId);
    publishedMessageId = -1;
    }


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

Windows.Networking.Proximity
Windows::Networking::Proximity [C++]

Metadata

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]

See also

PublishMessage(String, String, MessageTransmittedHandler)
PublishBinaryMessage(String, IBuffer, MessageTransmittedHandler)
PublishUriMessage(Uri, MessageTransmittedHandler)
Proximity and Tapping (JavaScript)
Proximity and Tapping (C#/VB/C++)
Samples
Proximity sample

 

 

Show:
© 2014 Microsoft