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..9b74e5c 100644 --- a/css/style.css +++ b/css/style.css @@ -1,6 +1,6 @@ body { width: 100%; - font-family: font-family:'qMmpS Pro W3','Hiragino Kaku Gothic Pro','CI',Meiryo,'lr oSVbN',sans-serif; + font-family: font-family:'ヒラギノ角ゴ Pro W3','Hiragino Kaku Gothic Pro','メイリオ',Meiryo,'MS Pゴシック',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..255c940 100644 --- a/index.js +++ b/index.js @@ -3,16 +3,28 @@ 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) { + // comma-separated protocol headers are passed as array + var protocols = protocol.replace(/\s/,'').split(','); + try { + ws = new WebSocket(url, protocols); + } catch (ex) { + alert(ex); + } + } else { + ws = new WebSocket(url); + } ws.onopen = onOpen; ws.onclose = onClose; ws.onmessage = onMessage; @@ -20,10 +32,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,38 +46,42 @@ 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() { + + 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'); 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 +89,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 +100,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 +143,4 @@ new function() {
 
 $(function() {
 	WebSocketClient.init();
-});
\ No newline at end of file
+});
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",