Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.connection.onmessage = (e) => {
try {
// console.log('received', e.data, e.target.readyState);
const data = EJSON.parse(e.data);
this.emit(data.msg, data);
return data.collection && this.emit(data.collection, data);
} catch (err) {
log('EJSON parse', err);
}
};
});
Device.prototype.parseMessage = function(message) {
// Attempt to parse the message.
try { message = EJSON.parse(message.toString()); }
catch(e) { return null; }
// The message has to be something.
if(!message) {
return null;
}
return message;
};
export const onNotification = (notification) => {
if (notification) {
const data = notification.getData();
if (data) {
try {
const { rid, name, sender, type, host } = EJSON.parse(data.ejson);
const types = {
c: 'channel',
d: 'direct',
p: 'group'
};
const roomName = type === 'd' ? sender.username : name;
const params = {
host,
rid,
path: `${types[type]}/${roomName}`
};
store.dispatch(deepLinkingOpen(params));
} catch (e) {
console.warn(e);
export const onNotification = (notification) => {
if (notification) {
const data = notification.getData();
if (data) {
try {
const {
rid, name, sender, type, host
} = EJSON.parse(data.ejson);
const types = {
c: 'channel', d: 'direct', p: 'group'
};
const roomName = type === 'd' ? sender.username : name;
const params = {
host,
rid,
path: `${ types[type] }/${ roomName }`
};
store.dispatch(deepLinkingOpen(params));
} catch (e) {
console.warn(e);
}
}
exports.decoder = function decoder(data, fn) {
var err;
try { data = EJSON.parse(data); }
catch (e) { err = e; }
fn(err, data);
};
const parse = function(serialized) {
if (serialized === undefined || serialized === 'undefined') return undefined;
return EJSON.parse(serialized);
};
const handleNotification = (notification) => {
if (notification.usernInteraction) {
return;
}
const { rid, name } = EJSON.parse(notification.ejson);
return rid && name && goRoom({ rid, name });
};
PushNotification.configure({
return new Promise((resolve, reject) => {
let c = typeof data === 'string' ? EJSON.parse(data) : data;
let totalDocuments = 0;
Object.keys(c).forEach((collection)=>{
totalDocuments += Array.isArray(c[collection]) ? c[collection].length : 0;
});
let counter = 0;
let uniqueId = this._id+"-"+this._opGenId();
const listener = this.on('added',(m,id)=>{
if (id == uniqueId) {
counter++;
if (counter==totalDocuments) {
listener.stop();
resolve();
}
onData(msg) {
log.trace(msg);
try {
msg = EJSON.parse(msg);
if (msg.msg === "changed" && msg.collection === "stream-room-messages") {
try {
msg.fields.args.forEach(this.onMessage.bind(this));
} catch (e) {
log.error(e.stack || e);
}
}
} catch (ignored) {}
}
mockServer.on('message', message => {
const data = EJSON.parse(message);
this.mockMessageResponse(mockServer, data);
});
});