TriggeredConnectState Enumeration

Indique l'état actuel d'une connexion à une application homologue.

Syntaxe


var value = Windows.Networking.Proximity.TriggeredConnectState.peerFound;

Attributs

[Version(0x06020000)]

Membres

TriggeredConnectStateÉnumération possède ces membres.

MembreValeurDescription
PeerFound | peerFound0

Un périphérique prenant en charge les connexions de socket de proximité se trouve dans la proximité. Le mouvement de frappe est terminé.

Listening | listening1

Ce côté de la connexion de socket sera l'hôte et attend une connexion de l'homologue.

Connecting | connecting2

Ce côté de la connexion de socket sera le client et tente de se connecter à l'homologue.

Completed | completed3

La connexion est terminée, et la classe StreamSocket peut désormais être utilisée pour communiquer avec l'homologue.

Canceled | canceled4

La connexion a été arrêtée avant la fin.

Failed | failed5

Une erreur n'a pas permis d'établir une connexion.

Exemples


var started = false;

// Click event for "Advertise" button.
function advertiseForPeers(launchedFromTap) {
    Windows.Networking.Proximity.PeerFinder.displayName = displayNameTextBox.Text;

    if (Windows.Networking.Proximity.PeerFinder.supportedDiscoveryTypes &
        Windows.Networking.Proximity.PeerDiscoveryTypes.triggered) {

        Windows.Networking.Proximity.PeerFinder.addEventListener(
            "triggeredconnectionstatechanged", triggeredConnectionStateChanged);

        id("messageDiv").innerHTML +=
            "You can tap to connect a peer device that is " +
            "also advertising for a connection.<br />";
    } else {
        id("messageDiv").innerHTML +=
            "Tap to connect is not supported.<br />";
    }

    if (!launchedFromTap) {
        if (!(Windows.Networking.Proximity.PeerFinder.SupportedDiscoveryTypes &
              Windows.Networking.Proximity.PeerDiscoveryTypes.Browse)) {
            id("messageDiv").innerHTML +=
                "Peer discovery using Wi-Fi Direct is not supported.<br />";
        }
    }

    if (!started) {
        Windows.Networking.Proximity.PeerFinder.start();
        started = true;
    }
}

function triggeredConnectionStateChanged(e) {
    if (e.state === Windows.Networking.Proximity.TriggeredConnectState.peerFound) {
        id("messageDiv").innerHTML +=
            "Peer found. You may now pull your devices out of proximity.<br />";
    }
    if (e.state === Windows.Networking.Proximity.TriggeredConnectState.completed) {
        id("messageDiv").innerHTML += "Connected. You may now send a message.<br />";
        sendMessage(e.socket);
    }
}


// Click event for "Browse" button.
function findPeers() {
    if (Windows.Networking.Proximity.PeerFinder.supportedDiscoveryTypes &
        Windows.Networking.Proximity.PeerDiscoveryTypes.browse) {

        Windows.Networking.Proximity.PeerFinder.findAllPeersAsync().done(
    function (peerInfoCollection) {
        if (peerInfoCollection.length > 0) {
            // Connect to first peer found - example only.
            // In your app, provide the user with a list of available peers.
            connectToPeer(peerInfoCollection[0]);
        }
    },
    function (err) {
        id("messageDiv").innerHTML += "Error finding peers: " + err + "<br />";
    });
    } else {
        id("messageDiv").innerHTML +=
        "Peer discovery using Wi-Fi Direct is not supported.<br />";
    }
}

function connectToPeer(peerInfo) {
    id("messageDiv").innerHTML += ("Peer found. Connecting to " + peerInfo.displayName + "<br />");
    Windows.Networking.Proximity.PeerFinder.connectAsync(peerInfo).done(
        function (socket) {
            id("messageDiv").innerHTML += "Connection successful. You may now send messages.<br />";
            sendMessage(socket);
        },
        function (err) {
            id("messageDiv").innerHTML += "Connection failed: " + err + "<br />";
        });

    requestingPeer = null;
}

function stopFindingPeers() {
    Windows.Networking.Proximity.PeerFinder.stop();
    started = false;
    if (proximitySocket != null) { closeSocket(); }
}

// Handle external connection requests.
var requestingPeer;

function connectionRequested(e) {
    id("messageDiv").innerHTML +=
        "Connection requested by " + e.peerInformation.DisplayName + ". " +
        "Click 'Accept Connection' to connect.";
    requestingPeer = e.PeerInformation;
}

function acceptConnection() {
    if (requestingPeer == null) {
        id("messageDiv").innerHTML += "No peer connection has been requested.";
        return;
    }

    connectToPeer(requestingPeer);
}


Conditions requises

Client minimal pris en charge

Windows 8

Serveur minimal pris en charge

Windows Server 2012

Téléphone minimal pris en charge

Windows Phone 8

Espace de noms

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

Métadonnées

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]

Voir aussi

Proximité et geste tactile (JavaScript)
Proximité et geste tactile (C#/VB/C++)
Exemples
Exemple de proximité

 

 

Afficher:
© 2014 Microsoft