2 * Copyright (c) 2016 highstreet technologies GmbH and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 [ 'app/odlChat/odlChat.module', 'app/odlChat/odlChat.services' ],
11 function(odlChatApp) {
13 var main = function($scope, $rootScope, $odlChat) {
15 $rootScope.section_logo = 'src/app/odlChat/odlChat.png';
17 $scope.collection = [];
19 nickname : 'anonymous',
20 message : "Hey, what's up?!"
23 var listenToNotifications = function(socketLocation) {
25 var notificatinSocket = new WebSocket(socketLocation);
27 notificatinSocket.onmessage = function(event) {
28 // we process our received event here
29 $odlChat.getData(event, function(info, tweet) {
30 $scope.collection.push(tweet);
31 if ($scope.collection.length > 20) {
32 $scope.collection.shift();
35 $scope.chat.message = info;
38 notificatinSocket.onerror = function(error) {
39 console.log("Socket error: " + JSON.stringify(error));
41 notificatinSocket.onopen = function(event) {
42 console.log("Socket connection opened.");
44 notificatinSocket.onclose = function(event) {
45 console.log("Socket connection closed.");
47 // if there is a problem on socket creation we get
48 // exception (i.e. when socket address is incorrect)
50 alert("Error when creating WebSocket" + e);
54 $scope.send = function(chat) {
55 $odlChat.send(chat, function(info) {
60 var path = "/opendaylight-inventory:nodes/opendaylight-inventory:node[opendaylight-inventory:id='odlChat']";
61 $odlChat.register(path, function(socketLocation) {
62 listenToNotifications(socketLocation);
66 odlChatApp.register.controller('odlChatCtrl', [ '$scope', '$rootScope',