Here we have created the chat room in XMPP using PHP. Now I'm writing the code to show you how you can join a chat room in XMPP using PHP. I'm using ejabbered server.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
class XMPP_JOIN_ROOM
{
public function joinRoom($room_name,$ejabber_id,$password) {
$command = 'send_direct_invitation';
$params = array(
'name' => $room_name,
'users' => $ejabber_id,
'service' => 'conference.localhost',
'password' => $password,
'reason' => 'reason');
$response = $this->sendRequest($command, $params);
}
public function sendRequest($command, $params) {
$request = xmlrpc_encode_request($command, $params, (array('encoding' => 'utf-8')));$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "User-Agent: XMLRPC::Client mod_xmlrpc\r\n" .
"Content-Type: text/xml\r\n" .
"Content-Length: " . strlen($request),
'content' => $request
)));
// edit RPC server url
$RPC_SERVER = 'http://IP:4560/RPC2'
$file = file_get_contents($RPC_SERVER , false, $context);
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
return $response;
}
}
}
$user = new XMPP_JOIN_ROOM();
$user->joinRoom($room_name,$ejabber_id,$password);
?>
|