リモート デバイスの検出

アプリは、ワイヤレス ネットワーク、Bluetooth、およびクラウド接続を使って、検出側デバイスと同じ Microsoft アカウントでサインインしている Windows デバイスを検出できます。 リモート デバイスを検出するために特別なソフトウェアをインストールする必要はありません。

注意

このガイドでは、「リモート アプリの起動」の手順に従うことで、リモート システム機能へのアクセスが既に許可されていることを前提としています。

検出可能な一連のデバイスのフィルター処理

フィルターに RemoteSystemWatcher を使うことで、検出可能な一連のデバイスを絞り込むことができます。 フィルターは、検出の種類 (隣接ネットワーク、ローカル ネットワーク、またはクラウド接続)、デバイスの種類 (デスクトップ、モバイル デバイス、Xbox、Hub、ホログラフィック)、利用可能ステータス (デバイスがリモート システム機能を利用可能かどうかのステータス) を検出できます。

RemoteSystemWatcher オブジェクトを初期化する前か、その初期化中に、フィルター オブジェクトを作成する必要があります。コンストラクターにパラメーターとして渡されるためです。 次のコードでは、利用可能な各種類のフィルターを作成し、一覧に追加します。

注意

この例のコードでは、ファイルに using Windows.System.RemoteSystems ステートメントがあることを利用としています。

private List<IRemoteSystemFilter> makeFilterList()
{
    // construct an empty list
    List<IRemoteSystemFilter> localListOfFilters = new List<IRemoteSystemFilter>();

    // construct a discovery type filter that only allows "proximal" connections:
    RemoteSystemDiscoveryTypeFilter discoveryFilter = new RemoteSystemDiscoveryTypeFilter(RemoteSystemDiscoveryType.Proximal);


    // construct a device type filter that only allows desktop and mobile devices:
    // For this kind of filter, we must first create an IIterable of strings representing the device types to allow.
    // These strings are stored as static read-only properties of the RemoteSystemKinds class.
    List<String> listOfTypes = new List<String>();
    listOfTypes.Add(RemoteSystemKinds.Desktop);
    listOfTypes.Add(RemoteSystemKinds.Phone);

    // Put the list of device types into the constructor of the filter
    RemoteSystemKindFilter kindFilter = new RemoteSystemKindFilter(listOfTypes);


    // construct an availibility status filter that only allows devices marked as available:
    RemoteSystemStatusTypeFilter statusFilter = new RemoteSystemStatusTypeFilter(RemoteSystemStatusType.Available);


    // add the 3 filters to the listL
    localListOfFilters.Add(discoveryFilter);
    localListOfFilters.Add(kindFilter);
    localListOfFilters.Add(statusFilter);

    // return the list
    return localListOfFilters;
}

注意

"proximal" フィルター値は、物理的な近さの度合いを保証するものではありません。 確実に物理的に近いことが求められるシナリオでは、フィルターに RemoteSystemDiscoveryType.SpatiallyProximal を使用します。 現時点では、このフィルターで許容されるデバイスは Bluetooth 経由で検出されたものに限られます。 物理的に隣接していることを保証する新しい検出メカニズムとプロトコルがサポートされたら、このフィルターにも組み込まれます。
また、検出したデバイスが実際に物理的に近い範囲内にあるかどうかを示す、RemoteSystem.IsAvailableBySpatialProximity という、RemoteSystem クラスのプロパティもあります。

注意

ローカル ネットワーク経由でデバイスを検出する場合 (検出の種類のフィルターの選択で決定されます)、ネットワークで "プライベート" または "ドメイン" プロファイルを使用する必要があります。 デバイスでは、"パブリック" ネットワーク経由で他のデバイスを検出しません。

IRemoteSystemFilter オブジェクトの一覧を作成すると、RemoteSystemWatcher のコンストラクターに渡すことができます。

// store filter list
List<IRemoteSystemFilter> listOfFilters = makeFilterList();

// construct watcher with the list
m_remoteSystemWatcher = RemoteSystem.CreateWatcher(listOfFilters);

このウォッチャーの Start メソッドが呼び出されると、次の条件を満たすデバイスが検出された場合のみ RemoteSystemAdded イベントが発生します。

  • 近接接続によって検出可能
  • デスクトップまたは携帯電話である
  • 利用可能として分類されている

これ以降、イベントの処理、RemoteSystem オブジェクトの取得、リモート デバイスへの接続の手順は「リモート アプリの起動」とまったく同じ手順です。 つまり、RemoteSystem オブジェクトは、各 RemoteSystemAdded イベントで渡される RemoteSystemAddedEventArgs オブジェクトのプロパティとして格納されます。

アドレス入力によるデバイスの検出

ユーザーに関連付けられていないか、スキャンで検出することができないデバイスでも、検出側のアプリが直接アドレスを使う場合はアクセスできます。 リモート デバイスのアドレスを表すには、HostName クラスを使います。 これは多くの場合 IP アドレスの形式で保存されますが、他のいくつかの形式も使うことができます (詳しくは、「HostName コンス トラクター」をご覧ください)。

RemoteSystem オブジェクトは、有効な HostName オブジェクトが指定された場合に取得されます。 アドレス データが無効な場合、null オブジェクト参照が返されます。

private async Task<RemoteSystem> getDeviceByAddressAsync(string IPaddress)
{
    // construct a HostName object
    Windows.Networking.HostName deviceHost = new Windows.Networking.HostName(IPaddress);

    // create a RemoteSystem object with the HostName
    RemoteSystem remotesys = await RemoteSystem.FindByHostNameAsync(deviceHost);

    return remotesys;
}

リモート システムの機能の照会

検出フィルタリングからは分離されていますが、デバイスの機能を照会することが検出プロセスの重要な要素になることがあります。 RemoteSystem.GetCapabilitySupportedAsync メソッドを使うと、リモート セッション接続や空間エンティティ (ホログラフィック) 共有などの特定の機能が、検出されたリモートシステムでサポートされているかどうかを照会できます。 照会可能な機能の一覧については、KnownRemoteSystemCapabilities クラスをご覧ください。

// Check to see if the given remote system can accept LaunchUri requests
bool isRemoteSystemLaunchUriCapable = remoteSystem.GetCapabilitySupportedAsync(KnownRemoteSystemCapabilities.LaunchUri);

ユーザー間の検出

開発者は、同一ユーザーに登録されているデバイスだけでなく、クライアント デバイスの近くにあるすべてのデバイスを検出するように指定できます。 これは、特別な IRemoteSystemFilter である、RemoteSystemAuthorizationKindFilter を通じて実装されます。 その実装は、他の種類のフィルターと同じように行われます。

// Construct a user type filter that includes anonymous devices
RemoteSystemAuthorizationKindFilter authorizationKindFilter = new RemoteSystemAuthorizationKindFilter(RemoteSystemAuthorizationKind.Anonymous);
// then add this filter to the RemoteSystemWatcher
  • RemoteSystemAuthorizationKind の値 Anonymous では、信頼されていないユーザーのデバイスも含めて、すべての近接デバイスを検出できるようになります。
  • SameUser では、クライアント デバイスと同じユーザーに登録されているデバイスのみを検出するようにフィルター処理が行われます。 これが既定の動作です。

ユーザー間共有設定の確認

サインイン済みのデバイスで他のユーザーとエクスペリエンスを共有できるようにするには、検出アプリで上記のフィルターを指定することに加えて、クライアント デバイス自体の構成も必要になります。 このシステム設定は、次のように RemoteSystem クラスで静的メソッドを使用することで照会できます。

if (!RemoteSystem.IsAuthorizationKindEnabled(RemoteSystemAuthorizationKind.Anonymous)) {
	// The system is not authorized to connect to cross-user devices. 
	// Inform the user that they can discover more devices if they
	// update the setting to "Anonymous".
}

この設定を変更するには、ユーザーが設定アプリを開く必要があります。 [システム]>[共有エクスペリエンス]>[デバイス間で共有します] メニューの順に移動すると、システムで共有可能なデバイスをユーザーが指定できるドロップダウン ボックスがあります。

[共有エクスペリエンス] 設定ページ