diff --git a/swift/ChatRoomTutorial/ChatRoomTutorial/ChatRoomExample.swift b/swift/ChatRoomTutorial/ChatRoomTutorial/ChatRoomExample.swift index 268cb2a..3ba2ca2 100644 --- a/swift/ChatRoomTutorial/ChatRoomTutorial/ChatRoomExample.swift +++ b/swift/ChatRoomTutorial/ChatRoomTutorial/ChatRoomExample.swift @@ -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) diff --git a/swift/ChatRoomTutorial/ChatRoomTutorial/ContentView.swift b/swift/ChatRoomTutorial/ChatRoomTutorial/ContentView.swift index a0242c2..729b54c 100644 --- a/swift/ChatRoomTutorial/ChatRoomTutorial/ContentView.swift +++ b/swift/ChatRoomTutorial/ChatRoomTutorial/ContentView.swift @@ -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 {