simple peer addTracks error thows proccess is not defined - peer

I want to add tracks in my stream with addTrack method and when I call addTrack method throws error
navigator.mediaDevices
.getDisplayMedia({ video: true, audio: true })
.then((stream) => {
peersRef.current.forEach((element) => {
const vidTrack = stream.getVideoTracks()[0];
element.peer.addTrack(
stream.getVideoTracks()[0],
element.peer.streams[0]
);
//console.log(stream.getVideoTracks()[0]);
//console.log(userVideo.current.srcObject.getVideoTracks()[0]);
});
});
when I adding track i got error with my simple-peer
Uncaught ReferenceError: process is not defined
at emitReadable (bundle.js:391846:5)
at onEofChunk (bundle.js:391823:5)
at readableAddChunk (bundle.js:391572:5)
at Readable.push (bundle.js:391558:10)
at bundle.js:397822:44

Related

mDNS on react-native Request failed with status code 500

I am currently working on an IoT project which requires service discovery (I am in the Android side). I decided to use react-native-zeroconf and I encountered a problem.
There is a warning Error: Request failed with status code 500 once I called .scan() method.
I have already added permission into the AndroidManifest file. Thank you in advance.
Edit: remove async from function
export function scanmDNS() {
const zeroconf = new Zeroconf();
zeroconf.scan();
const res = zeroconf.getServices();
console.log({ res });
zeroconf.stop();
}
Object {
"res": Object {},
}
Possible Unhandled Promise Rejection (id: 0):
Error: Request failed with status code 500
createError#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:224752:26
settle#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:224742:25
onloadend#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:224619:15
dispatchEvent#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:33843:31
setReadyState#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:32985:29
__didCompleteResponse#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:32783:29
emit#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:4940:42
__callFunction#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5979:36
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5707:31
__guard#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5933:15
callFunctionReturnFlushedQueue#http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.doji.dojimobileapplication&modulesOnly=false&runModule=true:5706:21
callFunctionReturnFlushedQueue#[native code]
Possible Unhandled Promise Rejection (id: 1):
There are two ways to handle Promises, since you're using async/await syntax your response should use the await keyword also you are wrapping your response in an object which you shouldn't (without assigning it to a property).
const res = await zeroconf.getServices();
console.log(res)
The other way would be
zeroconf.getServices()
.then((res) => {
console.log(res) //do whatever you want to do with your response here
})
.catch((err) => {
console.log(err) //handle errors here.
}
Not sure if this will solve your problem but hope it leads you to your solution :)

React Native: Network error when using axios on local server

I'm new to react-native, I want to fetch some data from my local laravel server, but I fire the mobx action I get the following errors:
Network Error
[Unhandled promise rejection: Error: Network Error]
This is my mobx action (I'm using flow, similar to async/await), I get 'fire' log but after that I get the error above:
listProducts = flow( function*(payload)
{
console.log('fire');
try
{
let response = yield axios.get('http://192.168.1.39:8000/api/products', { params: payload });
this.posts = response.data;
this.pagination = response.data.pagination;
console.log(response);
//return response;
}
catch (error)
{
console.error(error);
throw error;
}
});
As you can see I'm using my local IP instead of localhost, I'm also testing my app on my android device using EXPO connected to the same network as my dev laptop.
Ciao, I can't see errors on your code. Try to follow this guide to handle Unhandled promise rejection. Could help you to find a clue.
In brief the guide suggest to use axios interceptors:
axios.interceptors.response.use(
response => response,
error => {}
)

Run a oneOf validation imperatively?

I'm trying to validate a PATCH request payload for a Todo App that should have at least a text or a value property. I'm doing so in updateTodoValidators. Both properties are optional but at least one must exist (hence the oneOf) and if any exists it must be valid as the validators outside the oneOf indicate.
const validate = (validations) => {
return async (req, res, next) => {
await Promise.all(validations.map(validation => validation.run(req)));
const errors = validationResult(req)
if (errors.isEmpty()) {
return next();
}
res
.status(422)
.json({
payload: {
errors: errors.array()
},
message: "Validation error/s",
error: true
})
}
}
const updateTodoValidators = [
oneOf([
body('text').exists().withMessage('not specified'),
body('value').exists().withMessage('not specified')
]),
body('text').optional().trim().notEmpty().withMessage('cannot be empty'),
body('value').optional().isInt({ min: 1 }).withMessage('must be a valid positive number')
]
app.patch('/todos/:id', validate(updateTodoValidators), async (req, res, next) => { /* Route handler implementation */ })
I was looking into running the validations imperatively as indicated in Running validations imperatively [docs] for code readability purposes. And I discovered that if I have some validations that involve a oneOf my validate() throws with a TypeError saying validation.run is not a function. Bellow is a stack trace detailing the error:
(node:88997) UnhandledPromiseRejectionWarning: TypeError: validation.run is not a function
at Promise.all.validations.map.validation (/Users/alejandro/code/Production/server/validators/validate.js:6:64)
at Array.map (<anonymous>)
at /Users/alejandro/code/Production/server/validators/validate.js:6:35
at Layer.handle [as handle_request] (/Users/alejandro/code/Production/server/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/alejandro/code/Production/server/node_modules/express/lib/router/route.js:137:13)
at loginRequired (/Users/alejandro/code/Production/server/auth/helpers.js:18:24)
at Layer.handle [as handle_request] (/Users/alejandro/code/Production/server/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/alejandro/code/Production/server/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/alejandro/code/Production/server/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/alejandro/code/Production/server/node_modules/express/lib/router/layer.js:95:5)
(node:88997) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:88997) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
So, my question is: Is there any way to run validations imperatively when validations might involve one or more oneOfs?
I ended up doing it manually.
Do a .run() on both param checks. Then validate the _errors property is empty on both.
export const validateTokens = async (req, res, next) => {
// Check to make sure one of the header tokens is set and a UUID
const token1 = await header('token1')
.isUUID()
.run(req);
const token2 = await header('token2')
.isUUID()
.run(req);
// Manual oneOf
if (isEmpty(token1._errors) || isEmpty(token2._errors)) {
return next();
}
// Return error results
res.status(400).send('Must include either token1 or token2');
};
oneOf returns a middleware instance, not a validation chain. It doesn't have a .run() function which your customer middleware validator uses to validate hence it is erroring out.
There is an open issue for this here
For the moment I think you would need to implement you own custom function to validate these conditional parameters.

Unable to connect to MongoDB Atlas using Mongoose in Express

I am trying to connect to MongoDB atlas using mongoose but always get an error,
I have tried to change my ip address and also try to change the link
also change all the settings in mongoDB altas but always get the same error
const express = require('express')
const graphqlHTTP = require('express-graphql')
const app = express()
const catSchema = require('./Schema/categorySchema')
const mongoose = require('mongoose')
// SetUp MongoDB
mongoose.connect('mongodb+srv://khawar111:khawar111#e-selling-bh1wv.mongodb.net/test?retryWrites=true&w=majority', { useNewUrlParser: true })
mongoose.connection.once('open', () => {
console.log('Database Connected')
})
mongoose.connection.on('error', (e) => {
console.log(e)
})
// Set Route for GraphQL
app.use('/graphQL', graphqlHTTP({
schema: catSchema,
graphiql: true
})
)
app.listen(3000, () => {
console.log('Server Started')
})
Error:
Error: queryTxt ETIMEOUT e-selling-bh1wv.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19) {
errno: 'ETIMEOUT',
code: 'ETIMEOUT',
syscall: 'queryTxt',
hostname: 'e-selling-bh1wv.mongodb.net'
}
(node:25313) UnhandledPromiseRejectionWarning: Error: queryTxt ETIMEOUT e-selling-bh1wv.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19)
(node:25313) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:25313) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Actually,you need to remove " test?retryWrites=true&w=majority " from your connection string and replace it with the name of your database.Like this
mongoose.connect('mongodb+srv://khawar111:khawar111#e-selling-bh1wv.mongodb.net/DatabaseName', { useNewUrlParser: true })
this is because "test?retryWrites=true&w=majority" is used for testing purposes
Make sure to change the node version to 2.2.12
And add IP address like below:
I faced the issue and I try to find the answer but nothing works then after some time it works normally again . I think it is just a connection limit issue.

Uncaught exception causes app crash in Sails JS ~0.12.11

Error is:
event.js line number 160
Unhandled exception.
This error occured after an error was unhandled by utils.js
Due to Error: write EPROTO 139889615579008:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:794:
App crashes immediately.
function: (req, res, next) {
var domain = require('domain');
var d = domain.create();
d.on('error', function(er) {});
d.add(req);
d.add(res);
d.run(function() {
next();
});
}
Adding this to a common function used in config/http.js worked.