-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConversationManager.java
51 lines (51 loc) · 1.46 KB
/
ConversationManager.java
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
50
51
public class ConversationManager {
public static int count = 0;
public ITextReceiver _listener;
private ConversationManager _Conversant;
private String id;
private boolean inRoom;
public boolean IsInRoom(){
return inRoom;
}
public void setConversant(ConversationManager manager){
inRoom = !(manager==null);
if(!inRoom){
try {
_listener.ReceiveQuitNotice();
} catch (Exception e) {
e.printStackTrace();
}
}
_Conversant = manager;
}
public String GetConversantid(){
return _Conversant.GetId();
}
public void AcceptQueue() throws Exception {
try {
_listener.ConversationAcceptedNoticed();
} catch (Exception e) {
throw new Exception(this.GetId() + " couldn't connect to room.");
}
}
public void SetListener(ITextReceiver listener){
_listener = listener;
}
public ConversationManager(){
id = Integer.toString(count, 16);
count++;
inRoom = false;
System.out.println("New user joined id: "+id);
}
public void SendMessage(String message) throws Exception {
try {
_Conversant._listener.ReceiveText(message);
} catch (Exception e) {
inRoom = false;
throw new Exception(_Conversant.GetId() + " disconnected.");
}
}
public String GetId(){
return id;
}
}