您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

InCallController.swift 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright @ 2018-present 8x8, Inc.
  3. * Copyright @ 2017-2018 Atlassian Pty Ltd
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import WatchConnectivity
  18. import WatchKit
  19. import Foundation
  20. class InCallController: WKInterfaceController {
  21. @IBOutlet var mutedButton: WKInterfaceButton!
  22. @IBOutlet var roomLabel: WKInterfaceLabel!
  23. @IBOutlet var timer: WKInterfaceTimer!
  24. @IBAction func hangupClicked() {
  25. sendCommand(JitsiMeetCommands.CMD_HANG_UP, message: nil)
  26. }
  27. @IBAction func muteClicked() {
  28. if var micMuted = ExtensionDelegate.currentJitsiMeetContext.micMuted {
  29. micMuted = !micMuted;
  30. sendCommand(
  31. JitsiMeetCommands.CMD_SET_MUTED,
  32. message: [
  33. "muted": micMuted ? "true" : "false"
  34. ])
  35. updateMutedButton(withMuted: micMuted)
  36. }
  37. }
  38. func sendCommand(_ command: JitsiMeetCommands, message: [String : Any]?) {
  39. if WCSession.isSupported() {
  40. let session = WCSession.default
  41. var data = [String: Any]()
  42. if let sessionID = ExtensionDelegate.currentJitsiMeetContext.sessionID {
  43. if message != nil {
  44. message!.forEach { data[$0] = $1 }
  45. }
  46. data["command"] = command.rawValue;
  47. data["sessionID"] = sessionID;
  48. session.sendMessage(data, replyHandler: nil, errorHandler: nil)
  49. }
  50. }
  51. }
  52. func updateUI(_ newContext: JitsiMeetContext) {
  53. var conferenceURL = newContext.conferenceURL
  54. if let joinConferenceURL = newContext.joinConferenceURL {
  55. sendCommand(JitsiMeetCommands.CMD_JOIN_CONFERENCE, message: [ "data" : joinConferenceURL ])
  56. conferenceURL = joinConferenceURL
  57. }
  58. let newRoomName = conferenceURL != nil ? conferenceURL!.components(separatedBy: "/").last : ""
  59. roomLabel.setText(newRoomName)
  60. if let newTimestamp = newContext.conferenceTimestamp {
  61. restartTimer(newTimestamp)
  62. }
  63. if let newMuted = newContext.micMuted {
  64. updateMutedButton(withMuted: newMuted)
  65. }
  66. }
  67. func restartTimer(_ conferenceTimestamp: Int64) {
  68. if (conferenceTimestamp != 0) {
  69. let newDate = Date(timeIntervalSince1970: TimeInterval(conferenceTimestamp / 1000))
  70. timer.setDate(newDate)
  71. timer.start();
  72. print("WATCH timer set date to: \(newDate) and start")
  73. } else {
  74. print("WATCH timer stop")
  75. timer.stop();
  76. }
  77. }
  78. func updateMutedButton(withMuted isMuted: Bool) {
  79. if isMuted {
  80. mutedButton.setBackgroundImageNamed("mute-on.png")
  81. } else {
  82. mutedButton.setBackgroundImageNamed("mute-off.png")
  83. }
  84. }
  85. override func awake(withContext context: Any?) {
  86. super.awake(withContext: context)
  87. if let data = context as? JitsiMeetContext {
  88. updateUI(data)
  89. }
  90. }
  91. }