fix video blob

version-1
Marc Wäckerlin 8 years ago
parent 343bdd8c7c
commit f1042a1c2c
  1. 2
      nodejs/database/index.js
  2. 32
      nodejs/public/javascripts/mediarecorder.js
  3. 7
      nodejs/public/javascripts/safechat.js
  4. 14
      nodejs/sockets/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;
};

@ -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

@ -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();
});
}
}

@ -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
});

Loading…
Cancel
Save