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
9 define(['app/mwtnCommons/mwtnCommons.module', 'app/odlChat/odlChat.module'],function(odlChatApp) {
11 odlChatApp.register.factory('$odlChat', function($http, $mwtnCommons) {
13 var createStream = function(streamName, callback) {
16 url : [ service.base, 'streams/stream/', streamName ].join('')
18 $http(request).then(function successCallback(response) {
19 console.log(response.headers('Location'));
20 callback(response.headers('Location'));
21 }, function errorCallback(response) {
22 console.error(JSON.stringify(response));
28 base : window.location.origin + "/restconf/",
32 service.getData = function(event, callback) {
37 'config/opendaylight-inventory:nodes/node/odlChat/' ].join('')
39 $http(request).then(function successCallback(response) {
41 nickname : response.data.node[0]['flow-node-inventory:manufacturer'],
42 message : response.data.node[0]['flow-node-inventory:description'],
43 time : JSON.stringify(new Date()).split('T')[1].substring(0, 5)
46 }, function errorCallback(response) {
47 console.error(JSON.stringify(response));
48 callback('ERROR while sending ;(');
53 service.register = function(path, callback) {
57 'operations/sal-remote:create-data-change-event-subscription' ]
62 "sal-remote-augment:datastore" : "CONFIGURATION",
63 "sal-remote-augment:scope" : "SUBTREE"
68 function successCallback(response) {
69 createStream(response.data.output['stream-name'], function(
71 callback(socketLocation);
73 }, function errorCallback(response) {
74 console.error(JSON.stringify(response));
78 service.send = function(chat, callback) {
82 'config/opendaylight-inventory:nodes/node/odlChat' ].join(''),
86 "flow-node-inventory:manufacturer" : chat.nickname,
87 "flow-node-inventory:software" : "",
88 "flow-node-inventory:serial-number" : "",
89 "flow-node-inventory:hardware" : "",
90 "flow-node-inventory:description" : chat.message
94 $http(request).then(function successCallback(response) {
95 callback('send successfully');
96 }, function errorCallback(response) {
97 console.error(JSON.stringify(response));
98 callback('ERROR while sending ;(');