forked from fabiang/xmpp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.php
46 lines (36 loc) · 1.02 KB
/
example.php
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
38
39
40
41
42
43
44
45
46
<?php
require 'vendor/autoload.php';
error_reporting(-1);
set_time_limit(0);
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Fabiang\Xmpp\Options;
use Fabiang\Xmpp\Client;
use Fabiang\Xmpp\Protocol\Roster;
use Fabiang\Xmpp\Protocol\Presence;
use Fabiang\Xmpp\Protocol\Message;
$logger = new Logger('xmpp');
$logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
$address = "myjabber.com:5222";
$socksProxy = 'localhost:9050';
$username = 'xmpp';
$password = 'test';
$options = new Options($address);
$options->setLogger($logger)
->setUsername($username)
->setPassword($password)
->setAutoSubscribe(true)
;
if ($socksProxy) {
$options->setSocksProxyAddress($socksProxy);
}
$client = new Client($options);
$client->connect();
$client->send(new Roster());
$client->send(new Presence());
while (true) {
$messages = $client->getMessages(true); //blocking mode for get messages
foreach ($messages as $msg) {
$client->send(new Message($msg['message'], $msg['from']));
}
}