Messagefactory
MessageFactory serves as a personal messaging constructor. It's responsible for creating both the questions (requests) and the answers (responses) in the SIP conversation.
Creating a Request: When you want to initiate a call or simply say "hello" over SIP, you create a request. This process is similar to sending a letter – this request is your letter, complete with the address and the content.
// Create a basic SIP request to invite someone to a call
URI requestURI = addressFactory.createURI("sip:friend@example.com");
Request request = messageFactory.createRequest(
requestURI,
"INVITE", // The method
callIdHeader, // Unique call identifier
cSeqHeader, // Sequence number for ordering messages
fromHeader, // Who the request is from
toHeader, // Who the request is to
viaHeaders, // "Via" headers specifying the transport route
maxForwardsHeader // Limits the number of hops a request can make
);
Responding to a Request: Just as you would reply to a letter, SIP allows you to respond to requests. Whether it’s a "Yes, I’ll join the call" or a "Sorry, I’m busy," MessageFactory helps you craft that response.
// Create a response indicating the call was accepted
Response response = messageFactory.createResponse(
200, // Status code for "OK"
request, // The original request being responded to
callIdHeader,
cSeqHeader,
fromHeader,
toHeader,
viaHeaders,
maxForwardsHeader,
contentTypeHeader, // Describes the type of content
"Welcome to the call!" // The body of the response
);
HeaderFactory
HeaderFactory focuses on the details — the metadata of your SIP messages. Think of it as creating the stamp and return address for letter. It customizes how your message travels through the SIP network and how it's processed upon arrival.
Example: Adding a "From" header to indicate who's sending the request.
FromHeader fromHeader = headerFactory.createFromHeader(address, "123456");
AddressFactory
Lastly, AddressFactory deals with the "where" of SIP messages. It's all about creating the to and from addresses, ensuring your message reaches the right destination.
Example: Creating a SIP URI for your message’s destination.
SipURI sipURI = addressFactory.createSipURI("user", "example.com");
Together, these factories empower you to construct and navigate the SIP message ecosystem. From the very creation of a message to its detailed headers and the addresses it’s sent to, MessageFactory, HeaderFactory, and AddressFactory are the essential tools in your SIP communication toolkit. With them, you're well-equipped to craft, send, and manage SIP communications effectively.
Start innovating with Mobius
What's next? Let's talk!