Skip to content

Commit

Permalink
connect and immediate disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesbradshaw committed Apr 23, 2016
1 parent ed091e5 commit fcc3cb0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
33 changes: 22 additions & 11 deletions NodeSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,31 @@ class NodeSocket {
if(nodeId.split(':')[0] !== 'Executable') {
// install monitored item
//console.log('monitoring', nodeId);
let monitoredItem = subscription.monitor(nodeDefinition,
{
samplingInterval: 1000,
discardOldest: true,
queueSize: 10
},
opcua.read_service.TimestampsToReturn.Both
);

monitoredItem.on("changed",function(dataValue){
let monitoredPromise = new Promise((resolve, reject)=>{
let monitoredItem = subscription.monitor(nodeDefinition,
{
samplingInterval: 1000,
discardOldest: true,
queueSize: 10
},
opcua.read_service.TimestampsToReturn.Both,
(err)=>{
if(err) {
reject(err);
} else {
resolve(monitoredItem);
}
}
);

monitoredItem.on("changed",function(dataValue){
obs.onNext(dataValue);
});
console.log("-monitoring", subscription.subscriptionId, nodeId);
});
console.log("-monitoring", subscription.subscriptionId, nodeId);
return ()=>monitoredItem.terminate();
return ()=>
monitoredPromise.then((item)=>item.terminate());
} else {
let requiredPoll = {
obs,
Expand Down
14 changes: 12 additions & 2 deletions server.production.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,21 @@ io.on('connection', (mySocket)=> {


});
mySocket.on('leave', (nodeId) => leaveRoom(mySocket, nodeId, myRooms, myConnection));
mySocket.on('leave', (nodeId) => {
console.log('leave:' , nodeId);
leaveRoom(mySocket, nodeId, myRooms, myConnection);
});


mySocket.on('disconnect', function(){
console.log('disconnecting...');
for(const node of Object.keys(myRooms)) {
leaveRoom(mySocket, node, myRooms, myConnection);
try {
leaveRoom(mySocket, node, myRooms, myConnection);
} catch(ex){

}

}
});
});
Expand Down

0 comments on commit fcc3cb0

Please sign in to comment.