Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function wsConnection(ws) {
console.log('Connection: ', ws.upgradeReq.url);
var url = ws.upgradeReq.url;
var base = url.split('?')[0];
var parts = base.split('/');
console.log(parts);
// strip off websockets/ from the path
parts.shift();
ws.docId = Base62.decode(parts[1]);
if (parts[2] !== 'edit' && parts[2] !== 'view') {
return;
}
// Helper Functions
ws.sendJSON = function(json) {
this.send(JSON.stringify(json), function(err) {
if (err) {
console.error('WS ERROR', err);
}
});
};
ws.error = function(msg) {
ws.sendJSON({
type: 'error',
reason: msg