My problem is that I need in the key_client variable is loaded variable md5 obtained through a module called nodejs get-mac.
The way I'm working it can not get it work.
Always runs before key_client to get mac.
//Get Mac Machine for request
var md5;
node.mac.getMac(function(err, mac){
var hash = node.crypt.createHash('md5').setEncoding('hex');
hash.write(mac);
hash.end();
md5 = hash.read();
});
//Define host and set keys
var host = 'https://service.herokuapp.com/'
var namespace = 'api/v1'
var api = host + namespace
var key_server = '432565454'
var key_client = md5;
console.log(key_client);
Try:
//Get Mac Machine for request
var md5;
node.mac.getMac(function(err, mac){
var hash = node.crypt.createHash('md5').setEncoding('hex');
hash.write(mac);
hash.end();
md5 = hash.read();
someFunction();
});
function someFunction() {
//Define host and set keys
var host = 'https://service.herokuapp.com/'
var namespace = 'api/v1'
var api = host + namespace
var key_server = '432565454'
var key_client = md5;
console.log(key_client);
}
Related
i want to send a websocket, using express-ws out from a different controller, not by route and I have the following code in the server.js:
var SocketController = require('./routes/ws.routes');
var app = express();
var server = require('http').createServer(app);
var expressWs = require('express-ws')(app);
app.ws('/', SocketController.socketFunction);
the SocketController looks like that:
exports.socketFunction = function (ws, req) {
ws.on('message', function(msg) {
console.log(msg);
ws.send("hello");
});
}
Is it possible to call the
ws.send()
event from another controller? How do i get the "ws" object?
thanks!
You will have to store your sockets in memory. To access stored sockets from different modules, you can store references for these sockets in a separate module.
For example, you can create a module socketCollection that stores all the active sockets.
socketCollection.js:
exports.socketCollection = [];
You can import this module where you define your web socket server:
var socketCollection = require('./socketCollection');
var SocketController = require('./routes/ws.routes');
var app = express();
var server = require('http').createServer(app);
var expressWs = require('express-ws')(app);
expressWs.getWss().on('connection', function(ws) {
socketCollection.push({
id: 'someRandomSocketId',
socket: ws,
});
});
app.ws('/', SocketController.socketFunction);
Now every time new client connects to the server, it's reference will be saved to 'socketCollection'
You can access these clients from any module by importing this array
var socketCollection = require('./socketCollection');
var ws = findSocket('someRandomSocketId', socketCollection);
var findSocket = function(id, socketCollection) {
var result = socketCollection.filter(function(x){return x.id == id;} );
return result ? result[0].socket : null;
};
I am using below javascript code to connect to autobahn server. All these times I was using static ip but now the ip is going to be dynamic. How can I pass dynamic server ip and get autobahn connected dynamically?
var connection = new autobahn.Connection({url: 'ws://<ip>:8080/ws', realm: 'realm1'});
var openSession = null;
connection.onopen = function (session) {
openSession = session;
window.JSInterface.isConnected(true);
};
connection.onClose = function(reason, details) {
openSession = null;
window.JSInterface.isConnected(false);
}
There are to options:
Take a domain name instead of an IP e.g ws://autobahn.de:8080/ws
You have a service where you can fetch the ip an then pass it with a variable for example:
var connectionIP = 8.8.8.8;
var connection = new autobahn.Connection({url:'ws://'+connectionIP+':8080/ws', realm: 'realm1'});
Introduction
I have cloned the project from this git link here
App is running on localhost fine.I am willing to deploy this demo project on windows server where it will run on https://localhost:8443. I have no idea how to deploy this specific demo project, although i have successfully deployed another simple node application on iis.
What can be causing problem, i think from script server.js
var path = require('path');
var url = require('url');
var express = require('express');
var minimist = require('minimist');
var ws = require('ws');
var kurento = require('kurento-client');
var fs = require('fs');
var https = require('https');
var argv = minimist(process.argv.slice(2), {
default: {
as_uri: 'https://localhost:8443/',
ws_uri: 'ws://93.104.213.28:8888/kurento'
}
});
var options =
{
key: fs.readFileSync('keys/server.key'),
cert: fs.readFileSync('keys/server.crt')
};
var app = express();
/*
* Definition of global variables.
*/
var idCounter = 0;
var candidatesQueue = {};
var kurentoClient = null;
var presenter = null;
var viewers = [];
var noPresenterMessage = 'No active presenter. Try again later...';
/*
* Server startup
*/
var asUrl = url.parse(argv.as_uri);
var port = asUrl.port;
var server = https.createServer(options, app).listen(port, function() {
console.log('Kurento Tutorial started');
console.log('Open ' + url.format(asUrl) + ' with a WebRTC capable browser');
});
var wss = new ws.Server({
server : server,
path : '/one2many'
}); .....other code
I have been trying this for 2 days but no luck.Any expert might help.
Thanks for your time.
My remote js file as below
(function(window,document){
var config = {
'placeHolder' : 'content_div'
};
var html = "blaaa blaaa";
})(window,document);
I would likte to get value of html.
I have tried as below but I have got error.
string _JsVars = this._HttpWebRequestRemoteUrl(#"http://www.remotewebpage.com");
var engine = new Jurassic.ScriptEngine();
var result = engine.(_JsVars);
var var1 = engine.GetGlobalValue<string>("html");
MessageBox.Show(var1.ToString());
I'm using localStorage in my Firefox add-on in this way:
var ioService = Components.classes['#mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
var scriptSecManager = Components.classes['#mozilla.org/scriptsecuritymanager;1'].getService(Components.interfaces.nsIScriptSecurityManager);
var domStorageManager = Components.classes['#mozilla.org/dom/storagemanager;1'].getService(Components.interfaces.nsIDOMStorageManager);
var uri = ioService.newURI('http://example.com/addon/', null, null);
var principal = scriptSecManager.getNoAppCodebasePrincipal ? scriptSecManager.getNoAppCodebasePrincipal(uri) : scriptSecManager.getCodebasePrincipal(uri);
var localStorage = domStorageManager.getLocalStorageForPrincipal(principal, '');
All works fine, but when user removes "offline data" storage is cleared. How can i workround it?
Use the preferences service to store the data in the user's profile.
var prefService = Cc["#mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService),
prefs = prefService.getBranch("extensions.YOUREXTENSIONABBREVIATIONHERE.");
var stringValue = "My Name",
booleanValue = true,
numberValue = 55;
prefs.setCharPref("stringParam", stringValue);
prefs.setBoolPref("booleanParam", booleanValue);
prefs.setCharPref("numberParam", ''+numberValue);
prefService.savePrefFile(null); // only to force an immediate save
stringValue = prefs.getCharPref("stringParam");
booleanValue = prefs.getBoolPref("booleanParam");
numberValue = parseInt(prefs.getCharPref("numberParam"), 10);
Put a defaults.js file in your defaults/preferences folder and initialize preferences for a new user. You'll get an error if you try to retrieve a preference that doesn't exist and there's no way to check if it exists.
Look here:
https://developer.mozilla.org/en-US/docs/Adding_preferences_to_an_extension