From 1abf9c2bb6d5f3ac8288183166c84e6c212d8ea5 Mon Sep 17 00:00:00 2001 From: schmerdy Date: Wed, 7 Oct 2015 20:35:39 -0400 Subject: [PATCH 1/6] Add Sec-WebSocket-Protocol header --- RELEASE | 7 +++++-- css/style.css | 10 ++++++++-- index.html | 5 ++++- index.js | 47 ++++++++++++++++++++++++++++------------------- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/RELEASE b/RELEASE index 20a42a7..2c1c908 100644 --- a/RELEASE +++ b/RELEASE @@ -1,7 +1,11 @@ +ver 0.1.4 (2015-10-07) +====================== +Add Sec-WebSocket-Protocol header + ver 0.1.3 (2014-09-13) ====================== -Support Chorome manifest version 2. +Support Chrome manifest version 2. ver 0.1.2 (2010-10-25) ====================== @@ -10,4 +14,3 @@ Improve UX. ver 0.1.1 (2010-10-18) ====================== First release. - diff --git a/css/style.css b/css/style.css index 1f530cb..ab7e2bd 100644 --- a/css/style.css +++ b/css/style.css @@ -1,6 +1,6 @@ body { width: 100%; - font-family: font-family:'ヒラギノ角ゴ Pro W3','Hiragino Kaku Gothic Pro','メイリオ',Meiryo,'MS Pゴシック',sans-serif; + font-family: font-family:'ソスqソスソスソスMソスmソスpソスS Pro W3','Hiragino Kaku Gothic Pro','ソスソスソスCソスソスソスI',Meiryo,'ソスlソスr ソスoソスSソスVソスbソスN',sans-serif; color: #000; background-color: #eee; font-size: 10pt; @@ -38,6 +38,12 @@ label { border: 1px solid #999; } +#protocolHeader { + width: 113px; + padding: 1px 3px; + border: 1px solid #999; +} + #disconnectButton { display: none; } @@ -66,4 +72,4 @@ label { #messages pre.sent { color: #f63; -} \ No newline at end of file +} diff --git a/index.html b/index.html index 63094a4..3d2fb4b 100644 --- a/index.html +++ b/index.html @@ -16,6 +16,9 @@ +
+ +
CLOSED @@ -39,4 +42,4 @@ - \ No newline at end of file + diff --git a/index.js b/index.js index 71dbc21..48771e0 100644 --- a/index.js +++ b/index.js @@ -3,16 +3,22 @@ new function() { var connected = false; var serverUrl; + var protocolHeader; var connectionStatus; var sendMessage; - + var connectButton; - var disconnectButton; + var disconnectButton; var sendButton; var open = function() { var url = serverUrl.val(); - ws = new WebSocket(url); + var protocol = protocolHeader.val(); + if (protocol) { + ws = new WebSocket(url, protocol); + } else { + ws = new WebSocket(url); + } ws.onopen = onOpen; ws.onclose = onClose; ws.onmessage = onMessage; @@ -20,10 +26,11 @@ new function() { connectionStatus.text('OPENING ...'); serverUrl.attr('disabled', 'disabled'); + protocolHeader.attr('disabled', 'disabled'); connectButton.hide(); disconnectButton.show(); } - + var close = function() { if (ws) { console.log('CLOSING ...'); @@ -33,16 +40,17 @@ new function() { connectionStatus.text('CLOSED'); serverUrl.removeAttr('disabled'); + protocolHeader.removeAttr('disabled'); connectButton.show(); disconnectButton.hide(); sendMessage.attr('disabled', 'disabled'); sendButton.attr('disabled', 'disabled'); } - + var clearLog = function() { $('#messages').html(''); } - + var onOpen = function() { console.log('OPENED: ' + serverUrl.val()); connected = true; @@ -50,21 +58,21 @@ new function() { sendMessage.removeAttr('disabled'); sendButton.removeAttr('disabled'); }; - + var onClose = function() { console.log('CLOSED: ' + serverUrl.val()); ws = null; }; - + var onMessage = function(event) { var data = event.data; addMessage(data); }; - + var onError = function(event) { alert(event.data); } - + var addMessage = function(data, type) { var msg = $('
').text(data);
 		if (type === 'SENT') {
@@ -72,7 +80,7 @@ new function() {
 		}
 		var messages = $('#messages');
 		messages.append(msg);
-		
+
 		var msgBox = messages.get(0);
 		while (msgBox.childNodes.length > 1000) {
 			msgBox.removeChild(msgBox.firstChild);
@@ -83,32 +91,33 @@ new function() {
 	WebSocketClient = {
 		init: function() {
 			serverUrl = $('#serverUrl');
+			protocolHeader = $('#protocolHeader');
 			connectionStatus = $('#connectionStatus');
 			sendMessage = $('#sendMessage');
-			
+
 			connectButton = $('#connectButton');
-			disconnectButton = $('#disconnectButton'); 
+			disconnectButton = $('#disconnectButton');
 			sendButton = $('#sendButton');
-			
+
 			connectButton.click(function(e) {
 				close();
 				open();
 			});
-		
+
 			disconnectButton.click(function(e) {
 				close();
 			});
-			
+
 			sendButton.click(function(e) {
 				var msg = $('#sendMessage').val();
 				addMessage(msg, 'SENT');
 				ws.send(msg);
 			});
-			
+
 			$('#clearMessage').click(function(e) {
 				clearLog();
 			});
-			
+
 			var isCtrl;
 			sendMessage.keyup(function (e) {
 				if(e.which == 17) isCtrl=false;
@@ -125,4 +134,4 @@ new function() {
 
 $(function() {
 	WebSocketClient.init();
-});
\ No newline at end of file
+});

From cf8a4d0bc6f2091b909fcee3287c2b9b290a8e26 Mon Sep 17 00:00:00 2001
From: Juergen - Sonos Developer Advocate 
Date: Wed, 7 Oct 2015 20:43:27 -0400
Subject: [PATCH 2/6] Add Sec-WebSocket-Protocol header

---
 manifest.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/manifest.json b/manifest.json
index 382f999..c6822ab 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
 {
   "name": "Simple WebSocket Client",
   "manifest_version": 2,
-  "version": "0.1.3",
+  "version": "0.1.4",
   "description": "Construct custom Web Socket requests and handle responses to directly test your Web Socket services.",
   "icons": {
     "16":  "resources/icon_032.png",

From e55c9d6956e22b2f5580f9a20c9010af386df417 Mon Sep 17 00:00:00 2001
From: schmerdy 
Date: Wed, 7 Oct 2015 21:53:42 -0400
Subject: [PATCH 3/6] Support for multiple subprotocols

Protocol negotiation through comma-separated tokens in Sec-WebSocket-Protocol header, server chooses first matching protocol
---
 index.js | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/index.js b/index.js
index 48771e0..75eca6c 100644
--- a/index.js
+++ b/index.js
@@ -13,9 +13,14 @@ new function() {
 
 	var open = function() {
 		var url = serverUrl.val();
-		var protocol = protocolHeader.val();
+		// comma-separated protocol headers are passed as array
+		var protocol = protocolHeader.val().replace(/\s/,'').split(',');;
 		if (protocol) {
-			ws = new WebSocket(url, protocol);
+			try {
+				ws = new WebSocket(url, protocol);
+			} catch (ex) {
+				alert(ex);
+			}
 		} else {
 			ws = new WebSocket(url);
 		}
@@ -51,8 +56,11 @@ new function() {
 		$('#messages').html('');
 	}
 
-	var onOpen = function() {
+	var onOpen = function(evt) {
 		console.log('OPENED: ' + serverUrl.val());
+		if (evt.currentTarget.protocol) {
+			console.log('Sec-WebSocket-Protocol: ' + evt.currentTarget.protocol);
+		}
 		connected = true;
 		connectionStatus.text('OPENED');
 		sendMessage.removeAttr('disabled');

From b49da9056e41bfcc68221f96d8b6a17e801e6991 Mon Sep 17 00:00:00 2001
From: schmerdy 
Date: Wed, 7 Oct 2015 22:12:17 -0400
Subject: [PATCH 4/6] Fix empty Sec-WebSocket-Protocol header bug

---
 index.js | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/index.js b/index.js
index 75eca6c..9711509 100644
--- a/index.js
+++ b/index.js
@@ -14,10 +14,11 @@ new function() {
 	var open = function() {
 		var url = serverUrl.val();
 		// comma-separated protocol headers are passed as array
-		var protocol = protocolHeader.val().replace(/\s/,'').split(',');;
+		var protocol = protocolHeader.val();
 		if (protocol) {
+			var protocols = protocol.replace(/\s/,'').split(',');
 			try {
-				ws = new WebSocket(url, protocol);
+				ws = new WebSocket(url, protocols);
 			} catch (ex) {
 				alert(ex);
 			}

From 9d1e643bffba82964da38cd3249c3c9fea6369ca Mon Sep 17 00:00:00 2001
From: schmerdy 
Date: Wed, 7 Oct 2015 22:22:10 -0400
Subject: [PATCH 5/6] move comment closer to code it's actually commenting...

---
 index.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/index.js b/index.js
index 9711509..255c940 100644
--- a/index.js
+++ b/index.js
@@ -13,9 +13,9 @@ new function() {
 
 	var open = function() {
 		var url = serverUrl.val();
-		// comma-separated protocol headers are passed as array
 		var protocol = protocolHeader.val();
 		if (protocol) {
+			// comma-separated protocol headers are passed as array
 			var protocols = protocol.replace(/\s/,'').split(',');
 			try {
 				ws = new WebSocket(url, protocols);

From eafde199add74a6c7d53418a8461e1af4c79fdfe Mon Sep 17 00:00:00 2001
From: Juergen - Sonos Developer Advocate 
Date: Mon, 12 Oct 2015 00:44:16 -0700
Subject: [PATCH 6/6] Update style.css

unicode mess cleaned up
---
 css/style.css | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/css/style.css b/css/style.css
index ab7e2bd..9b74e5c 100644
--- a/css/style.css
+++ b/css/style.css
@@ -1,6 +1,6 @@
 body {
 	width: 100%;
-	font-family: font-family:'ソスqソスソスソスMソスmソスpソスS Pro W3','Hiragino Kaku Gothic Pro','ソスソスソスCソスソスソスI',Meiryo,'ソスlソスr ソスoソスSソスVソスbソスN',sans-serif;
+	font-family: font-family:'繝偵Λ繧ョ繝手ァ偵ざ Pro W3','Hiragino Kaku Gothic Pro','繝。繧、繝ェ繧ェ',Meiryo,'シュシウ シー繧エ繧キ繝繧ッ',sans-serif;
 	color: #000;
 	background-color: #eee;
 	font-size: 10pt;