OLD | NEW |
| (Empty) |
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. | |
4 | |
5 // Use the <code>chrome.copresenceEndpoints</code> API to create persistent | |
6 // sockets to send data to and receive from data nearby devices. | |
7 namespace copresenceEndpoints { | |
8 // Result of the <code>createEndpoint</code> call. | |
9 [noinline_doc] dictionary EndpointInfo { | |
10 // The ID of the newly created endpoint. | |
11 long endpointId; | |
12 | |
13 // An opaque string containing the locator data for this endpoint. This | |
14 // locator is needed to connect to this endpoint. | |
15 DOMString locator; | |
16 }; | |
17 | |
18 // Data from an <code>onReceive</code> event. | |
19 [noinline_doc] dictionary ReceiveInfo { | |
20 // The local endpoint this data is for. | |
21 long localEndpointId; | |
22 | |
23 // The remote endpoint this data came from. | |
24 long remoteEndpointId; | |
25 | |
26 // The data received. | |
27 ArrayBuffer data; | |
28 }; | |
29 | |
30 // Status of a socket operation. | |
31 enum EndpointStatus { | |
32 // There was no error in the previous operation. | |
33 no_error, | |
34 | |
35 // The socket was disconnected. | |
36 disconnected, | |
37 | |
38 // The local endpoint id provided is invalid. | |
39 invalid_local_endpoint, | |
40 | |
41 // The remote endpoint id provided is invalid. | |
42 invalid_remote_endpoint, | |
43 | |
44 // There was a failure during connection. | |
45 connect_failure, | |
46 | |
47 // There was an error while trying to send data. | |
48 send_failure, | |
49 | |
50 // There was an error while trying to receive data. | |
51 receive_failure | |
52 }; | |
53 | |
54 // Callback from the <code>createEndpoint</code> method. | |
55 // |endpointInfo| : The result of the endpoint creation. | |
56 callback CreateCallback = void (EndpointInfo endpointInfo); | |
57 | |
58 // Callback from the <code>send</code> method. | |
59 // |status| : Status of the send operation. | |
60 callback SendCallback = void (EndpointStatus status); | |
61 | |
62 // These functions all report failures via chrome.runtime.lastError. | |
63 interface Functions { | |
64 // Endpoint functions. | |
65 | |
66 // Creates a endpoint that can be connected to by a nearby devices. | |
67 // |callback| : Called when the endpoint has been created. | |
68 static void createLocalEndpoint(CreateCallback callback); | |
69 | |
70 // Destroys the endpoint. This will close any connections to this endpoint | |
71 // from remote hosts and will prevent any further connections to it. | |
72 // |endpointId|: Endpoint ID returned by <code>createEndpoint</code>. | |
73 static void destroyEndpoint(long endpointId); | |
74 | |
75 // Sends data from a local Copresence endpoint to a remote endpoint. | |
76 // |localEndpointId| : The local endpoint identifier. | |
77 // |remoteEndpointId| : The remote endpoint identifier. | |
78 // |data| : The data to send. | |
79 // |callback| : Called when the <code>send</code> operation completes. | |
80 static void send(long localEndpointId, long remoteEndpointId, | |
81 ArrayBuffer data, optional SendCallback callback); | |
82 }; | |
83 | |
84 interface Events { | |
85 // Event raised when data has been received for a given socket. | |
86 // |info| : The event data. | |
87 static void onReceive(ReceiveInfo info); | |
88 | |
89 // Event raised when a endpoint receives a new connection. A new socket is | |
90 // created and the id is passed to this event via socketId. | |
91 // |localEndpointId| : ID of the local endpoint that received this | |
92 // connection. | |
93 // TODO(rkc): This API needs to be modified to give a valid remote endpoint | |
94 // id also. This currently doesn't happen because of the lack of a | |
95 // handshake on a sockets connection. Once we have a handshake, modify this | |
96 // API to also return a remote endpoint id. | |
97 static void onConnected(long localEndpointId); | |
98 }; | |
99 }; | |
OLD | NEW |