-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.pl
49 lines (36 loc) · 982 Bytes
/
example.pl
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
47
48
49
# Copyright (c) 2013, Mitchell Cooper
use Net::Async::Omegle;
use warnings;
use strict;
use feature 'say';
# create an Omegle manager instance.
my $om = Net::Async::Omegle->new;
# create an IO::Async::Loop and add the Omegle manager instance.
my $loop = IO::Async::Loop->new;
$loop->add($om);
$om->init;
# create a session.
my $sess = $om->new();
$sess->on(debug => sub { say "@_" });
# send messages back to the user after 5 seconds.
$sess->on(message => sub {
my ($event, $msg) = @_;
my $timer = IO::Async::Timer::Countdown->new(
delay => 5,
on_expire => sub {
# we are no longer connected to a stranger.
return unless $sess->connected;
say "You: $msg";
$sess->say($msg);
}
);
$timer->start;
$loop->add($timer);
});
# start it when Omegle is ready.
$om->on(ready => sub {
say 'Ready to connect.';
$sess->start;
});
# run the loop.
$loop->run;