Skip to content

Commit

Permalink
Merge 9dc3061 into b73f66e
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali committed Jul 9, 2014
2 parents b73f66e + 9dc3061 commit 1b0fa73
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
24 changes: 8 additions & 16 deletions examples/webchat/web/app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
var origin = window.location.origin;

var sock = new SockJS(origin+'/echo')
if (!window.location.origin) { // Some browsers (mainly IE) does not have this property, so we need to build it manually...
window.location.origin = window.location.protocol + '//' + window.location.hostname + (window.location.port ? (':' + window.location.port) : '');
}


var sock = new SockJS(window.location.origin+'/echo')

document.getElementById("input").onkeydown= function (e) {
if (e.keyCode === 13) {
send();
e.target.value="";
};
};
document.getElementById("input").focus();
sock.onopen = function() {
console.log('connection open');
//console.log('connection open');
document.getElementById("status").innerHTML = "connected";
document.getElementById("send").disabled=false;
};
Expand All @@ -19,12 +16,7 @@ sock.onmessage = function(e) {
document.getElementById("output").value += e.data +"\n";
};
sock.onclose = function() {
console.log('connection closed');
//console.log('connection closed');
document.getElementById("status").innerHTML = "disconnected";
document.getElementById("send").disabled=true;
};

function send() {
text = document.getElementById("input").value;
sock.send(text);
}
11 changes: 8 additions & 3 deletions examples/webchat/web/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="app.js"> </script>
<meta charset="UTF-8">
<title>Chat Web Example</title>
</head>

<body>
<h1>Chat - Web Example</h1>
Input text: <input id="input" focus="true"><button onClick="send()" disabled="true" id="send">Send</button>
<form onSubmit='sock.send(document.getElementById("input").value); return false;'>
Input text: <input id="input" focus="true" />
<input type="submit" disabled="true" id="send" value="Send" />
</form>
<br/>
Messages from server:</br>
<textarea cols=80 rows=20 id="output">
</textarea>
<br/>
status: <span id="status">connecting...</span>
<script type="text/javascript" src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="app.js"> </script>

</body>
</html>
18 changes: 8 additions & 10 deletions examples/webecho/web/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if (!window.location.origin) { // Some browsers (mainly IE) does not have this property, so we need to build it manually...
window.location.origin = window.location.protocol + '//' + window.location.hostname + (window.location.port ? (':' + window.location.port) : '');
}

var origin = window.location.origin;

// options usage example
Expand All @@ -9,16 +13,9 @@ var options = {

var sock = new SockJS(origin+'/echo', undefined, options);

document.getElementById("input").onkeydown= function (e) {
if (e.keyCode === 13) {
send();
e.target.value="";
};
};
document.getElementById("input").focus();

sock.onopen = function() {
console.log('connection open');
//console.log('connection open');
document.getElementById("status").innerHTML = "connected";
document.getElementById("send").disabled=false;
};
Expand All @@ -28,10 +25,11 @@ sock.onmessage = function(e) {
};

sock.onclose = function() {
console.log('connection closed');
document.getElementById("status").innerHTML = "connection closed";
//console.log('connection closed');
};

function send() {
text = document.getElementById("input").value;
sock.send(text);
sock.send(document.getElementById("input").value); return false;
}
13 changes: 9 additions & 4 deletions examples/webecho/web/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="app.js"> </script>
<meta charset="UTF-8">
<title>Echo Web Example</title>
</head>

<body>
<h1>Echo - Web Example</h1>
Input text: <input id="input" focus="true"><button onClick="send()" disabled="true" id="send">Send</button>
<form onSubmit='sock.send(document.getElementById("input").value); return false;'>
Input text: <input id="input" focus="true" />
<input type="submit" disabled="true" id="send" value="Send" />
</form>
<br/>
Echo from server:</br>
Messages from server:</br>
<textarea cols=80 rows=20 id="output">
</textarea>
<br/>
status: <span id="status">connecting...</span>
<script type="text/javascript" src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script>
<script type="text/javascript" src="app.js"> </script>

</body>
</html>
2 changes: 1 addition & 1 deletion examples/webecho/webecho.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
http.Handle("/echo/", handler)
http.Handle("/", http.FileServer(http.Dir("web/")))
log.Println("Server started")
log.Fatal(http.ListenAndServe(":8080", nil))
log.Fatal(http.ListenAndServe(":3000", nil))
}

func echoHandler(session sockjs.Session) {
Expand Down

0 comments on commit 1b0fa73

Please sign in to comment.