-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.html
69 lines (67 loc) · 2.57 KB
/
index.html
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="action-cable-url" content="ws://localhost:3000/cable"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
<script src="bower_components/angular-websocket/dist/angular-websocket.js"></script>
<script src="bower_components/angular-actioncable/dist/angular-actioncable.min.js"></script>
</head>
<body ng-app="app">
<section ng-controller="SomeController">
<ul>
<li ng-repeat="datum in myData">
{{ datum }}
</li>
</ul>
<input ng-model="inputText" /><button ng-click="sendToMyChannel(inputText)">Send</button>
</section>
<br />
<section>
<div ng-controller="StatusController">
<h4>
<span ng-show="status.connected">✓ Connected</span>
<span ng-show="status.disconnected">✘ Disconnected</span>
<span ng-show="status.connecting">✘ Connecting......</span>
</h4>
<div>
You can
"<kbd>Ctrl+c</kbd>" + "<kbd>rails s</kbd>" and "<kbd>Ctrl+z</kbd>" + "<kbd>fg 1</kbd>"
the server to see how it affects client states over time.
Each client will maintain one and only one open connection and multiple clients will reconnect at slightly different times on server restart.
</div>
</div>
</section>
<script>
angular.module('app', [
'ngActionCable'
])
.run(function (ActionCableConfig){
ActionCableConfig.debug = true;
})
.controller('SomeController', function ($scope, ActionCableChannel){
$scope.inputText = "";
$scope.myData = [];
// connect to ActionCable
var consumer = new ActionCableChannel("ChatChannel", {user: 42, chat: 37});
var callback = function(message) {
$scope.myData.push(message);
};
consumer.subscribe(callback).then(function(){
$scope.sendToMyChannel = function(message){
consumer.send(message);
};
$scope.$on("$destroy", function(){
consumer.unsubscribe().then(function(){ $scope.sendToMyChannel = undefined; });
});
});
})
.controller('StatusController', function($scope, ActionCableSocketWrangler){
$scope.status= ActionCableSocketWrangler;
});
</script>
</body>
</html>