zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# DO NOT EDIT THIS FILE!
#
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules.
#
# CDP domain: Cast (experimental)
from __future__ import annotations
from .util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
 
@dataclass
class Sink:
    name: str
 
    id_: str
 
    #: Text describing the current session. Present only if there is an active
    #: session on the sink.
    session: typing.Optional[str] = None
 
    def to_json(self):
        json = dict()
        json['name'] = self.name
        json['id'] = self.id_
        if self.session is not None:
            json['session'] = self.session
        return json
 
    @classmethod
    def from_json(cls, json):
        return cls(
            name=str(json['name']),
            id_=str(json['id']),
            session=str(json['session']) if 'session' in json else None,
        )
 
 
def enable(
        presentation_url: typing.Optional[str] = None
    ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Starts observing for sinks that can be used for tab mirroring, and if set,
    sinks compatible with ``presentationUrl`` as well. When sinks are found, a
    ``sinksUpdated`` event is fired.
    Also starts observing for issue messages. When an issue is added or removed,
    an ``issueUpdated`` event is fired.
 
    :param presentation_url: *(Optional)*
    '''
    params: T_JSON_DICT = dict()
    if presentation_url is not None:
        params['presentationUrl'] = presentation_url
    cmd_dict: T_JSON_DICT = {
        'method': 'Cast.enable',
        'params': params,
    }
    json = yield cmd_dict
 
 
def disable() -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Stops observing for sinks and issues.
    '''
    cmd_dict: T_JSON_DICT = {
        'method': 'Cast.disable',
    }
    json = yield cmd_dict
 
 
def set_sink_to_use(
        sink_name: str
    ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Sets a sink to be used when the web page requests the browser to choose a
    sink via Presentation API, Remote Playback API, or Cast SDK.
 
    :param sink_name:
    '''
    params: T_JSON_DICT = dict()
    params['sinkName'] = sink_name
    cmd_dict: T_JSON_DICT = {
        'method': 'Cast.setSinkToUse',
        'params': params,
    }
    json = yield cmd_dict
 
 
def start_tab_mirroring(
        sink_name: str
    ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Starts mirroring the tab to the sink.
 
    :param sink_name:
    '''
    params: T_JSON_DICT = dict()
    params['sinkName'] = sink_name
    cmd_dict: T_JSON_DICT = {
        'method': 'Cast.startTabMirroring',
        'params': params,
    }
    json = yield cmd_dict
 
 
def stop_casting(
        sink_name: str
    ) -> typing.Generator[T_JSON_DICT,T_JSON_DICT,None]:
    '''
    Stops the active Cast session on the sink.
 
    :param sink_name:
    '''
    params: T_JSON_DICT = dict()
    params['sinkName'] = sink_name
    cmd_dict: T_JSON_DICT = {
        'method': 'Cast.stopCasting',
        'params': params,
    }
    json = yield cmd_dict
 
 
@event_class('Cast.sinksUpdated')
@dataclass
class SinksUpdated:
    '''
    This is fired whenever the list of available sinks changes. A sink is a
    device or a software surface that you can cast to.
    '''
    sinks: typing.List[Sink]
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> SinksUpdated:
        return cls(
            sinks=[Sink.from_json(i) for i in json['sinks']]
        )
 
 
@event_class('Cast.issueUpdated')
@dataclass
class IssueUpdated:
    '''
    This is fired whenever the outstanding issue/error message changes.
    ``issueMessage`` is empty if there is no issue.
    '''
    issue_message: str
 
    @classmethod
    def from_json(cls, json: T_JSON_DICT) -> IssueUpdated:
        return cls(
            issue_message=str(json['issueMessage'])
        )