WebPubSubServiceClient Class

WebPubSubServiceClient.

Constructor

WebPubSubServiceClient(endpoint: str, hub: str, credential: TokenCredential | AzureKeyCredential, **kwargs: Any)

Parameters

Name Description
endpoint
Required
str

HTTP or HTTPS endpoint for the Web PubSub service instance.

hub
Required
str

Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

credential
Required

Credential needed for the client to connect to Azure.

Keyword-Only Parameters

Name Description
api_version
str

Api Version. The default value is "2021-10-01". Note that overriding this default value may result in unsupported behavior.

Methods

add_connection_to_group

Add a connection to the target group.

Add a connection to the target group.

add_user_to_group

Add a user to the target group.

Add a user to the target group.

close
close_all_connections

Close the connections in the hub.

Close the connections in the hub.

close_connection

Close the client connection.

Close the client connection.

close_group_connections

Close connections in the specific group.

Close connections in the specific group.

close_user_connections

Close connections for the specific user.

Close connections for the specific user.

connection_exists

Check if the connection with the given connectionId exists.

Check if the connection with the given connectionId exists.

from_connection_string

Create a new WebPubSubServiceClient from a connection string.

get_client_access_token

Build an authentication token.

grant_permission

Grant permission to the connection.

Grant permission to the connection.

group_exists

Check if there are any client connections inside the given group.

Check if there are any client connections inside the given group.

has_permission

Check if a connection has permission to the specified action.

Check if a connection has permission to the specified action.

list_connections

List connections in a group.

List connections in a group.

remove_connection_from_all_groups

Remove a connection from all groups.

Remove a connection from all groups.

remove_connection_from_group

Remove a connection from the target group.

Remove a connection from the target group.

remove_user_from_all_groups

Remove a user from all groups.

Remove a user from all groups.

remove_user_from_group

Remove a user from the target group.

Remove a user from the target group.

revoke_permission

Revoke permission for the connection.

Revoke permission for the connection.

send_request

Runs the network request through the client's chained policies.


>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

send_to_all

Broadcast content inside request body to all the connected client connections.

Broadcast content inside request body to all the connected client connections.

send_to_connection

Send content inside request body to the specific connection.

Send content inside request body to the specific connection.

send_to_group

Send content inside request body to a group of connections.

Send content inside request body to a group of connections.

send_to_user

Send content inside request body to the specific user.

Send content inside request body to the specific user.

user_exists

Check if there are any client connections connected for the given user.

Check if there are any client connections connected for the given user.

add_connection_to_group

Add a connection to the target group.

Add a connection to the target group.

add_connection_to_group(group: str, connection_id: str, **kwargs: Any) -> None

Parameters

Name Description
group
Required
str

Target group name, which length should be greater than 0 and less than 1025. Required.

connection_id
Required
str

Target connection Id. Required.

Returns

Type Description

None

Exceptions

Type Description

add_user_to_group

Add a user to the target group.

Add a user to the target group.

add_user_to_group(group: str, user_id: str, **kwargs: Any) -> None

Parameters

Name Description
group
Required
str

Target group name, which length should be greater than 0 and less than 1025. Required.

user_id
Required
str

Target user Id. Required.

Returns

Type Description

None

Exceptions

Type Description

close

close() -> None

close_all_connections

Close the connections in the hub.

Close the connections in the hub.

close_all_connections(*, excluded: List[str] | None = None, reason: str | None = None, **kwargs: Any) -> None

Keyword-Only Parameters

Name Description
excluded

Exclude these connectionIds when closing the connections in the hub. Default value is None.

Default value: None
reason
str

The reason closing the client connection. Default value is None.

Default value: None

Returns

Type Description

None

Exceptions

Type Description

close_connection

Close the client connection.

Close the client connection.

close_connection(connection_id: str, *, reason: str | None = None, **kwargs: Any) -> None

Parameters

Name Description
connection_id
Required
str

Target connection Id. Required.

Keyword-Only Parameters

Name Description
reason
str

The reason closing the client connection. Default value is None.

Default value: None

Returns

Type Description

None

Exceptions

Type Description

close_group_connections

Close connections in the specific group.

Close connections in the specific group.

close_group_connections(group: str, *, excluded: List[str] | None = None, reason: str | None = None, **kwargs: Any) -> None

Parameters

Name Description
group
Required
str

Target group name, which length should be greater than 0 and less than 1025. Required.

Keyword-Only Parameters

Name Description
excluded

Exclude these connectionIds when closing the connections in the group. Default value is None.

Default value: None
reason
str

The reason closing the client connection. Default value is None.

Default value: None

Returns

Type Description

None

Exceptions

Type Description

close_user_connections

Close connections for the specific user.

Close connections for the specific user.

close_user_connections(user_id: str, *, excluded: List[str] | None = None, reason: str | None = None, **kwargs: Any) -> None

Parameters

Name Description
user_id
Required
str

The user Id. Required.

Keyword-Only Parameters

Name Description
excluded

Exclude these connectionIds when closing the connections for the user. Default value is None.

Default value: None
reason
str

The reason closing the client connection. Default value is None.

Default value: None

Returns

Type Description

None

Exceptions

Type Description

connection_exists

Check if the connection with the given connectionId exists.

Check if the connection with the given connectionId exists.

connection_exists(connection_id: str, **kwargs: Any) -> bool

Parameters

Name Description
connection_id
Required
str

The connection Id. Required.

Returns

Type Description

bool

Exceptions

Type Description

from_connection_string

Create a new WebPubSubServiceClient from a connection string.

from_connection_string(connection_string: str, hub: str, **kwargs: Any) -> WebPubSubServiceClient

Parameters

Name Description
connection_string
Required
str

Connection string

hub
Required
str

Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

Returns

Type Description

get_client_access_token

Build an authentication token.

get_client_access_token(*, client_protocol: str | None = 'Default', **kwargs: Any) -> MutableMapping[str, Any]

Keyword-Only Parameters

Name Description
user_id
str

User Id.

roles

Roles that the connection with the generated token will have.

minutes_to_expire
int

The expire time of the generated token.

jwt_headers

Any headers you want to pass to jwt encoding.

groups

Groups that the connection will join when it connects. Default value is None.

client_protocol

The type of client protocol. Case-insensitive. If not set, it's "Default". For Web PubSub for Socket.IO, "SocketIO" type is supported. For Web PubSub, the valid values are 'Default', 'MQTT'. Known values are: "Default", "MQTT" and "SocketIO". Default value is "Default".

Default value: Default

Returns

Type Description
<xref:JSON>

JSON response containing the web socket endpoint, the token and a url with the generated access token.

Examples


>>> get_client_access_token()
{
    'baseUrl': 'wss://contoso.com/api/webpubsub/client/hubs/theHub',
    'token': '<access-token>...',
    'url': 'wss://contoso.com/api/webpubsub/client/hubs/theHub?access_token=<access-token>...'
}

grant_permission

Grant permission to the connection.

Grant permission to the connection.

grant_permission(permission: str, connection_id: str, *, target_name: str | None = None, **kwargs: Any) -> None

Parameters

Name Description
permission
Required
str

The permission: current supported actions are joinLeaveGroup and sendToGroup. Known values are: "sendToGroup" and "joinLeaveGroup". Required.

connection_id
Required
str

Target connection Id. Required.

Keyword-Only Parameters

Name Description
target_name
str

The meaning of the target depends on the specific permission. For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name. Default value is None.

Default value: None

Returns

Type Description

None

Exceptions

Type Description

group_exists

Check if there are any client connections inside the given group.

Check if there are any client connections inside the given group.

group_exists(group: str, **kwargs: Any) -> bool

Parameters

Name Description
group
Required
str

Target group name, which length should be greater than 0 and less than 1025. Required.

Returns

Type Description

bool

Exceptions

Type Description

has_permission

Check if a connection has permission to the specified action.

Check if a connection has permission to the specified action.

has_permission(permission: str, connection_id: str, *, target_name: str | None = None, **kwargs: Any) -> bool

Parameters

Name Description
permission
Required
str

The permission: current supported actions are joinLeaveGroup and sendToGroup. Known values are: "sendToGroup" and "joinLeaveGroup". Required.

connection_id
Required
str

Target connection Id. Required.

Keyword-Only Parameters

Name Description
target_name
str

The meaning of the target depends on the specific permission. For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name. Default value is None.

Default value: None

Returns

Type Description

bool

Exceptions

Type Description

list_connections

List connections in a group.

List connections in a group.

list_connections(*, group: str, top: int | None = None, **kwargs: Any) -> ItemPaged[GroupMember]

Keyword-Only Parameters

Name Description
group
str

Target group name, whose length should be greater than 0 and less than 1025. Required.

top
int

The maximum number of connections to return. If the value is not set, then all the connections in a group are returned. Default value is None.

Default value: None

Returns

Type Description

An iterator like instance of GroupMember object

Exceptions

Type Description

Examples


   connections = client.list_connections(
       group="group_name",
       top=100
   )

   for member in connections:
       assert member.connection_id is not None

remove_connection_from_all_groups

Remove a connection from all groups.

Remove a connection from all groups.

remove_connection_from_all_groups(connection_id: str, **kwargs: Any) -> None

Parameters

Name Description
connection_id
Required
str

Target connection Id. Required.

Returns

Type Description

None

Exceptions

Type Description

remove_connection_from_group

Remove a connection from the target group.

Remove a connection from the target group.

remove_connection_from_group(group: str, connection_id: str, **kwargs: Any) -> None

Parameters

Name Description
group
Required
str

Target group name, which length should be greater than 0 and less than 1025. Required.

connection_id
Required
str

Target connection Id. Required.

Returns

Type Description

None

Exceptions

Type Description

remove_user_from_all_groups

Remove a user from all groups.

Remove a user from all groups.

remove_user_from_all_groups(user_id: str, **kwargs: Any) -> None

Parameters

Name Description
user_id
Required
str

Target user Id. Required.

Returns

Type Description

None

Exceptions

Type Description

remove_user_from_group

Remove a user from the target group.

Remove a user from the target group.

remove_user_from_group(group: str, user_id: str, **kwargs: Any) -> None

Parameters

Name Description
group
Required
str

Target group name, which length should be greater than 0 and less than 1025. Required.

user_id
Required
str

Target user Id. Required.

Returns

Type Description

None

Exceptions

Type Description

revoke_permission

Revoke permission for the connection.

Revoke permission for the connection.

revoke_permission(permission: str, connection_id: str, *, target_name: str | None = None, **kwargs: Any) -> None

Parameters

Name Description
permission
Required
str

The permission: current supported actions are joinLeaveGroup and sendToGroup. Known values are: "sendToGroup" and "joinLeaveGroup". Required.

connection_id
Required
str

Target connection Id. Required.

Keyword-Only Parameters

Name Description
target_name
str

The meaning of the target depends on the specific permission. For joinLeaveGroup and sendToGroup, targetName is a required parameter standing for the group name. Default value is None.

Default value: None

Returns

Type Description

None

Exceptions

Type Description

send_request

Runs the network request through the client's chained policies.


>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

send_request(request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse

Parameters

Name Description
request
Required

The network request you want to make. Required.

Keyword-Only Parameters

Name Description
stream

Whether the response payload will be streamed. Defaults to False.

Default value: False

Returns

Type Description

The response of your network call. Does not do error handling on your response.

send_to_all

Broadcast content inside request body to all the connected client connections.

Broadcast content inside request body to all the connected client connections.

send_to_all(message: IO | str | MutableMapping[str, Any], *, excluded: List[str] | None = None, filter: str | None = None, content_type: str | None = None, **kwargs: Any) -> None

Parameters

Name Description
message
Required
Union[IO, str, <xref:JSON>]

The payload body. Required.

Keyword-Only Parameters

Name Description
excluded

Excluded connection Ids. Default value is None.

Default value: None
filter
str

Following OData filter syntax to filter out the subscribers receiving the messages. Default value is None.

Default value: None
content_type
str

The content type of the payload. Default value is None. Allowed values are 'application/json', 'application/octet-stream' and 'text/plain'

Default value: None

Returns

Type Description

None

Exceptions

Type Description

send_to_connection

Send content inside request body to the specific connection.

Send content inside request body to the specific connection.

send_to_connection(connection_id: str, message: IO | str | MutableMapping[str, Any], *, content_type: str | None = None, **kwargs: Any) -> None

Parameters

Name Description
connection_id
Required
str

The connection Id. Required.

message
Required
Union[IO, str, <xref:JSON>]

The payload body. Required.

Keyword-Only Parameters

Name Description
content_type
str

The content type of the payload. Default value is None. Allowed values are 'application/json', 'application/octet-stream' and 'text/plain'

Default value: None

Returns

Type Description

None

Exceptions

Type Description

send_to_group

Send content inside request body to a group of connections.

Send content inside request body to a group of connections.

send_to_group(group: str, message: IO | str | MutableMapping[str, Any], *, excluded: List[str] | None = None, filter: str | None = None, content_type: str | None = None, **kwargs: Any) -> None

Parameters

Name Description
group
Required
str

Target group name, which length should be greater than 0 and less than 1025. Required.

message
Required
Union[IO, str, <xref:JSON>]

The payload body. Required.

Keyword-Only Parameters

Name Description
excluded

Excluded connection Ids. Default value is None.

Default value: None
filter
str

Following OData filter syntax to filter out the subscribers receiving the messages. Default value is None.

Default value: None
content_type
str

The content type of the payload. Default value is None. Allowed values are 'application/json', 'application/octet-stream' and 'text/plain'

Default value: None

Returns

Type Description

None

Exceptions

Type Description

send_to_user

Send content inside request body to the specific user.

Send content inside request body to the specific user.

send_to_user(user_id: str, message: IO | str | MutableMapping[str, Any], *, filter: str | None = None, content_type: str | None = None, **kwargs: Any) -> None

Parameters

Name Description
user_id
Required
str

The user Id. Required.

message
Required
Union[IO, str, <xref:JSON>]

The payload body. Required.

Keyword-Only Parameters

Name Description
filter
str

Following OData filter syntax to filter out the subscribers receiving the messages. Default value is None.

Default value: None
content_type
str

The content type of the payload. Default value is None. Allowed values are 'application/json', 'application/octet-stream' and 'text/plain'

Default value: None

Returns

Type Description

None

Exceptions

Type Description

user_exists

Check if there are any client connections connected for the given user.

Check if there are any client connections connected for the given user.

user_exists(user_id: str, **kwargs: Any) -> bool

Parameters

Name Description
user_id
Required
str

Target user Id. Required.

Returns

Type Description

bool

Exceptions

Type Description