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 /** |
| 6 * @fileoverview |
| 7 * REST API for host-list management. |
| 8 */ |
| 9 |
| 10 /** @suppress {duplicate} */ |
| 11 var remoting = remoting || {}; |
| 12 |
| 13 (function() { |
| 14 |
| 15 'use strict'; |
| 16 |
| 17 /** |
| 18 * @constructor |
| 19 * @implements {remoting.HostListApi} |
| 20 */ |
| 21 remoting.HostListApiGcdImpl = function() { |
| 22 this.gcd_ = new remoting.gcd.Client({ |
| 23 apiKey: remoting.settings.GOOGLE_API_KEY |
| 24 }); |
| 25 }; |
| 26 |
| 27 /** @override */ |
| 28 remoting.HostListApiGcdImpl.prototype.register = function( |
| 29 newHostId, hostName, publicKey, hostClientId) { |
| 30 var self = this; |
| 31 var deviceDraft = { |
| 32 channel: { |
| 33 supportedType: 'xmpp' |
| 34 }, |
| 35 deviceKind: 'vendor', |
| 36 name: newHostId, |
| 37 displayName: hostName, |
| 38 state: { |
| 39 'publicKey': publicKey |
| 40 } |
| 41 }; |
| 42 |
| 43 return /** @type {!Promise<string>} */ ( |
| 44 this.gcd_.insertRegistrationTicket(). |
| 45 then(function(ticket) { |
| 46 return self.gcd_.patchRegistrationTicket( |
| 47 ticket.id, deviceDraft, hostClientId); |
| 48 }). |
| 49 then(function(/**remoting.gcd.RegistrationTicket*/ ticket) { |
| 50 return self.gcd_.finalizeRegistrationTicket(ticket.id); |
| 51 }). |
| 52 then(function(/**remoting.gcd.RegistrationTicket*/ ticket) { |
| 53 return ticket.robotAccountAuthorizationCode; |
| 54 }). |
| 55 catch(function(error) { |
| 56 console.error('Error registering device with GCD: ' + error); |
| 57 throw new remoting.Error(remoting.Error.Tag.REGISTRATION_FAILED); |
| 58 })); |
| 59 }; |
| 60 |
| 61 /** @override */ |
| 62 remoting.HostListApiGcdImpl.prototype.get = function() { |
| 63 // TODO(jrw) |
| 64 this.gcd_.listDevices(); |
| 65 return Promise.resolve([]); |
| 66 }; |
| 67 |
| 68 /** @override */ |
| 69 remoting.HostListApiGcdImpl.prototype.put = |
| 70 function(hostId, hostName, hostPublicKey) { |
| 71 // TODO(jrw) |
| 72 throw new Error('Not implemented'); |
| 73 }; |
| 74 |
| 75 /** @override */ |
| 76 remoting.HostListApiGcdImpl.prototype.remove = function(hostId) { |
| 77 // TODO(jrw) |
| 78 throw new Error('Not implemented'); |
| 79 }; |
| 80 |
| 81 })(); |
OLD | NEW |