I've been following along with this
https://github.com/songz/OpenTokNodeJS
I posted an issue but thought I would try here as well.
I've been working at this for a minute and can't seem to get it running.
Here's my error
TypeError: Object Error: Invalid Key or Secret has no method 'createSession'
at port (/Users/rswain/Desktop/Art/videotok/app.js:42:19)
at callbacks (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:164:37)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:138:11)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:135:11)
at pass (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:173:5)
at Object.router (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:33:10)
at next (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/proto.js:193:15)
at resume (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:65:7)
at SendStream.error (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:80:37)
TypeError: Object Error: Invalid Key or Secret has no method 'createSession'
at port (/Users/rswain/Desktop/Art/videotok/app.js:42:19)
at callbacks (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:164:37)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:138:11)
at param (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:135:11)
at pass (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:145:5)
at Router._dispatch (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:173:5)
at Object.router (/Users/rswain/Desktop/Art/videotok/node_modules/express/lib/router/index.js:33:10)
at next (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/proto.js:193:15)
at resume (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:65:7)
at SendStream.error (/Users/rswain/Desktop/Art/videotok/node_modules/express/node_modules/connect/lib/middleware/static.js:80:37)
I'm guessing it has something to do with my api key, and to be honest i'm not 100% where i'm supposed to even put it. I've tried a few methods. First I replaced the lines in app.js
var OTKEY = process.env.TB_KEY;
var OTSECRET = process.env.TB_SECRET;
with
var OTKEY = (my api key);
var OTSECRET = (my secret);
but when i run $ node app.js, nothing happens, and I get the error
I've also tried adding the key and secret to the package.json file like so
{
"name":"NodeOpenTok",
"version":"0.0.2",
"dependencies":{
"opentok":"44456952",
"express":"7f2ecae114cd4095a1ed689ff63910f1ea79444b",
"ejs":""
}
}
but I get the same errors. any ideas?
thanks for making this, looks great, can't wait to get it working!
my name is Song and I believe I can help you. When I wrote the following code, I am simply setting the variables OTKEY and OT_SECRET.
var OTKEY = process.env.TB_KEY;
var OTSECRET = process.env.TB_SECRET;
You can similarly replace the key and secret directly:
var OTKEY = "1234";
var OTSECRET = "1abbababaabcabc";
process.env.TB_KEY and process.env.TB_SECRET pulls out the variables from my system environment . I do it this way because of security reasons ( I don't want to accidentally push my key/secret to github ). To set variables for your system environment, open your bash profile and add the following lines:
export TB_KEY='1234'
export TB_SECRET='1abbababaabcabc'
Again, setting the environment variables is not necessary to get your code to work. The simplest way to go is to simply set the variables OTKEY and OTSECRET.
Good Luck!
Related
I have tried a dozen ways to make a button on a webpage that's got a connected Twilio client voice call perform .sendDigits. This is the most recent try.
const dtmf_1 = document.getElementById('DTMF1');
dtmf_1.onclick = function(){call.sendDigits('1')};
This returns
Uncaught ReferenceError: call is not defined at dtmf_1.onclick (quickstart.js:46:79)
Frankly, I have no idea if fixing the reference is even going to work.
Does anyone have an example of working code that will play a DTMF tone on a live call with the Twilio JavaScript SDK?
Thanks to a timely comment by Tristan Blackwell (see above), I was able to fix this issue which was indeed a scoping problem.
The fix was to put the line
dtmf_1.onclick = function(){call.sendDigits('1')};
right under the line where the call is connected.
const call = await device.connect({ params });
Like so
const call = await device.connect({ params });
dtmf_1.onclick = function(){call.sendDigits('1')};
I am using this: https://www.npmjs.com/package/youtube-notification to get new uploads for my discord bot.
I'm not sure what to put for the urlCallback section?
This is the example code:
const notifier = new YouTubeNotifier({
hubCallback: 'https://example.com/youtube',
port: 8080,
secret: 'Something',
path: '/youtube'
});
notifier.setup();
I think, the documentation for the package makes it pretty clear
Quoting it
YouTubeNotifier.constructor(options)
options is an object that you may write your own properties to. The following properties are read by YouTubeNotifier:
hubCallback - Your ip/domain name that will be used as a callback URL by Pubsubhubbub. It must be in a URL format, ex: 'https://example.com/'. This is a required property as the default is undefined.
So basically your callback will be your localhost kinda thing, where the server will get data from. If you have let's say on a Repl in Repl.it, then it will have to get the data from the Repl hosting URL
I have created a Redis cluster with 30 instances (15 masters/ 15 nodes). With python code i connected to these instances, i found the masters and then i wanted to add some keys to them.
def settomasters(port, host):
r = redis.Redis( host=host, port=port )
r.set("key"+port,"value")
Error:
redis.exceptions.ResponseError: MOVED 12539 127.0.0.1:30012
If i try to set key from redis-cli -c -p portofmyinstance sometimes i get a redirection message that tells where the keys stored.
I know that in case of get requests for example, a smart client is needed in order to redirect the requests to the correct node (the node that holds the key) otherwise a moved error occurs. Is it the same situation? I need to catch the redis.exceptions.ResponseError and try to set again?
while True:
try:
r.set("key","value")
break
except:
print "error"
pass
My first try was above code but without solution. The set operation never succeeds.
On the other hand below code in javascript does not throw an error and i cannot figure the reason:
var redis = require('redis-stream'),
client = new redis(30001, '127.0.0.1');
// Open stream
var stream = client.stream();
// Example of setting 200 records
for(var record = 0; record <200; record++) {
var command = ['set', 'qwerty' + record, 'QWERTYUIOP'];
stream.redis.write( redis.parse(command) );
}
stream.on('close', function () {
console.log('Completed!');
});
// Close the stream after batch insert
stream.end();
Any help will be appreciated, thanks.
with a redis cluster you can use the normal redis client only if you "find for the certain key the slot that belongs and then the slots that each master serves. With this information i can set keys to the correct node without moved redirection errors." as #Antonis said. Otherwise you need http://redis-py-cluster.readthedocs.io/en/master/
I'm working on a broadcast e-mail template that would pull the latest three articles off our blog from an RSS feed and insert the relevant sections into the document.
I looked at the documentation, and based on the bit about the File object, some of my own debugging, and an InDesign forum post I've learned that it's not possible to use the File object to source an online XML file.
The alternative (without resorting to an external script, one of which didn't work for me anyways), it seems, is to use the Socket object. So I went back to the documentation and copied/pasted this code verbatim from there:
reply = "";
conn = new Socket;
// access Adobe’s home page
if (conn.open ("www.adobe.com:80")) {
// send a HTTP GET request
conn.write ("GET /index.html HTTP/1.0\n\n");
// and read the server’s reply
reply = conn.read(999999);
conn.close();
}
When I ran it, I received this descriptive error message:
A search for "89858 javascript error" yielded nothing useful.
So I'm stuck. Either Adobe's code sample has an error, or, more likely, there's something wrong on my end. If I had to guess, I'd guess that it's some kind of proxy problem, but I don't know for sure and don't know how to find out.
Can anyone help? The principles of the Socket object make sense to me, but if I can't get even the sample to work, I don't really have anywhere to go with this.
The error above occurs when you return certain objects (XML, Socket) from a function call, but the return values does not get assigned anywhere.
function test() {
var xml = new XML('<test />');
return xml;
}
test();
The above will cause an error. To get around it you have to assign the return value somewhere.
var result = test();
Try to put all collect all function calls result. I am not sure which one causes the error.
var reply = "";
var conn = new Socket;
// access Adobe’s home page
if (conn.open ("www.adobe.com:80")) {
// send a HTTP GET request
var result = conn.write ("GET /index.html HTTP/1.0\n\n");
// and read the server’s reply
reply = conn.read(999999);
var close = conn.close();
}
I'm making a temporary fake API and am trying to set up a simple request response script in node using express.js to achieve this. It's very strraightforward, A request comes in, is validated and, if valid, is merged with a .json template file and the result returned, thus giving the impression the user was successfully created.
app.post('/agent/user', function(req, res){
var responseTemplate = new jsonRequired('post_user');
var errorTemplate = new jsonRequired('post_user_error');
var payload = req.body;
var responseData;
var hasErrors = false;
console.log('Creating new user');
//Recursive Merge from http://stackoverflow.com/a/383245/284695
responseData = new mergeRecursive(responseTemplate,payload);
if(!payload.username){
hasErrors = true;
errorTemplate.errors.username.push('A username is required.');
}
if (hasErrors){
res.send(errorTemplate,422);
}else{
res.send(responseData,200);
}
});
The problem I'm having is that data is persisting between calls. So if I define a username and name[first] in 1 request and just a username in the 2nd one, both requests come back with the name[first] property.
I have a feeling it's something to do with js closures. Unfortunately, every tutorial I find seems to be about making closures, not avoiding them.
It should work like this:
The client POST's username=user1&name[first]=joe&name[last]=bloggs
The Server loads a json file containing a prepopulated user object: e.g.
{"username":"demo","name":{"first":"John","last":"Doe"}...}
mergeRecursive() merges the payload from the POST request over the template object and returns the new object as the POST response text.
The problem is that with every new request, the server is using the result of step 3 in step 2 instead of reloading the .json file.
That mergeRecursive function has the same caveat as jQuery.extend: it modifies the first object sent into it. In fact, you don't even need to use its return value.
You didn't show the code of jsonRequired function (it's not even clear why you've used new when invoking it), but it looks like this function doesn't create a new object each time it's called, instead fetching this object from some outer repository. Obviously, mergeRecursive modifications for it won't be lost after that function ends.
The solution is using your data object for merging. Like this:
var responseData = {};
...
mergeRecursive(responseData, responseTemplate);
mergeRecursive(responseData, payload);
Merging two objects will make this for you.
If your responseTemplate has parameter, which actual request did not have, then you will end up having it there.
Check definition of word merge ;)
While this doesn't resolve the issue I had, I have found a workaround using the cloneextend package available via npm:
$ npm install cloneextend
This allows me to use the following js:
var ce = require('cloneextend');
...
ce.extend(responseData, responseTemplate);
ce.extend(responseData, payload);