Skip to content

Just a simple checkbox to have the option to console.log the error instead of alerting the event.data #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<legend>Message Log <button id="clearMessage">Clear</button></legend>
<div id="messages"></div>
</fieldset>
<fieldset>
<legend>Options</legend>
<div>
<label><input title="You can ignore this if you don't know what it means" type="checkbox" id="logInstead" value="first_checkbox"> Console.log error obj instead of alerts</label
</div>
</fieldset>
</div>
<script type="text/javascript" src="lib/jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="index.js"></script>
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ new function() {
var serverUrl;
var connectionStatus;
var sendMessage;
var logInstead;

var connectButton;
var disconnectButton;
Expand All @@ -17,6 +18,7 @@ new function() {
ws.onclose = onClose;
ws.onmessage = onMessage;
ws.onerror = onError;
logInstead = $('#logInstead').is(':checked');

connectionStatus.text('OPENING ...');
serverUrl.attr('disabled', 'disabled');
Expand Down Expand Up @@ -62,7 +64,12 @@ new function() {
};

var onError = function(event) {
alert(event.data);
console.log(event);
if(logInstead){
console.error('Error! ', event);
}else{
alert(event.data);
}
}

var addMessage = function(data, type) {
Expand Down Expand Up @@ -101,6 +108,7 @@ new function() {

sendButton.click(function(e) {
var msg = $('#sendMessage').val();
logInstead = $('#logInstead').is(':checked');
addMessage(msg, 'SENT');
ws.send(msg);
});
Expand Down