fix video blob

version-1
Marc Wäckerlin 9 years ago
parent 343bdd8c7c
commit f1042a1c2c
  1. 2
      nodejs/database/index.js
  2. 32
      nodejs/public/javascripts/mediarecorder.js
  3. 5
      nodejs/public/javascripts/safechat.js
  4. 14
      nodejs/sockets/index.js

@ -6,6 +6,8 @@ module.exports = function() {
var pool = mysql.createPool(config); var pool = mysql.createPool(config);
pool.query(fs.readFileSync(__dirname+'/schema.sql').toString()); 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; return pool;
}; };

@ -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 /// @name internal event handlers
///@{ ///@{
@ -95,20 +103,24 @@ function MediaStreamRecorder(constraints) {
} }
/// Get Stream to the Preview /// Get Stream to the Preview
/** @return Stream prepared to be used in a HTML @c src attribute /** @return Data URL prepared to be used in a HTML @c src
within a @c audio or @c video tag. */ attribute within a @c audio or @c video tag. */
this.preview = function() { this.preview = function() {
return window.URL ? window.URL.createObjectURL(stream) : stream; return createURL(stream);
} }
/// Get Stream to the Recording /// Get Stream to the Recording
/** @return Stream prepared to be used in a HTML @c src attribute /** @param callback Callback function that will be called with a
within a @c audio or @c video tag, or to be used in a data url to be used in a HTML @c src attribute within a
HTML @c href attribute in a @c a tag for downloading @c audio or @c video tag, or to be used in a HTML @c
the recording. */ href attribute in a @c a tag for downloading the
this.recording = function() { recording. */
var buff = new Blob(recordedBlobs, {type: 'video/webm'}); this.recording = function(callback) {
return window.URL ? window.URL.createObjectURL(buff) : buff; var reader = new FileReader();
reader.onload = function(e) {
callback(e.target.result);
}
reader.readAsDataURL(new Blob(recordedBlobs, {type: 'video/webm'}));
} }
/// Start Stream Recording /// Start Stream Recording

@ -342,6 +342,7 @@ function guessfilename(mimetype, user, date) {
/// Display Image Attachments /// Display Image Attachments
function attachments(files, id, from, date) { function attachments(files, id, from, date) {
if (files) files.forEach(function(file) { if (files) files.forEach(function(file) {
console.log(file);
if (!file.name) file.name = guessfilename(file.type, from, date); if (!file.name) file.name = guessfilename(file.type, from, date);
var a = document.createElement('a'); var a = document.createElement('a');
a.href = file.content; a.href = file.content;
@ -373,8 +374,10 @@ var recorder;
function done() { function done() {
if (recorder) { if (recorder) {
recorder.stop(); recorder.stop();
previewfile(recorder.recording(), "video/webm"); recorder.recording(function(data) {
previewfile(data, "video/webm");
abort(); abort();
});
} }
} }

@ -6,12 +6,13 @@ module.exports = function(sql) {
console.log("new client"); console.log("new client");
function emit(signal, data) { function emit(signal, data, info) {
if (typeof data == 'string') { if (typeof data == 'string') {
console.log("<- signal: "+signal+"("+data+")"); console.log("<- signal: "+signal+"("+data+")");
} else { } else {
console.log("<- signal: "+signal); console.log("<- signal: "+signal);
} }
if (info) console.log(info);
socket.emit(signal, data); socket.emit(signal, data);
} }
@ -28,7 +29,12 @@ module.exports = function(sql) {
if (err || !res || !res.length) return emit("fail", "unknown sender"); if (err || !res || !res.length) return emit("fail", "unknown sender");
sql.query("insert into message set ?", {user: msg.user, msg: msg.content}, sql.query("insert into message set ?", {user: msg.user, msg: msg.content},
function(err, result) { 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"+ sql.query("select * from message, user"+
" where message.id = ? and"+ " where message.id = ? and"+
" message.user = user.name", " message.user = user.name",
@ -55,11 +61,11 @@ module.exports = function(sql) {
if (user.name=="safechat") return emit("fail", "user name safechat is reserved"); if (user.name=="safechat") return emit("fail", "user name safechat is reserved");
sql.query("select name, pubkey from user where name = ?", [user.name], sql.query("select name, pubkey from user where name = ?", [user.name],
function(err, res, flds) { 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) { if (!res || res.length==0) {
sql.query("insert into user (name, pubkey) values (?,?)", sql.query("insert into user (name, pubkey) values (?,?)",
[user.name, user.pubkey], function(err, res, flds) { [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", { broadcast("user", {
name: user.name, exists: false, pubkey: user.pubkey name: user.name, exists: false, pubkey: user.pubkey
}); });

Loading…
Cancel
Save