-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.html
More file actions
47 lines (41 loc) · 1.57 KB
/
index.html
File metadata and controls
47 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html>
<head>
<script src="angular.min.js"></script>
<script src="socket.io-1.3.2.js"></script>
<script src="angular-socket.js"></script>
<script type="application/javascript">
var app = angular.module('myApp', [ 'socket.io' ]);
app.config(function ($socketProvider) {
$socketProvider.setConnectionUrl('http://localhost:8080');
});
app.controller('Ctrl', function Ctrl($scope, $socket) {
$socket.on('echo', function (data) {
$scope.serverResponse = data;
});
$scope.emitBasic = function emitBasic() {
console.log('echo event emited');
$socket.emit('echo', $scope.dataToSend);
$scope.dataToSend = '';
};
$scope.emitACK = function emitACK() {
$socket.emit('echo-ack', $scope.dataToSend, function (data) {
//se nao tivesse sido feito $apply
//a variavel $scope não seria reconhecida
$scope.serverResponseACK = data;
});
$scope.dataToSend = '';
};
});
</script>
</head>
<body>
<div ng-app="myApp" ng-controller="Ctrl">
<input ng-model="dataToSend">
<button ng-click="emitBasic()">Send</button>
<button ng-click="emitACK()">Send (ACK)</button>
<div>Server Response: {{ serverResponse }}</div>
<div>Server Response (ACK): {{ serverResponseACK }}</div>
</div>
</body>
</html>