-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
93 lines (84 loc) · 2.77 KB
/
example.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<head>
<!-- generic unused meta -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
<!-- application title -->
<title>AngularJS SocketCluster Client Example</title>
</head>
<body ng-app="example.app">
<p>Open Console To View Output</p>
<!-- example js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.0/angular.js"></script>
<script src="./release/socket.js"></script>
<script type="text/javascript">
/**
* @description
* Example app module declaration.
*/
angular
.module('example.app', [
'sbb.components'
])
.run([
'$rootScope',
'$log',
'$timeout',
'sbb.components.socket',
Bootstrap
])
/**
* @name Bootstrap
* @description
* This function will bootstrap the application as needed.
* @param {angular.$rootScope} $rootScope
* @param {angular.$log} $log
* @param {angular.$timeout} $timeout
* @param {sbb.components.socket} SocketInterface
*/
function Bootstrap($rootScope, $log, $timeout, SocketInterface) {
// Enable Socket Debugging
SocketInterface.toggleDebugging(true);
// Set a placeholder for the random channel
channel = 'live-meeting-1234567890';
// Connect to the socket
SocketInterface
.connect()
.then(function() {
// Subscribe to the channel
SocketInterface
.subscribe(channel)
.then(function() {
// Set up a listener for the dummy published event.
$rootScope.$on('socket:meeting:current-state', function(e, eventData) {
// Do something here...
});
// Publish some data to the channel
SocketInterface
.publish(channel, {
$applications: ['live-meeting'],
$event: 'meeting:current-state',
$user: {
name: 'Tester',
invitation: '1234567890'
},
data: {}
})
.then(function() {
// Disconnect from the socket
$timeout(function() {
SocketInterface
.disconnect()
.then(function() {});
}, 5000)
})
})
})
.catch(function (err) {
console.log(err)
});
}
</script>
</body>
</html>