Browse Source

Fixes for upstream API changes

Andy Hochhaus 3 years ago
parent
commit
a7222ab1e9
5 changed files with 225 additions and 247 deletions
  1. 11 41
      Makefile
  2. 173 172
      gen/compiled.js
  3. 3 3
      uncompiled_deps.js
  4. 4 4
      wcchat.go
  5. 34 27
      wcchat.js

+ 11 - 41
Makefile

@@ -11,50 +11,20 @@ all: gen/compiled.js
 
 gen/compiled.js: $(JS)
 	java -jar $(CLOSURE_COMPILER_JAR) \
-	  --js=**.js \
-	  --js=$(DEPS)/closure-library/closure/goog \
-	  --closure_entry_point="wcchat.App" \
-	  --only_closure_dependencies \
-	  --compilation_level=ADVANCED_OPTIMIZATIONS \
+	  --js=wcchat.js \
+	  --js=$(DEPS)/closure-library/closure/goog/ \
+	  --js=!$(DEPS)/closure-library/closure/goog/**/*_test.js \
+	  --dependency_mode=LOOSE \
+	  --entry_point="wcchat.App" \
+	  --compilation_level=ADVANCED \
 	  --define=goog.DEBUG=false \
-	  --define=goog.json.USE_NATIVE_JSON=true \
-	  --jscomp_error=accessControls \
-	  --jscomp_error=ambiguousFunctionDecl \
-	  --jscomp_error=checkDebuggerStatement \
-	  --jscomp_error=checkEventfulObjectDisposal \
-	  --jscomp_error=checkRegExp \
-	  --jscomp_error=checkStructDictInheritance \
-	  --jscomp_error=checkTypes \
-	  --jscomp_error=checkVars \
-	  --jscomp_error=const \
-	  --jscomp_error=constantProperty \
-	  --jscomp_error=deprecated \
-	  --jscomp_error=duplicate \
-	  --jscomp_error=duplicateMessage \
-	  --jscomp_error=es3 \
-	  --jscomp_error=es5Strict \
-	  --jscomp_error=externsValidation \
-	  --jscomp_error=fileoverviewTags \
-	  --jscomp_error=globalThis \
-	  --jscomp_error=internetExplorerChecks \
-	  --jscomp_error=invalidCasts \
-	  --jscomp_error=misplacedTypeAnnotation \
-	  --jscomp_error=missingProperties \
-	  --jscomp_error=missingProvide \
-	  --jscomp_error=missingRequire \
-	  --jscomp_error=missingReturn \
-	  --jscomp_error=nonStandardJsDocs \
-	  --jscomp_error=strictModuleDepCheck \
-	  --jscomp_error=suspiciousCode \
-	  --jscomp_error=typeInvalidation \
-	  --jscomp_error=undefinedNames \
-	  --jscomp_error=undefinedVars \
-	  --jscomp_error=unknownDefines \
-	  --jscomp_error=uselessCode \
-	  --jscomp_error=visibility \
+	  --define=goog.json.USE_NATIVE_JSON \
+	  --jscomp_error=* \
+	  --hide_warnings_for=$(DEPS) \
 	  --language_in=ECMASCRIPT5_STRICT \
 	  --output_wrapper="(function(){%output%}).call(this);" \
 	  --use_types_for_optimization \
+	  --new_type_inf \
 	  --warning_level=VERBOSE \
 	  --js_output_file=gen/compiled.js
 
@@ -68,4 +38,4 @@ lint:
 	  --jslint_error=all {}
 
 clean:
-	rm gen/compiled.js
+	rm -f gen/compiled.js

File diff suppressed because it is too large
+ 173 - 172
gen/compiled.js


+ 3 - 3
uncompiled_deps.js

@@ -16,12 +16,12 @@
  */
 
 goog.require('goog.dom.ViewportSizeMonitor');
-goog.require('goog.net.createWebChannelTransport');
-goog.require('goog.net.WebChannelTransport');
-goog.require('goog.net.WebChannel');
 goog.require('goog.labs.net.webChannel.ConnectionState');
 goog.require('goog.labs.net.webChannel.WebChannelBase');
 goog.require('goog.labs.net.webChannel.WebChannelBaseTransport');
+goog.require('goog.net.WebChannel');
+goog.require('goog.net.WebChannelTransport');
+goog.require('goog.net.createWebChannelTransport');
 goog.require('goog.ui.Container');
 goog.require('goog.ui.FlatButtonRenderer');
 goog.require('goog.ui.Prompt');

+ 4 - 4
wcchat.go

@@ -19,7 +19,7 @@ import (
 	"strings"
 	"sync"
 
-	"gopkg.in/samegoal/wc.v0"
+	"github.com/samegoal/wc"
 )
 
 var (
@@ -110,8 +110,8 @@ type chatSession struct {
 	user     string
 }
 
-func newChatSession() *chatSession {
-	return &chatSession{DefaultSession: wc.NewDefaultSession(newSID())}
+func newChatSession(r *http.Request) *chatSession {
+	return &chatSession{DefaultSession: wc.NewDefaultSession(r, newSID())}
 }
 
 func (s *chatSession) Authenticated(r *http.Request) bool {
@@ -229,7 +229,7 @@ func (sm *chatSessionManager) NewSession(r *http.Request) (
 ) {
 	sm.mutex.Lock()
 	defer sm.mutex.Unlock()
-	s := newChatSession()
+	s := newChatSession(r)
 	sm.sessionMap[s.SID()] = s
 	return s, nil
 }

+ 34 - 27
wcchat.js

@@ -17,6 +17,7 @@ goog.provide('wcchat.App');
 
 goog.require('goog.Disposable');
 goog.require('goog.Uri');
+goog.require('goog.asserts');
 goog.require('goog.dom');
 goog.require('goog.dom.ViewportSizeMonitor');
 goog.require('goog.events');
@@ -71,12 +72,9 @@ if (wcchat.SKIP_HOSTPREFIX_CHECK) {
    * Set connection state to minimize the number of round trips to the server
    * when opening new connections.
    * @param {!goog.labs.net.webChannel.ConnectionState} conn_state
-   * @suppress {missingProvide}
+   * @suppress {missingProvide|unusedPrivateMembers}
    */
   WebChannelBase.prototype.setConnectionState = function(conn_state) {
-    /**
-     * @suppress {unusedPrivateMembers}
-     */
     this.ConnState_ = conn_state;
   };
 }
@@ -102,7 +100,7 @@ if (wcchat.SELFHOST_CLEARDOT) {
  * @extends {goog.Disposable}
  */
 wcchat.App = function() {
-  goog.base(this);
+  wcchat.App.base(this, 'constructor');
 };
 goog.inherits(wcchat.App, goog.Disposable);
 
@@ -112,19 +110,19 @@ goog.inherits(wcchat.App, goog.Disposable);
  */
 wcchat.App.prototype.launch = function() {
   /**
-   * @private {goog.ui.Container}
+   * @private {!goog.ui.Container}
    */
   this.userList_ = new goog.ui.Container();
 
 
   /**
-   * @private {goog.ui.Component}
+   * @private {!goog.ui.Component}
    */
   this.chatUi_ = new goog.ui.Component();
 
 
   /**
-   * @private {goog.ui.Textarea}
+   * @private {!goog.ui.Textarea}
    */
   this.textArea_ = new goog.ui.Textarea('');
   this.textArea_.setMinHeight(50);
@@ -132,7 +130,7 @@ wcchat.App.prototype.launch = function() {
   this.chatUi_.addChild(this.textArea_, true);
 
   /**
-   * @private {goog.events.KeyHandler}
+   * @private {!goog.events.KeyHandler}
    */
   this.keyHandler_ = new goog.events.KeyHandler(this.textArea_.getElement());
   goog.events.listen(this.keyHandler_,
@@ -143,7 +141,7 @@ wcchat.App.prototype.launch = function() {
 
 
   /**
-   * @private {goog.ui.Button}
+   * @private {!goog.ui.Button}
    */
   this.sendButton_ = new goog.ui.Button(
       'Send', goog.ui.FlatButtonRenderer.getInstance());
@@ -151,7 +149,7 @@ wcchat.App.prototype.launch = function() {
 
 
   /**
-   * @private {goog.ui.Button}
+   * @private {!goog.ui.Button}
    */
   this.disconnectButton_ = new goog.ui.Button(
       'Disconnect', goog.ui.FlatButtonRenderer.getInstance());
@@ -159,14 +157,14 @@ wcchat.App.prototype.launch = function() {
 
 
   /**
-   * @private {goog.ui.Component}
+   * @private {!goog.ui.Component}
    */
   this.chatConsole_ = new goog.ui.Component();
   this.chatUi_.addChild(this.chatConsole_, true);
 
 
   /**
-   * @private {goog.ui.SplitPane}
+   * @private {!goog.ui.SplitPane}
    */
   this.splitpane_ = new goog.ui.SplitPane(
       this.userList_, this.chatUi_, goog.ui.SplitPane.Orientation.HORIZONTAL);
@@ -179,8 +177,12 @@ wcchat.App.prototype.launch = function() {
                      this.disconnect_,
                      undefined,
                      this);
-  this.chatConsole_.getElement().innerHTML +=
-      '<div id=\"chatPane\" width=\"100%\"></div>';
+  /**
+   * @private {!Element}
+   */
+  this.chatConsoleEl_ = /** @type {!Element} */ (
+    this.chatConsole_.getElement());
+  this.chatConsoleEl_.innerHTML += '<div id=\"chatPane\" width=\"100%\"></div>';
   goog.events.listen(this.sendButton_,
                      goog.ui.Component.EventType.ACTION,
                      this.send_,
@@ -188,7 +190,7 @@ wcchat.App.prototype.launch = function() {
                      this);
 
   /**
-   * @private {goog.dom.ViewportSizeMonitor}
+   * @private {!goog.dom.ViewportSizeMonitor}
    */
   this.viewportSizeMonitor_ = new goog.dom.ViewportSizeMonitor();
   goog.events.listen(this.viewportSizeMonitor_,
@@ -211,12 +213,12 @@ wcchat.App.prototype.launch = function() {
   this.channel_ = this.channelTransport_.createWebChannel('/channel', options);
 
   if (wcchat.SKIP_HOSTPREFIX_CHECK) {
-    var channelBase = /** @type {goog.labs.net.webChannel.
+    var channelBase = /** @type {!goog.labs.net.webChannel.
         WebChannelBaseTransport.Channel} */ (this.channel_).
         getWebChannelBase();
 
     var connectionState = new goog.labs.net.webChannel.ConnectionState();
-    connectionState.handshakeResult = [null];  // hostPrefix
+    connectionState.handshakeResult = [];  // hostPrefix
     // Note: blockedPrefix is not supported by WebChannel
 
     channelBase.setConnectionState(connectionState);
@@ -247,7 +249,8 @@ wcchat.App.prototype.launch = function() {
  * @private
  */
 wcchat.App.prototype.resizeCallback_ = function(opt_event) {
-  this.splitpane_.setSize(this.viewportSizeMonitor_.getSize());
+  this.splitpane_.setSize(
+    /** @type {!goog.math.Size} */ (this.viewportSizeMonitor_.getSize()));
 };
 
 
@@ -256,8 +259,7 @@ wcchat.App.prototype.resizeCallback_ = function(opt_event) {
  * @param {string} message String to log.
  */
 wcchat.App.prototype.msg = function(message) {
-  var msgDiv = goog.dom.createDom('DIV', undefined,
-      goog.dom.htmlToDocumentFragment(message));
+  var msgDiv = goog.dom.createDom('DIV', undefined, message);
   var el = /** @type {!Element} */ (goog.dom.getElement('chatPane'));
   goog.dom.append(el, msgDiv);
   el.scrollTop = el.scrollHeight;
@@ -290,6 +292,7 @@ wcchat.App.prototype.channelClose_ = function(e) {
  * @private
  */
 wcchat.App.prototype.channelError_ = function(e) {
+  goog.asserts.assert(e != null);
   this.msg('** goog.net.WebChannel.EventType.ERROR status: ' + e.status);
 };
 
@@ -300,15 +303,16 @@ wcchat.App.prototype.channelError_ = function(e) {
  * @private
  */
 wcchat.App.prototype.channelMessage_ = function(e) {
-  var array = /** @type {Array} */ (e.data);
+  goog.asserts.assert(e != null);
+  var array = /** @type {!Array} */ (e.data);
   var cmd = array[0];
-  var item = array[1];
+  var item = /** @type {string} */ (array[1]);
   if (cmd == 'new') {
     var cont = new goog.ui.Control(item);
     cont.setId(item);
     this.userList_.addChild(cont, true);
   } else if (cmd == 'message') {
-    this.msg('<b>' + item + '</b>: ' + array[2]);
+    this.msg(item + ': ' + array[2]);
   } else if (cmd == 'delete') {
     this.userList_.removeChild(item, true);
   }
@@ -332,7 +336,9 @@ wcchat.App.prototype.send_ = function() {
  * @private
  */
 wcchat.App.prototype.keyPressed_ = function(e) {
-  if (e.keyCode == goog.events.KeyCodes.ENTER) {
+  goog.asserts.assert(e != null);
+  if (/** @type {!goog.events.BrowserEvent} */ (e).keyCode ==
+      goog.events.KeyCodes.ENTER) {
     this.send_();
     e.preventDefault();
   }
@@ -363,7 +369,7 @@ wcchat.App.prototype.unload_ = function() {
  */
 (function() {
   /**
-   * @type {wcchat.App}
+   * @type {!wcchat.App}
    */
   var app = new wcchat.App();
   app.launch();
@@ -371,7 +377,8 @@ wcchat.App.prototype.unload_ = function() {
   var p = new goog.ui.Prompt('Username Required', 'What is your name?',
       function(response) {
         app.channel_.send({'user': response ? response : 'Anonymous'});
-        app.textArea_.getElement().focus();
+        var ta = /** @type {!Element} */ (app.textArea_.getElement());
+        ta.focus();
       });
   p.setVisible(true);
 })();