Allow to reset the chatroom, and add delegates even to basic chatroom messages
This commit is contained in:
committed by
QuentinArguillere
parent
095492356c
commit
def8aefef6
@@ -130,33 +130,32 @@ class ChatRoomExampleContext : ObservableObject
|
||||
}
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
// Wait until we're sure that the chatroom is ready to send messages
|
||||
if (!self.isFlexiSip) {
|
||||
return
|
||||
if (self.isFlexiSip) {
|
||||
// Wait until we're sure that the chatroom is ready to send messages
|
||||
while(self.chatroomState != ChatroomExampleState.Started){
|
||||
usleep(100000)
|
||||
}
|
||||
}
|
||||
if let chatRoom = self.mChatRoom {
|
||||
self.send(room: chatRoom, msg: "Hello, \((self.isFlexiSip) ? "Flexisip" : "Basic") World !")
|
||||
}
|
||||
while(self.chatroomState != ChatroomExampleState.Started){
|
||||
usleep(100000)
|
||||
}
|
||||
|
||||
if let chatRoom = self.mChatRoom
|
||||
{
|
||||
do
|
||||
{
|
||||
self.mChatMessage = try chatRoom.createMessage(message: "Hello, \((self.isFlexiSip) ? "Flexisip" : "Basic") World !")
|
||||
self.mChatMessage!.addDelegate(delegate: self.mChatMessageDelegate)
|
||||
self.mChatMessage!.send()
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func reset() {
|
||||
if let chatRoom = mChatRoom {
|
||||
mCore.deleteChatRoom(chatRoom: chatRoom)
|
||||
mChatRoom = nil;
|
||||
}
|
||||
chatroomState = ChatroomExampleState.Unstarted
|
||||
}
|
||||
|
||||
func send(room : ChatRoom, msg : String)
|
||||
{
|
||||
do
|
||||
{
|
||||
self.mChatMessage = try room.createMessage(message: msg)
|
||||
self.mChatMessage!.addDelegate(delegate: self.mChatMessageDelegate)
|
||||
self.mChatMessage!.send()
|
||||
} catch {
|
||||
print(error)
|
||||
|
||||
@@ -45,7 +45,7 @@ struct ContentView: View {
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
Text("Call destination :")
|
||||
Text("Chat destination :")
|
||||
TextField("", text : $tutorialContext.dest)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
}
|
||||
@@ -64,14 +64,20 @@ struct ContentView: View {
|
||||
.foregroundColor((tutorialContext.chatroomState == ChatroomExampleState.Started) ? Color.green : Color.black)
|
||||
}
|
||||
}
|
||||
Button(action: { self.tutorialContext.createChatRoom() })
|
||||
Button(action: {
|
||||
if (self.tutorialContext.chatroomState == ChatroomExampleState.Started) {
|
||||
self.tutorialContext.reset()
|
||||
} else {
|
||||
self.tutorialContext.createChatRoom()
|
||||
}
|
||||
})
|
||||
{
|
||||
Text("Start\nChat")
|
||||
Text((tutorialContext.chatroomState == ChatroomExampleState.Started) ? "Reset" : "Start\nChat")
|
||||
.font(.largeTitle)
|
||||
.foregroundColor(Color.white)
|
||||
.frame(width: 100.0, height: 82.0)
|
||||
.background(Color.gray)
|
||||
}.disabled(!tutorialContext.loggedIn)
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
VStack {
|
||||
|
||||
Reference in New Issue
Block a user