1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // API for communicating with a Google Cast device over an authenticated
7 namespace cast.channel
{
8 // The state of the channel.
10 // The channel is connecting.
12 // The channel is open and available for messaging.
14 // The channel is closing.
16 // The channel is closed.
20 // Error conditions that the channel may encounter. All error conditions
21 // are terminal. When an error condition is encountered the API will:
22 // (1) Transition the channel to readyState == 'closed'.
23 // (2) Set ChannelInfo.lastError to the error condition.
24 // (3) Fire an onError event with the error condition.
25 // (4) Fire an onClose event.
27 // cast.channel.send() was called when ChannelInfo.readyState != 'open'.
29 // Authentication was requested and the receiver could not be
30 // authenticated (invalid signature, invalid handhake, TLS error, etc.)
32 // A new channel could not be created for reasons unrelated to
33 // authentication (e.g., there is already an open channel to the same URL).
35 // There was an error writing or reading from the underlying socket.
37 // A transport level occurred (like an unparseable message).
39 // The client attempted to send an unsupported message type through the
42 // An invalid channel id was passed.
44 // The connection could not be established before timing out.
46 // The receiving end became unresponsive.
52 // Authentication methods that may be required to connect to a Cast receiver.
53 enum ChannelAuthType
{
56 // SSL over TCP with challenge and receiver signature verification.
60 // Describes the information needed to connect to a Cast receiver.
61 // This replaces the prior use of cast:// and casts:// URLs.
62 dictionary ConnectInfo
{
63 // The IPV4 address of the Cast receiver, e.g. '198.1.0.2'.
64 // TODO(mfoltz): Investigate whether IPV6 addresses "just work."
67 // The port number to connect to, 0-65535.
70 // The amount of time to wait in milliseconds before stopping the
71 // connection process. Timeouts are disabled if the value is zero.
72 // The default timeout is 8000ms.
75 // The authentication method required for the channel.
78 // ------------------------------------------------------------------------
79 // Both pingInterval and livenessTimeout must be set to enable keep-alive
82 // The amount of time to wait in milliseconds before sending pings
86 // The maximum amount of idle time allowed before a channel is closed.
87 long? livenessTimeout
;
89 // If set, CastDeviceCapability bitmask values describing capability of the
94 // Describes the state of a channel to a Cast receiver.
95 dictionary ChannelInfo
{
96 // Id for the channel.
99 // DEPRECATED: The URL to the receiver. This field will be removed in a
103 // Connection information that was used to establish the channel to the
105 ConnectInfo connectInfo
;
107 // The current state of the channel.
108 ReadyState readyState
;
110 // If set, the last error condition encountered by the channel.
111 ChannelError? errorState
;
113 // If true, keep-alive messages are handled automatically by the channel.
117 // Describes a message sent or received over the channel. Currently only
118 // string messages are supported, although ArrayBuffer and Blob types may be
119 // supported in the future.
120 dictionary MessageInfo
{
121 // The message namespace. A namespace is a URN of the form
122 // urn:cast-x:<namespace> that is used to interpret and route Cast messages.
123 DOMString namespace_
;
125 // source and destination ids identify the origin and destination of the
126 // message. They are used to route messages between endpoints that share a
127 // device-to-device channel.
129 // For messages between applications:
130 // - The sender application id is a unique identifier generated on behalf
131 // of the sender application.
132 // - The receiver id is always the the session id for the application.
134 // For messages to or from the sender or receiver platform, the special ids
135 // 'sender-0' and 'receiver-0' can be used.
137 // For messages intended for all endpoints using a given channel, the
138 // wildcard destination_id '*' can be used.
140 DOMString destinationId
;
142 // The content of the message. Must be either a string or an ArrayBuffer.
146 // Describes a terminal error encountered by the channel with details of the
147 // error that caused the channel to be closed. One or more of the optional
148 // fields may be set with specific error codes from the underlying
150 dictionary ErrorInfo
{
151 // The type of error encountered by the channel.
152 ChannelError errorState
;
154 // The event that was occurring when the error happened. Values are defined
155 // in the enum EventType in logging.proto.
158 // An error encountered when processing the authentication handshake.
159 // Values are defined in the enum ChallengeReplyErrorType in logging.proto.
160 long? challengeReplyErrorType
;
162 // A return value from the underlying net:: socket libraries. Values are
163 // defined in net/base/net_error_list.h.
164 long? netReturnValue
;
166 // An error code returned by NSS. Values are defined in secerr.h.
170 // Callback holding the result of a channel operation.
171 callback ChannelInfoCallback
= void (ChannelInfo result
);
173 // Callback from <code>getLogs</code> method.
174 // |log|: compressed serialized raw bytes containing the logs.
175 // The log is formatted using protocol buffer.
176 // See extensions/browser/api/cast_channel/logging.proto for definition.
177 // Compression is in gzip format.
178 callback GetLogsCallback
= void (ArrayBuffer log
);
180 // Callback from <code>setAuthorityKeys</code> method.
181 callback SetAuthorityKeysCallback
= void ();
183 interface Functions
{
184 // Opens a new channel to the Cast receiver specified by connectInfo. Only
185 // one channel may be connected to same receiver from the same extension at
186 // a time. If the open request is successful, the callback will be invoked
187 // with a ChannelInfo with readyState == 'connecting'. If unsuccessful, the
188 // callback will be invoked with a ChannelInfo with channel.readyState ==
189 // 'closed', channel.errorState will be set to the error condition, and
190 // onError will be fired with error details.
192 // TODO(mfoltz): Convert 'any' to ConnectInfo once all clients are updated
194 static
void open
(any connectInfo
,
195 ChannelInfoCallback
callback);
197 // Sends a message on the channel and invokes callback with the resulting
198 // channel status. The channel must be in readyState == 'open'. If
199 // unsuccessful, channel.readyState will be set to 'closed',
200 // channel.errorState will be set to the error condition, and onError will
201 // be fired with error details.
202 static
void send
(ChannelInfo channel
,
204 ChannelInfoCallback
callback);
206 // Requests that the channel be closed and invokes callback with the
207 // resulting channel status. The channel must be in readyState == 'open' or
208 // 'connecting'. If successful, onClose will be fired with readyState ==
209 // 'closed'. If unsuccessful, channel.readyState will be set to 'closed',
210 // and channel.errorState will be set to the error condition.
211 static
void close
(ChannelInfo channel
,
212 ChannelInfoCallback
callback);
214 // Get logs in compressed serialized format. See GetLogsCallback for
216 // |callback|: If successful, |callback| is invoked with data. Otherwise,
217 // an error will be raised.
218 static
void getLogs
(GetLogsCallback
callback);
220 // Sets trusted certificate authorities where |signature| is a base64
221 // encoded RSA-PSS signature and |keys| is base64 encoded AuthorityKeys
223 static
void setAuthorityKeys
(DOMString keys
,
225 SetAuthorityKeysCallback
callback);
228 // Events on the channel.
230 // Fired when a message is received on an open channel.
231 static
void onMessage
(ChannelInfo channel
,
232 MessageInfo
message);
234 // Fired when an error occurs as a result of a channel operation or a
235 // network event. |error| contains details of the error.
236 static
void onError
(ChannelInfo channel
, ErrorInfo error
);