> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 雲端感知 API 呼叫

> 雲端感知 API 呼叫

使用本主題來偵測您的雲端感知作品是否能夠進行串流，以便您針對 XBOX Game Streaming [最佳化您的遊戲](https://docs.xbox.com/zh-TW/build/core-features/common/game-streaming/game-streaming-optimizing-your-game.md)。

## 設定您的遊戲以進行串流

在遊戲初始化期間，請確定您已使用 `XGameStreamingInitialize` 設定遊戲串流元件，如下列程式碼所示。

```C++ theme={null}

// Initialize the game streaming component
XGameStreamingInitialize();

```

若要偵測目前是否有任何已連線的作用中串流用戶端，請使用 `XGameStreamingIsStreaming`，如下列程式碼所示。

```C++ theme={null}
 if (XGameStreamingIsStreaming())
 {
     // The game is currently streaming to at least one device
     // Enable any customizations that might be useful when running from the cloud
 }
```

## 管理連線狀態

如果有任何作用中的串流用戶端，您的遊戲在使用 `XGameStreamingIsStreaming` 時，只能得知這些用戶端在某個時間點的狀態。若要在串流用戶端連線至遊戲或與遊戲中斷連線時收到通知，請使用 [XGameStreamingRegisterConnectionStateChanged](https://docs.xbox.com/zh-TW/reference/system/xgamestreaming/functions/xgamestreamingregisterconnectionstatechanged.md)。

## 參考 API 文件

* [XGameStreaming (API 內容)](https://docs.xbox.com/zh-TW/reference/system/xgamestreaming/xgamestreaming_members.md)
  * 函式
    * [XGameStreamingRegisterConnectionStateChanged](https://docs.xbox.com/zh-TW/reference/system/xgamestreaming/functions/xgamestreamingregisterconnectionstatechanged.md)

## 另請參閱

[XGameStreaming (API 內容)](https://docs.xbox.com/zh-TW/reference/system/xgamestreaming/xgamestreaming_members.md#connection-state)
[最佳化您的遊戲](https://docs.xbox.com/zh-TW/build/core-features/common/game-streaming/game-streaming-optimizing-your-game.md)


## Related topics

- [XGameStreamingRegisterConnectionStateChanged](https://docs.xbox.com/zh-TW/reference/system/xgamestreaming/functions/xgamestreamingregisterconnectionstatechanged.md)
- [XGameStreaming (API 內容)](https://docs.xbox.com/zh-TW/reference/system/xgamestreaming/xgamestreaming_members.md)
- [XBOX Game Streaming 的開發最佳做法](https://docs.xbox.com/zh-TW/build/core-features/common/game-streaming/game-streaming-optimizing-your-game.md)
- [XBOX Cloud Gaming 觸控與串流支援](https://docs.xbox.com/zh-TW/build/core-features/common/game-streaming/index.md)
- [設定 XBOX 開發套件以進行串流](https://docs.xbox.com/zh-TW/build/core-features/common/game-streaming/game-streaming-setup-xbox-developer-kit.md)
