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