@@ -16,15 +16,32 @@ export default {
1616 isSupported : 'VideoFrame' in window ,
1717 } ;
1818 } ,
19- created ( ) {
20- this . worker = new DecoderWorker ( ) ;
19+ expose : [ '' ] ,
20+ methods : {
21+ cleanup ( ) {
22+ if ( this . worker ) {
23+ this . worker . terminate ( ) ;
24+ }
25+
26+ // unsub trame.rca.topic.stream
27+ if ( this . wslinkSubscription ) {
28+ if ( this . trame ) {
29+ this . trame . client
30+ . getConnection ( )
31+ . getSession ( )
32+ . unsubscribe ( this . wslinkSubscription ) ;
33+ this . wslinkSubscription = null ;
34+ }
35+ }
36+ } ,
2137 } ,
2238 mounted ( ) {
39+ this . worker = new DecoderWorker ( ) ;
2340 if ( this . isSupported ) {
2441 const canvas = this . $el . querySelector ( '.js-canvas' ) ;
2542 this . worker . bindCanvas ( canvas ) ;
2643
27- this . onChunkAvailable = ( [ { name, meta, content } ] ) => {
44+ this . onChunkAvailable = async ( [ { name, meta, content } ] ) => {
2845 // when we do not get octet-stream or valid codec, terminate worker.
2946 if (
3047 ! meta . type . includes ( 'application/octet-stream' ) ||
@@ -36,9 +53,10 @@ export default {
3653
3754 if ( this . name === name && meta . codec . length ) {
3855 this . worker . setContentType ( meta . codec , meta . w , meta . h ) ;
39- content . arrayBuffer ( ) . then ( ( data ) => {
40- this . worker . pushChunk ( meta . st , meta . key , data ) ;
41- } ) ;
56+ const data = content . buffer
57+ ? content
58+ : new Uint8Array ( await content . arrayBuffer ( ) ) ;
59+ this . worker . pushChunk ( meta . st , meta . key , data ) ;
4260 }
4361 } ;
4462
@@ -50,23 +68,12 @@ export default {
5068 }
5169 }
5270 } ,
71+ // support both vue2 and vue3 unmount callbacks
5372 beforeUnmount ( ) {
54- if ( this . worker ) {
55- this . worker . terminate ( ) ;
56- this . worker = null ;
57- }
58-
59- // unsub trame.rca.topic.stream
60- if ( this . wslinkSubscription ) {
61- if ( this . trame ) {
62- this . trame . client
63- . getConnection ( )
64- . getSession ( )
65- . unsubscribe ( this . wslinkSubscription ) ;
66- this . wslinkSubscription = null ;
67- }
68- this . destroyDecoder ( ) ;
69- }
73+ this . cleanup ( ) ;
74+ } ,
75+ beforeDestroy ( ) {
76+ this . cleanup ( ) ;
7077 } ,
7178 inject : [ 'trame' , 'rcaPushSize' ] ,
7279 template : `
0 commit comments