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

# XGameStreamingRegisterConnectionStateChanged

> XGameStreamingRegisterConnectionStateChanged

# XGameStreamingRegisterConnectionStateChanged

Registra um retorno de chamada a ser invocado quando o estado de conexão de um dispositivo cliente de streaming for alterado.  Após o registro, o retorno de chamada será invocado para todos os dispositivos cliente de streaming que já estiverem conectados.

## Sintaxe

```cpp theme={null}
HRESULT XGameStreamingRegisterConnectionStateChanged(  
         XTaskQueueHandle queue,  
         void* context,  
         XGameStreamingConnectionStateChangedCallback* callback,  
         XTaskQueueRegistrationToken* token  
)  
```

### Parâmetros

*queue*   \_In\_opt\_\
Tipo: XTaskQueueHandle

Identificador da fila assíncrona na qual colocar o retorno de chamada de alteração.

*context*   \_In\_opt\_\
Tipo: void\*

Um ponteiro opcional para o contexto passado para a função de retorno de chamada.

*callback*   \_In\_\
Tipo: XGameStreamingConnectionStateChangedCallback\*

A função de retorno de chamada que será invocada quando o estado de conexão de qualquer dispositivo cliente de streaming for alterado.

*token*   \_Out\_\
Tipo: XTaskQueueRegistrationToken\*

Um ponteiro para o token de registro que pode ser usado para cancelar o registro do evento.

### Valor retornado

Tipo: HRESULT

Retornará **S\_OK** se for bem-sucedido; caso contrário, retornará um código de erro.

#### Erros potenciais

| Código de erro | Valor do erro | Motivo do erro |
| - | - | - |
| E\_GAMESTREAMING\_NOT\_INITIALIZED | 0x89245400 | O runtime do XGameStreaming não foi inicializado. Chame [XGameStreamingInitialize](/pt-BR/reference/system/xgamestreaming/functions/xgamestreaminginitialize) antes de chamar outras APIs. |

Para obter uma lista de códigos de erro, consulte [Códigos de erro](/pt-BR/reference/errorcodes).

## Comentários

<Note>Não é seguro chamar esta função em um thread sensível ao tempo. Para obter mais informações, consulte [Threads sensíveis ao tempo](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads).</Note>

Esta API é a forma recomendada de fazer com que o jogo realize personalizações por dispositivo cliente de streaming e mantenha um estado que permita otimizar a experiência com base na existência de dispositivos conectados.

<Note>Após o registro, o retorno de chamada será invocado para todos os dispositivos cliente de streaming conectados no momento.</Note>

## Exemplo

```cpp theme={null}
    // Called during game startup to hook into any game streaming start/stop events
    void SetupStreamAware()
    {
        // Register a callback for client connections and disconnections. Note that the connection callback
        // will fire for any already connected clients, so do all of our per-client setup in that callback.      
        XGameStreamingConnectionStateChangedRegistrationToken stateChangeToken = {0};
        XGameStreamingRegisterConnectionStateChanged(
            m_taskQueue, this, ConnectionStateChangedCallback, &stateChangeToken);
    }

    static void ConnectionStateChangedCallback(void* context, XGameStreamingClientId client, XGameStreamingConnectionState state)
    {
        static_cast<Game*>(context)->OnConnectionStateChanged(client, state);
    }

    void OnConnectionStateChanged(XGameStreamingClientId client, XGameStreamingConnectionState state)
    {
        switch (state)
        {
        case XGameStreamingConnectionState::Connected: 
            OnClientConnected(client); 
            break;
        case XGameStreamingConnectionState::Disconnected: 
            OnClientDisconnected(client); 
            break;
        default: 
            break;
        }
    }


    void OnClientConnected(XGameStreamingClientId client)
    {
        // Update list of connected clients
        m_streamingClients.push_back(client);

        // Do per-client initialization
        // ...
    }

    void OnClientDisconnected(XGameStreamingClientId client)
    {
        // Release our reference on the client that is no longer streaming the game
        std::remove(m_streamingClients.begin(), m_streamingClients.end(), client);

        // Do per-client cleanup
        // ...
    }



```

## Requisitos

**Cabeçalho:** xgamestreaming.h

**Biblioteca:** xgameruntime.lib

**Plataformas com suporte:** Windows, consoles da família XBOX One e consoles XBOX Series

## Documentação conceitual

* [Chamadas de API com reconhecimento de nuvem](/pt-BR/build/core-features/common/game-streaming/game-streaming-am-i-streaming)
* [Threads sensíveis ao tempo](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## Confira também

[XGameStreamingConnectionState](/pt-BR/reference/system/xgamestreaming/enums/xgamestreamingconnectionstate)\
[XGameStreamingConnectionStateChangedCallback](/pt-BR/reference/system/xgamestreaming/functions/xgamestreamingconnectionstatechangedcallback)\
[XGameStreamingUnregisterConnectionStateChanged](/pt-BR/reference/system/xgamestreaming/functions/xgamestreamingunregisterconnectionstatechanged)\
[XGameStreaming](/pt-BR/reference/system/xgamestreaming/xgamestreaming_members)


## Related topics

- [XGameStreamingRegisterConnectionStateChanged](/reference/system/xgamestreaming/functions/xgamestreamingregisterconnectionstatechanged.md)
- [XGameStreamingUnregisterConnectionStateChanged](/es/reference/system/xgamestreaming/functions/xgamestreamingunregisterconnectionstatechanged.md)
