dvoina / imsdroid

Automatically exported from code.google.com/p/imsdroid
0 stars 0 forks source link

Which method of MsrpSession should I call for sending a chat message? #119

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.How to call sendLMessage method of MsrpSession class to send a chat message ?
2.sendLMessage(byte[] payload, String ContentType) of MyMsrpSession class is 
not finished,could you give me a code or pseudocode for showing how to call 
method of MsrpSession class in order to finish a chat?
3.I see sendFile method of MyMsrpSession class calls 
callMsrp(actionConfig).Chat message ,such as "Hello Alice!",How should I pass 
"Hello Alice!",ActionConfig only have setMediaString and setMediaInt method.
By the way,please describe callMsrp,sendLMessage and sendFile method of 
MsrpSession class,including overload version.Specially,sendLMessage() have no 
argument and how to pass payload:byte[] ("Hello Alice!")?

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
IMSDroid 1.1.327  ,on Android 2.2

Please provide any additional information below.

For example,I want to send Request Message as follow
---------------------------------------------------------------------------
INVITE sip:192.168.253.3 SIP/2.0
To: <tel:+8521341041108>
From: <sip:nemo@ims.chinamobile.com>;tag=fy8bsg8q-6i
Call-ID: 10.170.32.117_83_5516001569175573513
CSeq: 1 INVITE
Max-Forwards: 64
Content-Length: 442
Via: SIP/2.0/TCP 
10.170.32.11:5062;branch=z9hG4bK4b9e42f6fd4df179310c943a4054d663jaaaaaaiaaaaaafo
ml5ha3Zqkv7fc433vmcw5fuja
Record-Route: 
<sip:3Zqkv7%0BaGqh4aaaadysip%3Asimba%40ims.chinamobile.com@pcscf.ims.chinamobile
.com:5060;maddr=10.170.32.11;lr>
Contact: 
<sip:10.170.32.117:5065;transport=tcp;fid=imsm_instance_PL_2_4_1>;+g.oma.sip-im
Content-Type: application/sdp
Allow: INVITE, ACK, BYE, CANCEL
Accept-Contact: *;+g.oma.sip-im
Supported: timer
Require: pref
Subject:Hello
P-Asserted-Identity: sip:nemo@ims.chinamobile.com
P-Asserted-Identity: tel:+8521341041107
Min-SE: 3600
P-Access-Network-Info: 3GPP-UTRAN-FDD;utran-cell-id-3gpp=2620209329320065
User-Agent: IM-Serv/OMA1.0/v3.0_IMSM_R1C02
Session-Expires: 3600;refresher=uac
P-Called-Party-ID: <sip:simba@ims.chinamobile.com>

v=0
o=- 1250012797 1250012797 IN IP4 10.170.32.117
s=none
c=IN IP4 10.170.32.117
t=0 0
m=message 4000 TCP/MSRP *
a=accept-types:message/cpim;text/plain;charset=UTF-8;application/im-iscomposing+
xml;image/png;image/x-png;image/jpeg;image/gif;audio/mpeg;audio/x-mpeg;audio/mid
i;x-music/x-midi;audio/wav;audio/x-wav;video/3gpp;video/mp4
a=path:msrp://10.170.32.117:4000/VL1SmRjx0qhi;tcp
a=sendrecv
a=max-size:51200
a=setup:active
a=connection:new
---------------------------------------------------------------------------

Response message as follow
---------------------------------------------------------------------------
SIP/2.0 200 OK
Via: SIP/2.0/TCP 
10.170.32.11:5062;branch=z9hG4bK4b9e42f6fd4df179310c943a4054d663jaaaaaaiaaaaaafo
ml5ha3Zqkv7fc433vmcw5fuja
Record-Route: 
<sip:3Zqkv7%0BaGqh4aaaadysip%3Asimba%40ims.chinamobile.com@pcscf.ims.chinamobile
.com:5060;maddr=10.170.32.11;lr>
From: <sip:nemo@ims.chinamobile.com>;tag=fy8bsg8q-6i
To: <tel:+8521341041108>;tag=2604935847
Call-ID: 10.170.32.117_83_5516001569175573513
CSeq: 1 INVITE
Contact: <sip:192.168.253.3>;+g.oma.sip-im
P-Access-Network-Info: 3GPP-UTRAN-FDD;utran-cell-id-3gpp=2620209329320065
Content-Length: 437
Content-Type: application/sdp
Allow: INVITE,OPTIONS,BYE,CANCEL,ACK,SUBSCRIBE,NOTIFY,PUBLISH,MESSAGE,REFER
Session-Expires: 3600;refresher=uac
Supported: timer
Require: timer
Server: SEMC_IMS_R3

v=0
o=- 1250012847 1250012847 IN IP4 192.168.253.3
s=none
c=IN IP4 192.168.253.3
t=0 0
m=message 4322 TCP/MSRP *
a=accept-types:message/cpim;text/plain;charset=UTF-8;application/im-iscomposing+
xml;image/png;image/x-png;image/jpeg;image/gif;audio/mpeg;audio/x-mpeg;audio/mid
i;x-music/x-midi;audio/wav;audio/x-wav;video/3gpp;video/mp4
a=sendrecv
a=max-size:51200
a=connection:new
a=path:msrp://192.168.253.3:4322/1314866162;tcp
---------------------------------------------------------------------------

MSRP SEND message as follow
---------------------------------------------------------------------------
MSRP 466215851 SEND
To-Path: msrp://192.168.245.23:4000/amFDknQZ7OIi;tcp
From-Path: msrp://192.168.245.235:59962/1811611648;tcp
Message-ID: ZdmAg13857-ID00000005-H12M011S2
Byte-Range: 1-9/9
Success-Report: no
Failure-Report: yes
Content-Type: text/plain;charset=utf-8

Hi buddy!
-------466215851$
---------------------------------------------------------------------------

MSRP response message as follow
---------------------------------------------------------------------------
MSRP 466215851 200 OK
To-Path: msrp://192.168.245.235:59962/1811611648;tcp
From-Path: msrp://192.168.245.23:4000/amFDknQZ7OIi;tcp
-------466215851$
---------------------------------------------------------------------------

Original issue reported on code.google.com by yuwenbin...@gmail.com on 9 Dec 2010 at 7:21

GoogleCodeExporter commented 9 years ago
In addition,I captured the SIP/SDP message package by using Wireshark and find 
that "o=doubango 1983 678901 IN IP4 10.0.2.15".I want to set "o=- 1983 678901 
IN IP4 10.0.2.15",how to do it?

Original comment by yuwenbin...@gmail.com on 9 Dec 2010 at 8:25

GoogleCodeExporter commented 9 years ago
First update the source code to SVN revision 343.
sendLMessage() is now implemented.
To achieve your workflow:

 // establish an MSRP session
        ActionConfig sessionConfig = new ActionConfig();
        MyMsrpSession msrpSession = MyMsrpSession.createOutgoingSession(sipStack, MediaType.Chat);
        sessionConfig.addHeader("Subject","Hello");
        msrpSession.session.callMsrp("+8521341041108", sessionConfig);
        sessionConfig.delete();

        // Once the session is established
        if(msrpSession.isConnected())
        {
            byte[] content = "Hi buddy!".getBytes();
            final ByteBuffer payload = ByteBuffer.allocateDirect(content.length);
            payload.put(content);

            ActionConfig messageConfig = new ActionConfig();
            messageConfig.setMediaString(twrap_media_type_t.twrap_media_msrp, "content-type", "text/plain;charset=utf-8");
            msrpSession.session.sendMessage(payload, (long)payload.capacity(), messageConfig);
        }

Original comment by boss...@yahoo.fr on 9 Dec 2010 at 4:34

GoogleCodeExporter commented 9 years ago
Thank you for your help!

Original comment by yuwenbin...@gmail.com on 9 Dec 2010 at 5:10

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Dear  yuwenbin...@gmail.com is the  code  of  chat messaging work ?
Please answer .
It's only call and doesn't send message .
Please help .

Original comment by Arian.Sa...@gmail.com on 13 Feb 2011 at 7:41

GoogleCodeExporter commented 9 years ago
Yes,the code works.establish an MSRP session and send MSRP message must be 
asynchronous 

Original comment by Splash.P...@gmail.com on 15 Feb 2011 at 3:15

GoogleCodeExporter commented 9 years ago
Thanks for your answer,but I have some difficults.
I want to know except the code of top and the changes of revision 343,there are 
not any changes in the  other part of imsdroid project or there is no any 
additional code which you didnn't write here.
Please help.I have already some days trying this ,but widthout any result.

Original comment by Arian.Sa...@gmail.com on 16 Feb 2011 at 2:19

GoogleCodeExporter commented 9 years ago
(msrpSession.isConnected()) its always return false .

Original comment by Arian.Sa...@gmail.com on 16 Feb 2011 at 2:44

GoogleCodeExporter commented 9 years ago

            byte[] content = "Hi buddy!".getBytes();
            final ByteBuffer payload = ByteBuffer.allocateDirect(content.length);
            payload.put(content);

            ActionConfig messageConfig = new ActionConfig();
            messageConfig.setMediaString(twrap_media_type_t.twrap_media_msrp, "content-type", "text/plain;charset=utf-8");
            msrpSession.session.sendMessage(payload, (long)payload.capacity(), messageConfig);

These code MUST be put when receiving 200OK(SIP).
for example,in SipService::OnInviteEvent method.

establish an MSRP session and send MSRP message must be asynchronous,this is 
very importment.

Original comment by Splash.P...@gmail.com on 16 Feb 2011 at 3:23

GoogleCodeExporter commented 9 years ago

If it isn't difficult for you please write down the whole 
SipService::OnInviteEvent method.
Please .
Thanks in advance.

Original comment by Arian.Sa...@gmail.com on 16 Feb 2011 at 4:24

GoogleCodeExporter commented 9 years ago
No problem.But you have to wait 2 days.

Original comment by Splash.P...@gmail.com on 16 Feb 2011 at 4:37

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
addition.
Dear Splash.P...@gmail.com
Please write here any changes you done in your project for imsdroid chat 
messaging 
Thanks in advance .I will wait.
It's very important for me.

Original comment by Arian.Sa...@gmail.com on 17 Feb 2011 at 12:50

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Dear Splash.P...@gmail.com please answer is it possible to have 
SipService::OnInviteEvent method tomorrow(on Friday)?

Original comment by Arian.Sa...@gmail.com on 17 Feb 2011 at 7:11

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Dear everybody
why the ruturn value is always "false" for follow funtion:
tinyWRAPJNI.MsrpSession_sendMessage__SWIG_0(swigCPtr, this, payload, len, 
ActionConfig.getCPtr(config), config);

Original comment by sundl2...@gmail.com on 18 Feb 2011 at 11:14

GoogleCodeExporter commented 9 years ago
public int OnInviteEvent(InviteEvent e) {
            short code = e.getCode();
            String phrase = e.getPhrase();
            tsip_invite_event_type_t type = e.getType();
            //SipMessage message = e.getSipMessage();
            InviteSession session = e.getSession();
            session.accept();
            ChatService cs = ChatService.getChatService();
            if(code > 399 && code < 500){
                Log.d("MSRP_TEST","xxx");
            }
            if(code == 200 && session!=null){
                if(cs.sendMessage("Hello World!")){
                    Log.d("MSRP_TEST","sendMessage Hello World! true!");
                }
                else{
                    Log.d("MSRP_TEST","sendMessage Hello World! false!");
                }

            }

Original comment by Splash.P...@gmail.com on 18 Feb 2011 at 12:28

GoogleCodeExporter commented 9 years ago
public boolean sendMessage(String messageBody){
        Log.d("MSRP_TEST","msrpSession ID-->"+msrpSession.getId());
        if(!msrpSession.isConnected()){
            Log.d("MSRP_TEST","msrpSession is not connected");
            msrpSession.setConnected(true);
            //return false;
        }

        if(msrpSession.isConnected()){
            Log.d("MSRP_TEST","msrpSession is connected");
        }

            byte[] content = messageBody.getBytes();
            final ByteBuffer payload = ByteBuffer.allocateDirect(content.length);
            payload.put(content);

            ActionConfig messageConfig = new ActionConfig();
            messageConfig.setMediaString(twrap_media_type_t.twrap_media_msrp, "Content-Type", "text/plain;charset=utf-8");
            if(msrpSession.session.sendMessage(payload, (long)payload.capacity(), messageConfig)){
                Log.d("MSRP_TEST",messageBody+" MSRP message send!");
                return true;
            }
            else{
                Log.d("MSRP_TEST",messageBody+" MSRP message send error!");
                return false;
            }

    }

Original comment by Splash.P...@gmail.com on 18 Feb 2011 at 12:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thank you very much. 
but in onInviteEvent method the code's value always equals to 100 and
it is not become 200.
Can you say what can be the reason? or I do smth. wrong.
Please answer.

Original comment by Arian.Sa...@gmail.com on 18 Feb 2011 at 2:16

GoogleCodeExporter commented 9 years ago
Issue 142 has been merged into this issue.

Original comment by boss...@yahoo.fr on 18 Feb 2011 at 2:36

GoogleCodeExporter commented 9 years ago
If you want help you should send network trace (wireshark) and provide more 
information:
Which client are you using on the remote side?
Are you using a real device or the emulator?
BTW the code I provided in comment 2 should work without any problem.

Original comment by boss...@yahoo.fr on 18 Feb 2011 at 2:38

GoogleCodeExporter commented 9 years ago
A Invite B,then B receive a INVITE message.B accept this INVITE and 200 OK will 
be sent.

Original comment by Splash.P...@gmail.com on 18 Feb 2011 at 2:47

GoogleCodeExporter commented 9 years ago
I am running project on emulator and I use x-lite4.
But can  an emulator be the reason of my problem?
Thanks in advance.

Original comment by Arian.Sa...@gmail.com on 18 Feb 2011 at 2:55

GoogleCodeExporter commented 9 years ago
It will not work on the emultor as the ip address is not routable and I don't 
think that xlite support MSRP.

Original comment by boss...@yahoo.fr on 18 Feb 2011 at 2:59

GoogleCodeExporter commented 9 years ago
You are wrong.It may work on the emultor.I ever used two emultor(run 
IMSDroid).chat message may be received.

Original comment by Splash.P...@gmail.com on 18 Feb 2011 at 4:05

GoogleCodeExporter commented 9 years ago
OK if "Splash.P...@gmail.com" say it. He is the expert ;)
@Arian.Sa...@gmail.com: Issue 142 has been merged into this issue so you don't 
need to always send on both.

Original comment by boss...@yahoo.fr on 18 Feb 2011 at 4:17

GoogleCodeExporter commented 9 years ago
Hi Everybody.
I want to know how to get the reiceved message(incoming message)
someone can write the code or a attach a file of getting incoming message?

Original comment by timeandr...@time.com on 18 Feb 2011 at 7:02

GoogleCodeExporter commented 9 years ago
Please help me.
I want to know in OnInviteEvent method we must call sendMessage method and in 
the same onInviteEvent method we must call a takeIncomingSession method.
and in which cases they  called
Pleease write smth here.

Original comment by timeandr...@time.com on 19 Feb 2011 at 5:34

GoogleCodeExporter commented 9 years ago
Please write smth Dear Splash.P...@gmail.com and Dear  boss...@yahoo.fr.
I am waiting to Your answer.

Original comment by timeandr...@time.com on 20 Feb 2011 at 3:11

GoogleCodeExporter commented 9 years ago
Thanks  Splash.P...@gmail.com and boss...@yahoo.fr for help.

Original comment by Arian.Sa...@gmail.com on 20 Feb 2011 at 4:04

GoogleCodeExporter commented 9 years ago
Now I can send message  and I have the same question in onInviteEvent method in 
which case I will add takeIncomingSession() method .
Please answer I have already work on chat messaging very long time.
Thanks in advance.

Original comment by Arian.Sa...@gmail.com on 20 Feb 2011 at 6:40

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I can't send message
when the code=200,I call the sendMessage() method of ChatService's class,then 
call the  method msrpSession.session.sendMessage(payload, 
(long)payload.capacity(), messageConfig)) that in the MrspSession class 
,finally,call tinyWRAPJNI.MsrpSession_sendMessage__SWIG_0(swigCPtr, this, 
payload, len, ActionConfig.getCPtr(config), config). 
but the function of tinyWRAPJNI.MsrpSession_sendMessage__SWIG_0 is always 
return false
Please answer what reason for it?

Original comment by sundl2...@gmail.com on 21 Feb 2011 at 3:46

Attachments:

GoogleCodeExporter commented 9 years ago
Dear Splash.P...@gmail.com
why the ims client can't accept the message when i send a message?
please help

Original comment by sundl2...@gmail.com on 21 Feb 2011 at 8:20

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
@timeandr...@time.com
First, you should know that MSRP messaging is not officially supported in 
IMSDroid. However, you have all functions you need to implement a chat client 
as per RFC 4975. The best way to get started is to see how file transfer (MSRP) 
is implemented in IMSDroid. You can also checkout the source of Boghe 
(http://code.google.com/p/boghe) which support MSRP messaging and uses the same 
API (Doubango).

You don't need to call sendMessage() in OnInviteEvent().
- OnInviteEvent() is a callbak function called from the native code (Doubango) 
to the managed (imsdroid). This function is called to notify you about the 
incoming/outgoing messages associated to this session. You should also see 
OnDialogEvent() which monitor the sip session state 
(connecting,connected,terminating,terminated).
- takeIncomingSession() is used to take a reference to the session otherwise it 
will be destroyed by the garbage collector if the reference count reach zero. 
This function will also add the session to a static map to allow you to 
retrieve it from any function in your code.
- sendMessage() is called to send a MSRP message. This function will only 
succeed if the session is connected (mSession.isConnected()). The session state 
is set to "connected" by OnDialogEvent() callback when you receive 200 INVITE 
response.

Last and not least: To get help you MUST attach both network (Wireshark) and 
device logs (DDMS). Doubango log tag: "tinyWRAP".

Original comment by boss...@yahoo.fr on 21 Feb 2011 at 8:40

GoogleCodeExporter commented 9 years ago
@sundl2...@gmail.com
Please attach both network (Wireshark) and device logs (DDMS).

Original comment by boss...@yahoo.fr on 21 Feb 2011 at 8:43

GoogleCodeExporter commented 9 years ago
Thanks .
Maybe I wrote smth wrong and you didn't understand me right
I want to know how to get  incoming messages.
Please help me

Original comment by timeandr...@time.com on 21 Feb 2011 at 10:28

GoogleCodeExporter commented 9 years ago
@timeandr...@time.com
Incoming MSRP messages (chat) are receive as MSRP file messages.
OnInviteEvent() and OnDialogEvent() are only used for SIP signaling layer.

// 1. create the MSRP messaging session
MyMsrpSession mSession = 
MyMsrpSession.createOutgoingSession(ServiceManager.getSipService().getStack()
        , MediaType.Chat);
// 2. Hook the MSRP callback in order to receive incoming requests or responses
mSession.setCallback(new MsrpCallback(){
    @Override
    public int OnEvent(MsrpEvent e) {
        @SuppressWarnings("unused")
        final MsrpSession session = e.getSipSession();
        final MsrpMessage message = e.getMessage();
        if(message == null){
            return -1;
        }

        if(message.isRequest()){ // You have received a request
            switch(message.getRequestType()){
                case tmsrp_SEND: // You have received Chuck
                    // see file transfer to understand how to get content data, MSRP headers and
                    // byte-byte range
                    break;
                case tmsrp_REPORT: break;
                default :case tmsrp_AUTH: break;
            }
        } 
        else{ // You have received a response to a reguest (SEND,AUTH or REPORT)
            @SuppressWarnings("unused")
            final short code = message.getCode();
            // see file transfer to understand how to get content data, MSRP headers and
            // byte-byte range
        }
        return 0;
    }
});

3. send the message as explained in comment 2

Original comment by boss...@yahoo.fr on 21 Feb 2011 at 10:57

GoogleCodeExporter commented 9 years ago
Thanks.
But if it is not so diffiult for you  write in which part of file transfer I 
shall look 
to understand for my chat messaging,or write smth else that can help me 
more,(Please)
I am new in android and that is why I have some difficults ,but I have great 
desire to understand chat messaging, and want that chat messaging work in my 
project.
Thanks in advance ,
I will wait to your answer.

Original comment by timeandr...@time.com on 21 Feb 2011 at 11:50

GoogleCodeExporter commented 9 years ago
MSRP callback used to receive chunks (file transfer):
http://code.google.com/p/imsdroid/source/browse/trunk/imsdroid/src/org/doubango/
imsdroid/sip/MyMsrpSession.java#386

Original comment by boss...@yahoo.fr on 21 Feb 2011 at 2:14

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thank you for your help

Addition,I want to know that the detail steps of sending a message

Original comment by sundl2...@gmail.com on 21 Feb 2011 at 4:04

GoogleCodeExporter commented 9 years ago
Hi,all
 How to send a message by calling messagingSession ? Addition,which steps will be call

Original comment by sundl2...@gmail.com on 24 Feb 2011 at 9:04

GoogleCodeExporter commented 9 years ago
Hi,
Please can you attach the whole  classes  of chat messaging .
I am new to android and have some difficults.
I look what you write above,and I could understand ,but I can't understand 
where this methods will be written 
for example the onInviteEvent() method and how I will write in code that for 
chat messaging will work onInvteEvent()(I can't understand the connection of 
this methods)
Thanks in advance.
Any advice will help me.

Original comment by s...@android.com on 2 Mar 2011 at 3:50