From f1042a1c2c0d04b6866997c3d80d0a6ca7dcf715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Wed, 13 Jan 2016 15:54:50 +0000 Subject: [PATCH] fix video blob --- nodejs/database/index.js | 2 ++ nodejs/public/javascripts/mediarecorder.js | 32 +++++++++++++++------- nodejs/public/javascripts/safechat.js | 7 +++-- nodejs/sockets/index.js | 14 +++++++--- 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/nodejs/database/index.js b/nodejs/database/index.js index eab7e60..c54e7b3 100644 --- a/nodejs/database/index.js +++ b/nodejs/database/index.js @@ -6,6 +6,8 @@ module.exports = function() { var pool = mysql.createPool(config); pool.query(fs.readFileSync(__dirname+'/schema.sql').toString()); + if (config.max_allowed_packet) + pool.query("set global max_allowed_packet=?", [config.max_allowed_packet]); return pool; }; diff --git a/nodejs/public/javascripts/mediarecorder.js b/nodejs/public/javascripts/mediarecorder.js index 3fdda75..b57ce2c 100644 --- a/nodejs/public/javascripts/mediarecorder.js +++ b/nodejs/public/javascripts/mediarecorder.js @@ -46,6 +46,14 @@ function MediaStreamRecorder(constraints) { }; ///@} + /// @name private methods + ///@{ + function createURL(data) { + var urlCreator = window.URL || window.webkitURL; + return urlCreator ? urlCreator.createObjectURL(data) : data; + } + ///@} + /// @name internal event handlers ///@{ @@ -95,20 +103,24 @@ function MediaStreamRecorder(constraints) { } /// Get Stream to the Preview - /** @return Stream prepared to be used in a HTML @c src attribute - within a @c audio or @c video tag. */ + /** @return Data URL prepared to be used in a HTML @c src + attribute within a @c audio or @c video tag. */ this.preview = function() { - return window.URL ? window.URL.createObjectURL(stream) : stream; + return createURL(stream); } /// Get Stream to the Recording - /** @return Stream prepared to be used in a HTML @c src attribute - within a @c audio or @c video tag, or to be used in a - HTML @c href attribute in a @c a tag for downloading - the recording. */ - this.recording = function() { - var buff = new Blob(recordedBlobs, {type: 'video/webm'}); - return window.URL ? window.URL.createObjectURL(buff) : buff; + /** @param callback Callback function that will be called with a + data url to be used in a HTML @c src attribute within a + @c audio or @c video tag, or to be used in a HTML @c + href attribute in a @c a tag for downloading the + recording. */ + this.recording = function(callback) { + var reader = new FileReader(); + reader.onload = function(e) { + callback(e.target.result); + } + reader.readAsDataURL(new Blob(recordedBlobs, {type: 'video/webm'})); } /// Start Stream Recording diff --git a/nodejs/public/javascripts/safechat.js b/nodejs/public/javascripts/safechat.js index c96e3a5..465f0f2 100644 --- a/nodejs/public/javascripts/safechat.js +++ b/nodejs/public/javascripts/safechat.js @@ -342,6 +342,7 @@ function guessfilename(mimetype, user, date) { /// Display Image Attachments function attachments(files, id, from, date) { if (files) files.forEach(function(file) { + console.log(file); if (!file.name) file.name = guessfilename(file.type, from, date); var a = document.createElement('a'); a.href = file.content; @@ -373,8 +374,10 @@ var recorder; function done() { if (recorder) { recorder.stop(); - previewfile(recorder.recording(), "video/webm"); - abort(); + recorder.recording(function(data) { + previewfile(data, "video/webm"); + abort(); + }); } } diff --git a/nodejs/sockets/index.js b/nodejs/sockets/index.js index 4f04aba..d03ffd6 100644 --- a/nodejs/sockets/index.js +++ b/nodejs/sockets/index.js @@ -6,12 +6,13 @@ module.exports = function(sql) { console.log("new client"); - function emit(signal, data) { + function emit(signal, data, info) { if (typeof data == 'string') { console.log("<- signal: "+signal+"("+data+")"); } else { console.log("<- signal: "+signal); } + if (info) console.log(info); socket.emit(signal, data); } @@ -28,7 +29,12 @@ module.exports = function(sql) { if (err || !res || !res.length) return emit("fail", "unknown sender"); sql.query("insert into message set ?", {user: msg.user, msg: msg.content}, function(err, result) { - if (err) return emit("fail", "cannot store message"); + if (err) { + if (err.code=='ER_NET_PACKET_TOO_LARGE') + return emit('fail', "message too large", err); + else + return emit("fail", "cannot store message", err); + } sql.query("select * from message, user"+ " where message.id = ? and"+ " message.user = user.name", @@ -55,11 +61,11 @@ module.exports = function(sql) { if (user.name=="safechat") return emit("fail", "user name safechat is reserved"); sql.query("select name, pubkey from user where name = ?", [user.name], function(err, res, flds) { - if (err) return emit('fail', "login failed (db access) - "+err); + if (err) return emit('fail', "login failed (db access)", err); if (!res || res.length==0) { sql.query("insert into user (name, pubkey) values (?,?)", [user.name, user.pubkey], function(err, res, flds) { - if (err) return emit('fail', "create user failed - "+err); + if (err) return emit('fail', "create user failed", err); broadcast("user", { name: user.name, exists: false, pubkey: user.pubkey });