librelist archives

« back to archive

ConverseJs - sending msg.

ConverseJs - sending msg.

From:
Michał Kosyk
Date:
2014-10-16 @ 09:40
Hi,

I'm trying to make a function that would send a msg from one jid to another
jid. My idea was something like this:

sendMessageTo(sender_jid, recipient_jid, msg_text)

How can i add it to a public API? I understand the spec/converse.js is in
need of adding an "it" function.

i'm trying to figure out how do you use mock and how is the "cur_names"
formated. I think for developers - it would be a great feature to just send
something using a button (in an AngularJs app for example) and a custom
made, bigger chat window with some additional options, text area and
buttons.

So my questions are:

1. How does mock.cur_names works? What is it?
2. How does it() work in your converse plugin?
3. How can i add something in the non-public api and then add it to public
api?

Cheers,
Michał

Re: [conversejs] ConverseJs - sending msg.

From:
Jc Brand
Date:
2014-10-16 @ 10:06
On Thu, Oct 16, 2014 at 11:40:54AM +0200, Michał Kosyk wrote:
>    Hi,
>    I'm trying to make a function that would send a msg from one jid to
>    another jid. My idea was something like this:
>    sendMessageTo(sender_jid, recipient_jid, msg_text)
>    How can i add it to a public API? I understand the spec/converse.js is in
>    need of adding an "it" function.
>    i'm trying to figure out how do you use mock and how is the "cur_names"
>    formated. I think for developers - it would be a great feature to just
>    send something using a button (in an AngularJs app for example) and a
>    custom made, bigger chat window with some additional options, text area
>    and buttons.
>    So my questions are:
>    1. How does mock.cur_names works? What is it?
>    2. How does it() work in your converse plugin?
>    3. How can i add something in the non-public api and then add it to public
>    api?

You're looking in the wrong place. The spec files are Jasmine tests and the
mock file sets up a mock test fixture.

They have nothing to do with converse.js's functionality or API.

The public API is implemented in the converse.js file in the root of the repo,
near the end of the file.

See here:

https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638

The "non-public API" is simply the closure, which stars here:

https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134

To extend any functionality, you'll have to read the code to understand what's
going on. Better yet, step through the code with the debugger, then you'll get
a good idea of the control flow.

Re: [conversejs] ConverseJs - sending msg.

From:
Michał Kosyk
Date:
2014-10-16 @ 10:43
I made a method like this.

It is just next to sendMessageStanza:

sendMessageTo: function(recipient_jid, message){
                var timestamp = (new Date()).getTime();
                var message = $msg({from: converse.connection.jid, to:
recipient_jid, type: 'chat', id: timestamp})
                    .c('body').t(message).up()
                    .c('active', {'xmlns': '
http://jabber.org/protocol/chatstates'});
                converse.connection.send(message);
            },

-----

and in the returned object:

-----

'sendMessage':function (recipient_jid, message){
            converse.sendMessageTo(recipient_jid, message);
        },


The only thing i did is copy the first section of the sendMessageStanza and
just give the recipient_jid. And i get "undefined is not a function. I can
see the function via instance and even by looking in the minified code.

On Thu, Oct 16, 2014 at 12:06 PM, JC Brand <lists@opkode.com> wrote:

> On Thu, Oct 16, 2014 at 11:40:54AM +0200, Michał Kosyk wrote:
> >    Hi,
> >    I'm trying to make a function that would send a msg from one jid to
> >    another jid. My idea was something like this:
> >    sendMessageTo(sender_jid, recipient_jid, msg_text)
> >    How can i add it to a public API? I understand the spec/converse.js
> is in
> >    need of adding an "it" function.
> >    i'm trying to figure out how do you use mock and how is the
> "cur_names"
> >    formated. I think for developers - it would be a great feature to just
> >    send something using a button (in an AngularJs app for example) and a
> >    custom made, bigger chat window with some additional options, text
> area
> >    and buttons.
> >    So my questions are:
> >    1. How does mock.cur_names works? What is it?
> >    2. How does it() work in your converse plugin?
> >    3. How can i add something in the non-public api and then add it to
> public
> >    api?
>
> You're looking in the wrong place. The spec files are Jasmine tests and the
> mock file sets up a mock test fixture.
>
> They have nothing to do with converse.js's functionality or API.
>
> The public API is implemented in the converse.js file in the root of the
> repo,
> near the end of the file.
>
> See here:
>
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
>
> The "non-public API" is simply the closure, which stars here:
>
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134
>
> To extend any functionality, you'll have to read the code to understand
> what's
> going on. Better yet, step through the code with the debugger, then you'll
> get
> a good idea of the control flow.
>

Re: [conversejs] ConverseJs - sending msg.

From:
Jc Brand
Date:
2014-10-16 @ 11:19
On Thu, Oct 16, 2014 at 12:43:56PM +0200, Michał Kosyk wrote:
>    I made a method like this.
>    It is just next to sendMessageStanza:
>    sendMessageTo: function(recipient_jid, message){
>                    var timestamp = (new Date()).getTime();
>                    var message = $msg({from: converse.connection.jid, to:
>    recipient_jid, type: 'chat', id: timestamp})
>                        .c('body').t(message).up()
>                        .c('active', {'xmlns':
>    '[1]http://jabber.org/protocol/chatstates'});
>                    converse.connection.send(message);
>                },
>    -----
>    and in the returned object:
>    -----
>    'sendMessage':function (recipient_jid, message){
>                conve rse.sendMessageTo(recipient_jid, message);
>            },
>    The only thing i did is copy the first section of the sendMessageStanza
>    and just give the recipient_jid. And i get "undefined is not a function. I
>    can see the function via instance and even by looking in the minified
>    code.

You need to put the method on the converse object, you've now put it in the
ChatBoxView Backbone view


>    On Thu, Oct 16, 2014 at 12:06 PM, JC Brand <[2]lists@opkode.com> wrote:
> 
>      On Thu, Oct 16, 2014 at 11:40:54AM +0200, Michał Kosyk wrote:
>      >    Hi,
>      >    I'm trying to make a function that would send a msg from one jid to
>      >    another jid. My idea was something like this:
>      >    sendMessageTo(sender_jid, recipient_jid, msg_text)
>      >    How can i add it to a public API? I understand the spec/converse.js
>      is in
>      >    need of adding an "it" function.
>      >    i'm trying to figure out how do you use mock and how is the
>      "cur_names"
>      >    formated. I think for developers - it would be a great feature to
>      just
>      >    send something using a button (in an AngularJs app for example) and
>      a
>      >    custom made, bigger chat window with some additional options, text
>      area
>      >    and buttons.
>      >    So my questions are:
>      >    1. How does mock.cur_names works? What is it?
>      >    2. How does it() work in your converse plugin?
>      >    3. How can i add something in the non-public api and then add it to
>      public
>      >    api?
> 
>      You're looking in the wrong place. The spec files are Jasmine tests and
>      the
>      mock file sets up a mock test fixture.
> 
>      They have nothing to do with converse.js's functionality or API.
> 
>      The public API is implemented in the converse.js file in the root of the
>      repo,
>      near the end of the file.
> 
>      See here:
>      
[3]https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
> 
>      The "non-public API" is simply the closure, which stars here:
>      
[4]https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134
> 
>      To extend any functionality, you'll have to read the code to understand
>      what's
>      going on. Better yet, step through the code with the debugger, then
>      you'll get
>      a good idea of the control flow.
> 
> References
> 
>    Visible links
>    1. http://jabber.org/protocol/chatstates'}
>    2. mailto:lists@opkode.com
>    3. 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
>    4. 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134

Re: [conversejs] ConverseJs - sending msg.

From:
Michał Kosyk
Date:
2014-10-16 @ 11:37
By "returned object" i meant the converse instance. That's why i had the
question.

On Thu, Oct 16, 2014 at 1:19 PM, JC Brand <lists@opkode.com> wrote:

> On Thu, Oct 16, 2014 at 12:43:56PM +0200, Michał Kosyk wrote:
> >    I made a method like this.
> >    It is just next to sendMessageStanza:
> >    sendMessageTo: function(recipient_jid, message){
> >                    var timestamp = (new Date()).getTime();
> >                    var message = $msg({from: converse.connection.jid, to:
> >    recipient_jid, type: 'chat', id: timestamp})
> >                        .c('body').t(message).up()
> >                        .c('active', {'xmlns':
> >    '[1]http://jabber.org/protocol/chatstates'});
> >                    converse.connection.send(message);
> >                },
> >    -----
> >    and in the returned object:
> >    -----
> >    'sendMessage':function (recipient_jid, message){
> >                conve rse.sendMessageTo(recipient_jid, message);
> >            },
> >    The only thing i did is copy the first section of the
> sendMessageStanza
> >    and just give the recipient_jid. And i get "undefined is not a
> function. I
> >    can see the function via instance and even by looking in the minified
> >    code.
>
> You need to put the method on the converse object, you've now put it in the
> ChatBoxView Backbone view
>
>
> >    On Thu, Oct 16, 2014 at 12:06 PM, JC Brand <[2]lists@opkode.com>
> wrote:
> >
> >      On Thu, Oct 16, 2014 at 11:40:54AM +0200, Michał Kosyk wrote:
> >      >    Hi,
> >      >    I'm trying to make a function that would send a msg from one
> jid to
> >      >    another jid. My idea was something like this:
> >      >    sendMessageTo(sender_jid, recipient_jid, msg_text)
> >      >    How can i add it to a public API? I understand the
> spec/converse.js
> >      is in
> >      >    need of adding an "it" function.
> >      >    i'm trying to figure out how do you use mock and how is the
> >      "cur_names"
> >      >    formated. I think for developers - it would be a great feature
> to
> >      just
> >      >    send something using a button (in an AngularJs app for
> example) and
> >      a
> >      >    custom made, bigger chat window with some additional options,
> text
> >      area
> >      >    and buttons.
> >      >    So my questions are:
> >      >    1. How does mock.cur_names works? What is it?
> >      >    2. How does it() work in your converse plugin?
> >      >    3. How can i add something in the non-public api and then add
> it to
> >      public
> >      >    api?
> >
> >      You're looking in the wrong place. The spec files are Jasmine tests
> and
> >      the
> >      mock file sets up a mock test fixture.
> >
> >      They have nothing to do with converse.js's functionality or API.
> >
> >      The public API is implemented in the converse.js file in the root
> of the
> >      repo,
> >      near the end of the file.
> >
> >      See here:
> >      [3]
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
> >
> >      The "non-public API" is simply the closure, which stars here:
> >      [4]
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134
> >
> >      To extend any functionality, you'll have to read the code to
> understand
> >      what's
> >      going on. Better yet, step through the code with the debugger, then
> >      you'll get
> >      a good idea of the control flow.
> >
> > References
> >
> >    Visible links
> >    1. http://jabber.org/protocol/chatstates'}
> >    2. mailto:lists@opkode.com
> >    3.
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
> >    4.
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134
>

Re: [conversejs] ConverseJs - sending msg.

From:
Jc Brand
Date:
2014-10-16 @ 12:01
On Thu, Oct 16, 2014 at 01:37:05PM +0200, Michał Kosyk wrote:
>    By "returned object" i meant the converse instance. That's why i had the
>    question.

I'm not referring to "sendMessage", I'm referring to "sendMessageTo".

You added it to a view, it must be on the inner/private/closure converse
object.

>    On Thu, Oct 16, 2014 at 1:19 PM, JC Brand <[1]lists@opkode.com> wrote:
> 
>      On Thu, Oct 16, 2014 at 12:43:56PM +0200, Michał Kosyk wrote:
>      >    I made a method like this.
>      >    It is just next to sendMessageStanza:
>      >    sendMessageTo: function(recipient_jid, message){
>      >                    var timestamp = (new Date()).getTime();
>      >                    var message = $msg({from: converse.connection.jid,
>      to:
>      >    recipient_jid, type: 'chat', id: timestamp})
>      >                        .c('body').t(message).up()
>      >                        .c('active', {'xmlns':
>      >    '[1][2]http://jabber.org/protocol/chatstates'});
>      >                    converse.connection.send(message);
>      >                },
>      >    -----
>      >    and in the returned object:
>      >    -----
>      >    'sendMessage':function (recipient_jid, message){
>      >                conve rse.sendMessageTo(recipient_jid, message);
>      >            },
>      >    The only thing i did is copy the first section of the
>      sendMessageStanza
>      >    and just give the recipient_jid. And i get "undefined is not a
>      function. I
>      >    can see the function via instance and even by looking in the
>      minified
>      >    code.
> 
>      You need to put the method on the converse object, you've now put it in
>      the
>      ChatBoxView Backbone view
> 
>      >    On Thu, Oct 16, 2014 at 12:06 PM, JC Brand <[2][3]lists@opkode.com>
>      wrote:
>      >
>      >      On Thu, Oct 16, 2014 at 11:40:54AM +0200, Michał Kosyk wrote:
>      >      >    Hi,
>      >      >    I'm trying to make a function that would send a msg from one
>      jid to
>      >      >    another jid. My idea was something like this:
>      >      >    sendMessageTo(sender_jid, recipient_jid, msg_text)
>      >      >    How can i add it to a public API? I understand the
>      spec/converse.js
>      >      is in
>      >      >    need of adding an "it" function.
>      >      >    i'm trying to figure out how do you use mock and how is the
>      >      "cur_names"
>      >      >    formated. I think for developers - it would be a great
>      feature to
>      >      just
>      >      >    send something using a button (in an AngularJs app for
>      example) and
>      >      a
>      >      >    custom made, bigger chat window with some additional
>      options, text
>      >      area
>      >      >    and buttons.
>      >      >    So my questions are:
>      >      >    1. How does mock.cur_names works? What is it?
>      >      >    2. How does it() work in your converse plugin?
>      >      >    3. How can i add something in the non-public api and then
>      add it to
>      >      public
>      >      >    api?
>      >
>      >      You're looking in the wrong place. The spec files are Jasmine
>      tests and
>      >      the
>      >      mock file sets up a mock test fixture.
>      >
>      >      They have nothing to do with converse.js's functionality or API.
>      >
>      >      The public API is implemented in the converse.js file in the root
>      of the
>      >      repo,
>      >      near the end of the file.
>      >
>      >      See here:
>      >     
>      
[3][4]https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
>      >
>      >      The "non-public API" is simply the closure, which stars here:
>      >     
>      
[4][5]https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134
>      >
>      >      To extend any functionality, you'll have to read the code to
>      understand
>      >      what's
>      >      going on. Better yet, step through the code with the debugger,
>      then
>      >      you'll get
>      >      a good idea of the control flow.
>      >
>      > References
>      >
>      >    Visible links
>      >    1. [6]http://jabber.org/protocol/chatstates'}
>      >    2. mailto:[7]lists@opkode.com
>      >    3.
>      
[8]https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
>      >    4.
>      
[9]https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134
> 
> References
> 
>    Visible links
>    1. mailto:lists@opkode.com
>    2. http://jabber.org/protocol/chatstates'}
>    3. mailto:lists@opkode.com
>    4. 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
>    5. 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134
>    6. http://jabber.org/protocol/chatstates
>    7. mailto:lists@opkode.com
>    8. 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
>    9. 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134

Re: [conversejs] ConverseJs - sending msg.

From:
Michał Kosyk
Date:
2014-10-16 @ 12:07
Oh, now i see! Thanks a lot!

Cheers!

On Thu, Oct 16, 2014 at 2:01 PM, JC Brand <lists@opkode.com> wrote:

> On Thu, Oct 16, 2014 at 01:37:05PM +0200, Michał Kosyk wrote:
> >    By "returned object" i meant the converse instance. That's why i had
> the
> >    question.
>
> I'm not referring to "sendMessage", I'm referring to "sendMessageTo".
>
> You added it to a view, it must be on the inner/private/closure converse
> object.
>
> >    On Thu, Oct 16, 2014 at 1:19 PM, JC Brand <[1]lists@opkode.com>
> wrote:
> >
> >      On Thu, Oct 16, 2014 at 12:43:56PM +0200, Michał Kosyk wrote:
> >      >    I made a method like this.
> >      >    It is just next to sendMessageStanza:
> >      >    sendMessageTo: function(recipient_jid, message){
> >      >                    var timestamp = (new Date()).getTime();
> >      >                    var message = $msg({from:
> converse.connection.jid,
> >      to:
> >      >    recipient_jid, type: 'chat', id: timestamp})
> >      >                        .c('body').t(message).up()
> >      >                        .c('active', {'xmlns':
> >      >    '[1][2]http://jabber.org/protocol/chatstates'});
> >      >                    converse.connection.send(message);
> >      >                },
> >      >    -----
> >      >    and in the returned object:
> >      >    -----
> >      >    'sendMessage':function (recipient_jid, message){
> >      >                conve rse.sendMessageTo(recipient_jid, message);
> >      >            },
> >      >    The only thing i did is copy the first section of the
> >      sendMessageStanza
> >      >    and just give the recipient_jid. And i get "undefined is not a
> >      function. I
> >      >    can see the function via instance and even by looking in the
> >      minified
> >      >    code.
> >
> >      You need to put the method on the converse object, you've now put
> it in
> >      the
> >      ChatBoxView Backbone view
> >
> >      >    On Thu, Oct 16, 2014 at 12:06 PM, JC Brand <[2][3]
> lists@opkode.com>
> >      wrote:
> >      >
> >      >      On Thu, Oct 16, 2014 at 11:40:54AM +0200, Michał Kosyk wrote:
> >      >      >    Hi,
> >      >      >    I'm trying to make a function that would send a msg
> from one
> >      jid to
> >      >      >    another jid. My idea was something like this:
> >      >      >    sendMessageTo(sender_jid, recipient_jid, msg_text)
> >      >      >    How can i add it to a public API? I understand the
> >      spec/converse.js
> >      >      is in
> >      >      >    need of adding an "it" function.
> >      >      >    i'm trying to figure out how do you use mock and how is
> the
> >      >      "cur_names"
> >      >      >    formated. I think for developers - it would be a great
> >      feature to
> >      >      just
> >      >      >    send something using a button (in an AngularJs app for
> >      example) and
> >      >      a
> >      >      >    custom made, bigger chat window with some additional
> >      options, text
> >      >      area
> >      >      >    and buttons.
> >      >      >    So my questions are:
> >      >      >    1. How does mock.cur_names works? What is it?
> >      >      >    2. How does it() work in your converse plugin?
> >      >      >    3. How can i add something in the non-public api and
> then
> >      add it to
> >      >      public
> >      >      >    api?
> >      >
> >      >      You're looking in the wrong place. The spec files are Jasmine
> >      tests and
> >      >      the
> >      >      mock file sets up a mock test fixture.
> >      >
> >      >      They have nothing to do with converse.js's functionality or
> API.
> >      >
> >      >      The public API is implemented in the converse.js file in the
> root
> >      of the
> >      >      repo,
> >      >      near the end of the file.
> >      >
> >      >      See here:
> >      >
> >      [3][4]
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
> >      >
> >      >      The "non-public API" is simply the closure, which stars here:
> >      >
> >      [4][5]
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134
> >      >
> >      >      To extend any functionality, you'll have to read the code to
> >      understand
> >      >      what's
> >      >      going on. Better yet, step through the code with the
> debugger,
> >      then
> >      >      you'll get
> >      >      a good idea of the control flow.
> >      >
> >      > References
> >      >
> >      >    Visible links
> >      >    1. [6]http://jabber.org/protocol/chatstates'}
> >      >    2. mailto:[7]lists@opkode.com
> >      >    3.
> >      [8]
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
> >      >    4.
> >      [9]
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134
> >
> > References
> >
> >    Visible links
> >    1. mailto:lists@opkode.com
> >    2. http://jabber.org/protocol/chatstates'}
> >    3. mailto:lists@opkode.com
> >    4.
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
> >    5.
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134
> >    6. http://jabber.org/protocol/chatstates
> >    7. mailto:lists@opkode.com
> >    8.
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L4638
> >    9.
> 
https://github.com/jcbrand/converse.js/blob/35928308c8ac14f403f213e6c31ea72d0356e543/converse.js#L134
>