Chromium Code Reviews| 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.copresence</code> API to communicate with other devices | |
|
Daniel Erat
2014/08/06 22:59:37
nit: "... to communicate with other nearby devices
rkc
2014/08/07 02:18:34
We don't use Copresence for branding (at least yet
| |
| 6 // close by, using Google's copresence service. | |
| 7 namespace copresence { | |
| 8 // Suggestions to copresence on how to do the publication and subscription. | |
| 9 // Note: These are only suggestions. Actual behavior may not always match | |
| 10 // what is requested. | |
| 11 dictionary Strategy { | |
| 12 // Attempt to use low power mode. Defaults to false. | |
| 13 boolean? lowPower; | |
| 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. | |
| 19 boolean? onlyScan; | |
| 20 // Attempt to use audible audio. Defaults to false. | |
| 21 boolean? audible; | |
| 22 }; | |
| 23 | |
| 24 dictionary Message { | |
| 25 // The type of message that we're publishing. Cannot be empty. | |
|
Daniel Erat
2014/08/06 22:59:38
nit: s/that we're publishing/being published/
rkc
2014/08/07 02:18:34
Done.
| |
| 26 DOMString type; | |
| 27 // The message payload, in raw bytes. | |
| 28 ArrayBuffer payload; | |
| 29 }; | |
| 30 | |
| 31 dictionary MessageFilter { | |
| 32 // The type of messages to subscribe to. Cannot be empty. | |
| 33 DOMString type; | |
| 34 }; | |
| 35 | |
| 36 [noinline_doc] dictionary AccessPolicy { | |
| 37 // Only send this message to people within hearing range. | |
|
Daniel Erat
2014/08/06 22:59:38
nit: s/people/devices/
rkc
2014/08/07 02:18:34
Done.
| |
| 38 // Defaults to false. | |
| 39 boolean? onlyEarshot; | |
| 40 }; | |
| 41 | |
| 42 [noinline_doc] dictionary PublishOperation { | |
| 43 // A unique ID that identifies this publish. | |
| 44 DOMString id; | |
| 45 // The message to publish. | |
| 46 Message message; | |
| 47 // The number of milliseconds for which this publication will be active. | |
| 48 // This is capped at 24 hours. If not provided, we default to 5 minutes. | |
|
Daniel Erat
2014/08/06 22:59:37
nit: s/we default to 5 minutes/a default of 5 minu
rkc
2014/08/07 02:18:34
Done.
| |
| 49 long? timeToLiveMillis; | |
| 50 // A policy specifying who can get the message. | |
| 51 AccessPolicy? policy; | |
| 52 // A set of strategies to use when publishing the message. These | |
| 53 // strategies are suggestions to copresence that may or may not be followed. | |
| 54 Strategy? strategies; | |
| 55 }; | |
| 56 | |
| 57 [noinline_doc] dictionary SubscribeOperation { | |
| 58 // A unique ID that identifies this subscription. | |
| 59 DOMString id; | |
| 60 // Filter that defines which messages we want to subscribe to. | |
| 61 MessageFilter filter; | |
| 62 // The number of milliseconds for which this subscription will be active. | |
| 63 // This is capped at 24 hours. If not provided, we default to 5 minutes. | |
|
Daniel Erat
2014/08/06 22:59:38
nit: s/we default to 5 minutes/a default of 5 minu
rkc
2014/08/07 02:18:34
Done.
| |
| 64 long? timeToLiveMillis; | |
| 65 // A set of strategies to use when subscribing with this filter. These | |
| 66 // strategies are suggestions to copresence that may or may not be followed. | |
| 67 Strategy? strategies; | |
| 68 }; | |
| 69 | |
| 70 [noinline_doc] dictionary UnpublishOperation { | |
| 71 // The id of a message to unpublish. Required if the operation type | |
|
Daniel Erat
2014/08/06 22:59:37
nit: s/id/ID/ here and elsewhere in this file
rkc
2014/08/07 02:18:34
Done.
| |
| 72 // is 'unpublish'. | |
| 73 DOMString unpublishId; | |
| 74 }; | |
| 75 | |
| 76 [noinline_doc] dictionary UnsubscribeOperation { | |
| 77 // The id of a subscription to cancel. Required if the operation type | |
| 78 // is 'unsubscribe'. | |
| 79 DOMString unsubscribeId; | |
| 80 }; | |
| 81 | |
| 82 // Only one of these can be set. | |
| 83 [noinline_doc] dictionary Operation { | |
| 84 // Publication details. Required if the operation type is 'publish'. | |
| 85 PublishOperation? publish; | |
| 86 // Subscription details. Required if the operation type is 'subscribe'. | |
| 87 SubscribeOperation? subscribe; | |
| 88 // Unpublish details. Required if the operation type is 'unpublish'. | |
| 89 UnpublishOperation? unpublish; | |
| 90 // Unsubscribe details. Required if the operation type is 'unsubscribe'. | |
| 91 UnsubscribeOperation? unsubscribe; | |
| 92 }; | |
| 93 | |
| 94 // Indicates whether a batchExecute() call succeeded or encountered errors. | |
| 95 enum ExecuteStatus { | |
| 96 // All operations sent to batchExecute succeeded. | |
| 97 success, | |
| 98 // One of the operations sent to batchExecute failed. | |
| 99 failed, | |
| 100 // Contacting the Copresence server failed. | |
| 101 serverError, | |
| 102 // Initializing Copresence failed. | |
| 103 initFailed | |
| 104 }; | |
| 105 | |
| 106 // Specifies an asynchronous status event sent to the app. | |
| 107 enum Status { | |
| 108 // We attempted to broadcast audio but weren't able to. | |
| 109 audioFailed, | |
| 110 // Contacting the Copresence server failed. | |
| 111 serverError | |
| 112 }; | |
| 113 | |
| 114 // Callback to return the status of a completed batchExecute() call. | |
| 115 callback ExecuteCallback = void(ExecuteStatus status); | |
| 116 | |
| 117 interface Functions { | |
| 118 // Sets the API key to use with our app. This parameter only needs to be | |
|
Daniel Erat
2014/08/06 22:59:37
nit: s/our app/the app/
rkc
2014/08/07 02:18:34
Done.
| |
| 119 // set if we need to communicate with apps on other platforms. Once we set | |
|
Daniel Erat
2014/08/06 22:59:38
nit: "set to communicate with apps on other platfo
rkc
2014/08/07 02:18:34
Done.
| |
| 120 // the api key, apps on any platform that are using this API key can | |
|
Daniel Erat
2014/08/06 22:59:37
nit: s/api/API/, also change to "Once the API key
rkc
2014/08/07 02:18:34
Done.
| |
| 121 // publish/subscribe to each other. | |
| 122 static void setApiKey(DOMString apiKey); | |
| 123 | |
| 124 // Executes a set of copresence operations in one batch. They will either | |
| 125 // all be executed, or none will be executed (due to an error in one or | |
| 126 // more of them). Publish/Subscribe operations are executed in the order | |
| 127 // that they exist in the array. Unpublish and Unsubscribe are processsed | |
| 128 // at the end, again, in the order that they exist in the array. | |
| 129 static void execute(Operation[] operations, ExecuteCallback callback); | |
| 130 }; | |
| 131 | |
| 132 interface Events { | |
| 133 // Fired when new messages arrive. | |
| 134 static void onMessagesReceived(DOMString subscriptionId, | |
| 135 Message[] messages); | |
| 136 | |
| 137 // Fired when we have a new status update for copresence. | |
|
Daniel Erat
2014/08/06 22:59:37
nit: Fired when a new Copresence status update is
rkc
2014/08/07 02:18:34
Done.
| |
| 138 static void onStatusUpdated(Status status); | |
| 139 }; | |
| 140 }; | |
| 141 | |
| OLD | NEW |