[jitsi-dev] Questions about JavaScript in Jitsi Meet


#1

Hey, guys!

I recently wrote a few lines of JavaScript code for Jitsi Meet and I already have a multitude of questions. Please excuse my ignorance!

For starters, I see the following:

for (var channel = 0; channel < this.channels[participant].length; channel++) {
     ...
     change.c('channel', {
                 id: $(this.channels[participant][channel]).attr('id'),
                 endpoint: $(this.channels[participant][channel]).attr('endpoint'),
                 expire: '0'
             });
     ...
}

There are multiple lookups in the array this.channels for the index participant. There are also two lookups in the array this.channels[participant] for the index channel. I can imagine how a state of the art C/C++ or Java compiler with all the time in the world could decide to reduce these but I cannot quite wrap my head around how JavaScript with its time constraint can immediately do anything about these. Do you have insight to share about how JavaScript implementations will optimize the source code above?

And even if V8 is able to optimize the above better than a hand-crafted optimization, am I the only one who finds it a tad unreadable to write this.channels[participant] and this.channels[participant][channel] multiple times?

Secondly, there's $(this.channels[participant][channel]).attr('id'). Is that the same as this.channels[participant][channel].id?

Thirdly, I see the following in libs/colibri/colibri.focus.js at times:

var element = ...
element.c(...
...
element.up();
this.connection.sendIQ(element,...

Are these element.up() before this.connection.sendIQ(element necessary at all? I know they're necessary when one is going to walk and/or modify the DOM tree after them but if there's no such thing after them? I did test and they appear to me to be useless.

Thank you very much,
Lyubomir Marinov


#2

Hi Lubomir,

Hey, guys!

I recently wrote a few lines of JavaScript code for Jitsi Meet and I already
have a multitude of questions. Please excuse my ignorance!

For starters, I see the following:

for (var channel = 0; channel < this.channels[participant].length;
channel++) {
    ...
    change.c('channel', {
                id: $(this.channels[participant][channel]).attr('id'),
                endpoint:
$(this.channels[participant][channel]).attr('endpoint'),
                expire: '0'
            });
    ...
}

And even if V8 is able to optimize the above better than a hand-crafted
optimization, am I the only one who finds it a tad unreadable to write
this.channels[participant] and this.channels[participant][channel] multiple
times?

Yes, I totally agree with you, but most of the code is written this
way. Seems that most of all was too lazy to fix it so far :wink:

Thirdly, I see the following in libs/colibri/colibri.focus.js at times:

var element = ...
element.c(...
element.c(...
...
element.up();
element.up();
this.connection.sendIQ(element,...

Are these element.up() before this.connection.sendIQ(element necessary at
all? I know they're necessary when one is going to walk and/or modify the
DOM tree after them but if there's no such thing after them? I did test and
they appear to me to be useless.

You're right, but eventually I found those up() calls to increase
readability a bit, cause we know at what point of XML structure we
currently are.

Another thing which was stopping from fixing those(at least me) is
that I do not belive in client side focus and I'd rather see Java
based server focus written from scratch.

Best regards,
Pawel

···

On Thu, Jul 17, 2014 at 11:04 PM, Lyubomir Marinov <lyubomir.marinov@jitsi.org> wrote: