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 // Use the <code>chrome.copresence</code> API to communicate with other nearby
6 // devices using Google's copresence service.
8 // Suggestions to copresence on how to do the publication and subscription.
9 // Note: These are only suggestions. Actual behavior may not always match
12 // Attempt to use low power mode. Defaults to false.
14 // Attempt to only broadcast. Using this with onlyScan can result in both
15 // being ignored. Defaults to false.
16 boolean? onlyBroadcast
;
17 // Attempt to only scan. Using this with onlyBroadcast can result in both
18 // being ignored. Defaults to false.
20 // Attempt to use audible audio. Defaults to false.
25 // The type of message being published. Cannot be empty.
27 // The message payload, in raw bytes.
31 dictionary MessageFilter
{
32 // The type of messages to subscribe to. Cannot be empty.
36 [noinline_doc
] dictionary AccessPolicy
{
37 // Only send this message to devices within hearing range.
42 [noinline_doc
] dictionary PublishOperation
{
43 // A unique ID that identifies this publish.
45 // The message to publish.
47 // The number of milliseconds for which this publication will be active.
48 // This is capped at 24 hours. If not provided, a default of 5 minutes is
50 long? timeToLiveMillis
;
51 // A policy specifying who can get the message.
53 // A set of strategies to use when publishing the message. These
54 // strategies are suggestions to copresence that may or may not be followed.
58 [noinline_doc
] dictionary SubscribeOperation
{
59 // A unique ID that identifies this subscription.
61 // Filter that defines which messages we want to subscribe to.
63 // The number of milliseconds for which this subscription will be active.
64 // This is capped at 24 hours. If not provided, a default of 5 minutes is
66 long? timeToLiveMillis
;
67 // A set of strategies to use when subscribing with this filter. These
68 // strategies are suggestions to copresence that may or may not be followed.
72 [noinline_doc
] dictionary UnpublishOperation
{
73 // The ID of a message to unpublish. Required if the operation type
75 DOMString unpublishId
;
78 [noinline_doc
] dictionary UnsubscribeOperation
{
79 // The ID of a subscription to cancel. Required if the operation type
81 DOMString unsubscribeId
;
84 // Only one of these can be set.
85 [noinline_doc
] dictionary Operation
{
86 // Publication details. Required if the operation type is 'publish'.
87 PublishOperation? publish
;
88 // Subscription details. Required if the operation type is 'subscribe'.
89 SubscribeOperation? subscribe
;
90 // Unpublish details. Required if the operation type is 'unpublish'.
91 UnpublishOperation? unpublish
;
92 // Unsubscribe details. Required if the operation type is 'unsubscribe'.
93 UnsubscribeOperation? unsubscribe
;
96 // Indicates whether a batchExecute() call succeeded or encountered errors.
98 // All operations sent to batchExecute succeeded.
100 // One of the operations sent to batchExecute failed.
102 // Contacting the Copresence server failed.
104 // Initializing Copresence failed.
108 // Specifies an asynchronous status event sent to the app.
110 // We attempted to broadcast audio but weren't able to.
112 // Contacting the Copresence server failed.
116 // Callback to return the status of a completed batchExecute() call.
117 callback ExecuteCallback
= void(ExecuteStatus status
);
119 interface Functions
{
120 // Sets the API key to use with the app. This parameter only needs to be
121 // set to communicate with apps on other platforms. Once the API key is set,
122 // apps on any platform that are using this API key can publish/subscribe to
124 [nodoc
] static
void setApiKey
(DOMString apiKey
);
126 // Temporary call to enable authenticated copresence
127 // with an externally provided OAuth token.
128 // TODO(ckehoe): Replace this with a proper API.
129 [nodoc
] static
void setAuthToken
(DOMString token
);
131 // Executes a set of copresence operations in one batch. They will either
132 // all be executed, or none will be executed (due to an error in one or
133 // more of them). Publish/Subscribe operations are executed in the order
134 // that they exist in the array. Unpublish and Unsubscribe are processsed
135 // at the end, again, in the order that they exist in the array.
136 static
void execute
(Operation
[] operations
, ExecuteCallback
callback);
140 // Fired when new messages arrive.
141 static
void onMessagesReceived
(DOMString subscriptionId
,
144 // Fired when a new copresence status update is available.
145 static
void onStatusUpdated
(Status status
);