File: bluetooth_socket.webidl

package info (click to toggle)
chromium 145.0.7632.159-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,976,224 kB
  • sloc: cpp: 36,198,469; ansic: 7,634,080; javascript: 3,564,060; python: 1,649,622; xml: 838,470; asm: 717,087; pascal: 185,708; sh: 88,786; perl: 88,718; objc: 79,984; sql: 59,811; cs: 42,452; fortran: 24,101; makefile: 21,144; tcl: 15,277; php: 14,022; yacc: 9,066; ruby: 7,553; awk: 3,720; lisp: 3,233; lex: 1,328; ada: 727; jsp: 228; sed: 36
file content (307 lines) | stat: -rw-r--r-- 11,802 bytes parent folder | download | duplicates (6)
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

dictionary SocketProperties {
  // Flag indicating whether the socket is left open when the event page of
  // the application is unloaded (see <a
  // href="http://developer.chrome.com/apps/app_lifecycle.html">Manage App
  // Lifecycle</a>). The default value is <code>false.</code> When the
  // application is loaded, any sockets previously opened with persistent=true
  // can be fetched with $ref:getSockets.
  boolean persistent;

  // An application-defined string associated with the socket.
  DOMString? name;

  // The size of the buffer used to receive data. The default value is 4096.
  long? bufferSize;
};

dictionary CreateInfo {
  // The ID of the newly created socket. Note that socket IDs created
  // from this API are not compatible with socket IDs created from other APIs,
  // such as the <code>$(ref:sockets.tcp)</code> API.
  required long socketId;
};

// Options that may be passed to the <code>listenUsingRfcomm</code> and
// <code>listenUsingL2cap</code> methods. Each property is optional with a
// default being used if not specified.
dictionary ListenOptions {
  // The RFCOMM Channel used by <code>listenUsingRfcomm</code>. If specified,
  // this channel must not be previously in use or the method call will fail.
  // When not specified, an unused channel will be automatically allocated.
  long? channel;

  // The L2CAP PSM used by <code>listenUsingL2cap</code>. If specified, this
  // PSM must not be previously in use or the method call with fail. When
  // not specified, an unused PSM will be automatically allocated.
  long? psm;

  // Length of the socket's listen queue. The default value depends on the
  // operating system's host subsystem.
  long? backlog;
};

dictionary SocketInfo {
  // The socket identifier.
  required long socketId;

  // Flag indicating if the socket remains open when the event page of the
  // application is unloaded (see <code>SocketProperties.persistent</code>).
  // The default value is "false".
  required boolean persistent;

  // Application-defined string associated with the socket.
  DOMString? name;

  // The size of the buffer used to receive data. If no buffer size has been
  // specified explictly, the value is not provided.
  long? bufferSize;

  // Flag indicating whether a connected socket blocks its peer from sending
  // more data, or whether connection requests on a listening socket are
  // dispatched through the <code>onAccept</code> event or queued up in the
  // listen queue backlog.
  // See <code>setPaused</code>. The default value is "false".
  required boolean paused;

  // Flag indicating whether the socket is connected to a remote peer.
  required boolean connected;

  // If the underlying socket is connected, contains the Bluetooth address of
  // the device it is connected to.
  DOMString? address;

  // If the underlying socket is connected, contains information about the
  // service UUID it is connected to, otherwise if the underlying socket is
  // listening, contains information about the service UUID it is listening
  // on.
  DOMString? uuid;
};

dictionary AcceptInfo {
  // The server socket identifier.
  required long socketId;

  // The client socket identifier, i.e. the socket identifier of the newly
  // established connection. This socket identifier should be used only with
  // functions from the <code>chrome.bluetoothSocket</code> namespace. Note
  // the client socket is initially paused and must be explictly un-paused by
  // the application to start receiving data.
  required long clientSocketId;
};

enum AcceptError {
  // A system error occurred and the connection may be unrecoverable.
  "system_error",

  // The socket is not listening.
  "not_listening"
};

dictionary AcceptErrorInfo {
  // The server socket identifier.
  required long socketId;

  // The error message.
  required DOMString errorMessage;

  // An error code indicating what went wrong.
  required AcceptError error;
};

dictionary ReceiveInfo {
  // The socket identifier.
  required long socketId;

  // The data received, with a maxium size of <code>bufferSize</code>.
  required ArrayBuffer data;
};

enum ReceiveError {
  // The connection was disconnected.
  "disconnected",

  // A system error occurred and the connection may be unrecoverable.
  "system_error",

  // The socket has not been connected.
  "not_connected"
};

dictionary ReceiveErrorInfo {
  // The socket identifier.
  required long socketId;

  // The error message.
  required DOMString errorMessage;

  // An error code indicating what went wrong.
  required ReceiveError error;
};

// |info| : The event data.
callback OnAcceptListener = undefined (AcceptInfo info);

interface OnAcceptEvent : ExtensionEvent {
  static undefined addListener(OnAcceptListener listener);
  static undefined removeListener(OnAcceptListener listener);
  static boolean hasListener(OnAcceptListener listener);
};

// |info| : The event data.
callback OnAcceptErrorListener = undefined (AcceptErrorInfo info);

interface OnAcceptErrorEvent : ExtensionEvent {
  static undefined addListener(OnAcceptErrorListener listener);
  static undefined removeListener(OnAcceptErrorListener listener);
  static boolean hasListener(OnAcceptErrorListener listener);
};

// |info| : The event data.
callback OnReceiveListener = undefined (ReceiveInfo info);

interface OnReceiveEvent : ExtensionEvent {
  static undefined addListener(OnReceiveListener listener);
  static undefined removeListener(OnReceiveListener listener);
  static boolean hasListener(OnReceiveListener listener);
};

// |info| : The event data.
callback OnReceiveErrorListener = undefined (ReceiveErrorInfo info);

interface OnReceiveErrorEvent : ExtensionEvent {
  static undefined addListener(OnReceiveErrorListener listener);
  static undefined removeListener(OnReceiveErrorListener listener);
  static boolean hasListener(OnReceiveErrorListener listener);
};

// Use the <code>chrome.bluetoothSocket</code> API to send and receive data
// to Bluetooth devices using RFCOMM and L2CAP connections.
interface BluetoothSocket {
  // Creates a Bluetooth socket.
  // |properties| : The socket properties (optional).
  // |Returns|: Called when the socket has been created.
  // |PromiseValue|: createInfo: The result of the socket creation.
  [requiredCallback] static Promise<CreateInfo> create(
      optional SocketProperties properties);

  // Updates the socket properties.
  // |socketId| : The socket identifier.
  // |properties| : The properties to update.
  // |Returns|: Called when the properties are updated.
  static Promise<undefined> update(
      long socketId,
      SocketProperties properties);

  // Enables or disables a connected socket from receiving messages from its
  // peer, or a listening socket from accepting new connections. The default
  // value is "false". Pausing a connected socket is typically used by an
  // application to throttle data sent by its peer. When a connected socket
  // is paused, no <code>onReceive</code>event is raised. When a socket is
  // connected and un-paused, <code>onReceive</code> events are raised again
  // when messages are received. When a listening socket is paused, new
  // connections are accepted until its backlog is full then additional
  // connection requests are refused. <code>onAccept</code> events are raised
  // only when the socket is un-paused.
  // |Returns|: Callback from the <code>setPaused</code> method.
  static Promise<undefined> setPaused(
      long socketId,
      boolean paused);

  // Listen for connections using the RFCOMM protocol.
  // |socketId| : The socket identifier.
  // |uuid| : Service UUID to listen on.
  // |options| : Optional additional options for the service.
  // |Returns|: Called when listen operation completes.
  [requiredCallback] static Promise<undefined> listenUsingRfcomm(
      long socketId,
      DOMString uuid,
      optional ListenOptions options);

  // Listen for connections using the L2CAP protocol.
  // |socketId| : The socket identifier.
  // |uuid| : Service UUID to listen on.
  // |options| : Optional additional options for the service.
  // |Returns|: Called when listen operation completes.
  [requiredCallback] static Promise<undefined> listenUsingL2cap(
      long socketId,
      DOMString uuid,
      optional ListenOptions options);

  // Connects the socket to a remote Bluetooth device. When the
  // <code>connect</code> operation completes successfully,
  // <code>onReceive</code> events are raised when data is received from the
  // peer. If a network error occur while the runtime is receiving packets,
  // a <code>onReceiveError</code> event is raised, at which point no more
  // <code>onReceive</code> event will be raised for this socket until the
  // <code>setPaused(false)</code> method is called.
  // |socketId| : The socket identifier.
  // |address| : The address of the Bluetooth device.
  // |uuid| : The UUID of the service to connect to.
  // |Returns|: Called when the connect attempt is complete.
  [requiredCallback] static Promise<undefined> connect(
      long socketId,
      DOMString address,
      DOMString uuid);

  // Disconnects the socket. The socket identifier remains valid.
  // |socketId| : The socket identifier.
  // |Returns|: Called when the disconnect attempt is complete.
  static Promise<undefined> disconnect(
      long socketId);

  // Disconnects and destroys the socket. Each socket created should be
  // closed after use. The socket id is no longer valid as soon at the
  // function is called. However, the socket is guaranteed to be closed only
  // when the callback is invoked.
  // |socketId| : The socket identifier.
  // |Returns|: Called when the <code>close</code> operation completes.
  static Promise<undefined> close(
      long socketId);

  // Sends data on the given Bluetooth socket.
  // |socketId| : The socket identifier.
  // |data| : The data to send.
  // |Returns|: Called with the number of bytes sent.
  // |PromiseValue|: bytesSent: The number of bytes sent.
  static Promise<long> send(
      long socketId,
      ArrayBuffer data);

  // Retrieves the state of the given socket.
  // |socketId| : The socket identifier.
  // |Returns|: Called when the socket state is available.
  // |PromiseValue|: socketInfo: Object containing the socket information.
  [requiredCallback] static Promise<SocketInfo> getInfo(
      long socketId);

  // Retrieves the list of currently opened sockets owned by the application.
  // |Returns|: Called when the list of sockets is available.
  // |PromiseValue|: sockets: Array of object containing socket information.
  [requiredCallback] static Promise<sequence<SocketInfo>> getSockets();

  // Event raised when a connection has been established for a given socket.
  static attribute OnAcceptEvent onAccept;

  // Event raised when a network error occurred while the runtime was waiting
  // for new connections on the given socket. Once this event is raised, the
  // socket is set to <code>paused</code> and no more <code>onAccept</code>
  // events are raised for this socket.
  static attribute OnAcceptErrorEvent onAcceptError;

  // Event raised when data has been received for a given socket.
  static attribute OnReceiveEvent onReceive;

  // Event raised when a network error occured while the runtime was waiting
  // for data on the socket. Once this event is raised, the socket is set to
  // <code>paused</code> and no more <code>onReceive</code> events are raised
  // for this socket.
  static attribute OnReceiveErrorEvent onReceiveError;
};

partial interface Browser {
  static attribute BluetoothSocket bluetoothSocket;
};