@@ -232,6 +232,11 @@ const FORMAT_TAGS = {
232
232
md_tag : undefined ,
233
233
isVoid : false
234
234
} ,
235
+ VD : {
236
+ html_tag : 'video' ,
237
+ md_tag : undefined ,
238
+ isVoid : false
239
+ }
235
240
} ;
236
241
237
242
// Convert base64-encoded string into Blob.
@@ -434,6 +439,26 @@ const DECORATORS = {
434
439
} ;
435
440
}
436
441
} ,
442
+ // Video.
443
+ VD : {
444
+ open : ( data ) => {
445
+ const url = data . ref || base64toObjectUrl ( data . val , data . mime , Drafty . logger ) ;
446
+ return '<video controls src="' + url + '">' ;
447
+ } ,
448
+ close : _ => '</video>' ,
449
+ props : ( data ) => {
450
+ if ( ! data ) return null ;
451
+ return {
452
+ // Embedded data or external link.
453
+ src : data . ref || base64toObjectUrl ( data . val , data . mime , Drafty . logger ) ,
454
+ 'data-preload' : data . ref ? 'metadata' : 'auto' ,
455
+ 'data-duration' : data . duration ,
456
+ 'data-name' : data . name ,
457
+ 'data-size' : data . val ? ( ( data . val . length * 0.75 ) | 0 ) : ( data . size | 0 ) ,
458
+ 'data-mime' : data . mime ,
459
+ } ;
460
+ }
461
+ } ,
437
462
} ;
438
463
439
464
/**
@@ -726,6 +751,80 @@ Drafty.insertImage = function(content, at, imageDesc) {
726
751
return content ;
727
752
}
728
753
754
+ /**
755
+ * @typedef Drafty.VideoDesc
756
+ * @memberof Drafty
757
+ * @type Object
758
+ * @param {string } mime - mime-type of the video, e.g. "video/mpeg"
759
+ * @param {string } preview - base64-encoded video content (or preview, if large video is attached). Could be null/undefined.
760
+ * @param {integer } width - width of the video
761
+ * @param {integer } height - height of the video
762
+ * @param {integer } duration - duration of the video.
763
+ * @param {string } filename - file name suggestion for downloading the video.
764
+ * @param {integer } size - size of the video in bytes. Treat is as an untrusted hint.
765
+ * @param {string } refurl - reference to the content. Could be null/undefined.
766
+ * @param {string } _tempPreview - base64-encoded image preview used during upload process; not serializable.
767
+ * @param {Promise } urlPromise - Promise which returns content URL when resolved.
768
+ */
769
+
770
+ /**
771
+ * Insert inline image into Drafty document.
772
+ * @memberof Drafty
773
+ * @static
774
+ *
775
+ * @param {Drafty } content - document to add video to.
776
+ * @param {integer } at - index where the object is inserted. The length of the video is always 1.
777
+ * @param {VideoDesc } videoDesc - object with video paramenets and data.
778
+ *
779
+ * @return {Drafty } updated document.
780
+ */
781
+ Drafty . insertVideo = function ( content , at , videoDesc ) {
782
+ content = content || {
783
+ txt : ' '
784
+ } ;
785
+ content . ent = content . ent || [ ] ;
786
+ content . fmt = content . fmt || [ ] ;
787
+
788
+ content . fmt . push ( {
789
+ at : at | 0 ,
790
+ len : 1 ,
791
+ key : content . ent . length
792
+ } ) ;
793
+
794
+ const ex = {
795
+ tp : 'VD' ,
796
+ data : {
797
+ mime : videoDesc . mime ,
798
+ val : videoDesc . preview ,
799
+ width : videoDesc . width ,
800
+ height : videoDesc . height ,
801
+ name : videoDesc . filename ,
802
+ size : videoDesc . size | 0 ,
803
+ ref : videoDesc . refurl
804
+ }
805
+ } ;
806
+
807
+ if ( videoDesc . urlPromise ) {
808
+ ex . data . _tempPreview = videoDesc . _tempPreview ;
809
+ ex . data . _processing = true ;
810
+ videoDesc . urlPromise . then (
811
+ url => {
812
+ ex . data . ref = url ;
813
+ ex . data . _tempPreview = undefined ;
814
+ ex . data . _processing = undefined ;
815
+ } ,
816
+ _ => {
817
+ // Catch the error, otherwise it will appear in the console.
818
+ ex . data . _processing = undefined ;
819
+ }
820
+ ) ;
821
+ }
822
+
823
+ content . ent . push ( ex ) ;
824
+
825
+ return content ;
826
+ }
827
+
729
828
/**
730
829
* @typedef Drafty.AudioDesc
731
830
* @memberof Drafty
@@ -830,7 +929,7 @@ Drafty.videoCall = function() {
830
929
*
831
930
* @returns the same document with update applied.
832
931
*/
833
- Drafty . updateVideoEnt = function ( content , params ) {
932
+ Drafty . updateVideoCall = function ( content , params ) {
834
933
// The video element could be just a format or a format + entity.
835
934
// Must ensure it's the latter first.
836
935
const fmt = ( ( content || { } ) . fmt || [ ] ) [ 0 ] ;
0 commit comments