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.
7 tvcm.require('ui.spy');
8 tvcm.require('tvcm.ui');
9 tvcm.require('tvcm.ui.dom_helpers');
10 tvcm.requireTemplate('ui.spy_shell');
12 tvcm.exportTo('ui', function() {
16 var SpyShell = tvcm.ui.define('x-spy-shell');
18 SpyShell.prototype = {
19 __proto__: HTMLUnknownElement.prototype,
21 decorate: function(socketURL) {
22 var node = tvcm.instantiateTemplate('#x-spy-shell-template');
23 this.appendChild(node);
25 this.socketURL_ = socketURL;
26 this.conn_ = undefined;
28 this.statusEl_ = this.querySelector('#status');
29 this.statusEl_.textContent = 'Not connected';
31 this.spy_ = this.querySelector('x-spy');
32 tvcm.ui.decorate(this.spy_, ui.Spy);
34 this.openConnection_();
38 return this.socketURL_;
41 openConnection_: function() {
42 if (!(this.conn_ == undefined ||
43 this.conn_.readyState === undefined ||
44 conn.readyState > 1)) {
48 this.conn_ = new WebSocket(this.socketURL_);
49 this.conn_.onopen = function() {
50 this.statusEl_.textContent = 'connected at ' + this.socketURL_;
51 this.spy_.connection = this.conn_;
54 this.conn_.onclose = function(event) {
55 this.statusEl_.textContent = 'connection closed';
56 this.spy_.connection = undefined;
58 this.conn_.onerror = function(event) {
59 this.statusEl_.innerHTML = 'got error';