You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.7 KiB
48 lines
1.7 KiB
var hubUrl = "/IoTCenter/hub?group=page";
|
|
var connection = new signalR.HubConnectionBuilder().withUrl(hubUrl).build();
|
|
function connect() {
|
|
if (connection.state === signalR.HubConnectionState.Disconnected) {
|
|
connection.start().then(function () {
|
|
console.log('signalR 连接成功');
|
|
}).catch(function (err) {
|
|
console.log(err);
|
|
setTimeout(connect, 15 * 1000);
|
|
});
|
|
}
|
|
}
|
|
connection.on('Connected', function (id) {
|
|
connectionId = id;
|
|
console.log('signalR 连接Id:' + connectionId);
|
|
});
|
|
connection.on("ServerToClient", function (method, message, to, from) {
|
|
console.log(method);
|
|
console.log(message);
|
|
var event = method.substr(0, 1).toLowerCase() + method.substr(1);
|
|
var model = JSON.parse(message);
|
|
store.dispatch('update', {event,model,to,from});
|
|
//store.commit('update', method,message,to,from);
|
|
//store.commit('update',method,message,to,from)
|
|
//if (method === 'NodeEntityUpdated') {
|
|
// store.commit('updateNode', model);
|
|
//}
|
|
////else if (method === 'NodeEntityInserted') {}
|
|
////else if (method === 'NodeEntityDeleted') {}
|
|
//else if (method === 'DeviceEntityInserted') {
|
|
// store.commit('insertDevice', model);
|
|
//}
|
|
//else if (method === 'DeviceEntityUpdated') {
|
|
// store.commit('updateDevice', model);
|
|
//}
|
|
//else if (method === 'DeviceEntityDeleted') {
|
|
// store.commit('deleteDevice', model);
|
|
//}
|
|
//else if (method === 'DataEntityInserted') {
|
|
// store.commit('insertData', model);
|
|
//}
|
|
//else if (method === 'DataEntityUpdated') {
|
|
// store.commit('updateData', model);
|
|
//}
|
|
//else if (method === 'DataEntityDeleted') {
|
|
// store.commit('deleteData', model);
|
|
//}
|
|
}); |