"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7688/ios/app/watchos/extension/InCallController.swift" (1 Dec 2023, 3581 Bytes) of package /linux/misc/jitsi-meet-7688.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Swift source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
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
18 import WatchConnectivity
19 import WatchKit
20 import Foundation
21
22
23 class InCallController: WKInterfaceController {
24 @IBOutlet var mutedButton: WKInterfaceButton!
25 @IBOutlet var roomLabel: WKInterfaceLabel!
26 @IBOutlet var timer: WKInterfaceTimer!
27
28 @IBAction func hangupClicked() {
29 sendCommand(JitsiMeetCommands.CMD_HANG_UP, message: nil)
30 }
31
32 @IBAction func muteClicked() {
33 if var micMuted = ExtensionDelegate.currentJitsiMeetContext.micMuted {
34 micMuted = !micMuted;
35 sendCommand(
36 JitsiMeetCommands.CMD_SET_MUTED,
37 message: [
38 "muted": micMuted ? "true" : "false"
39 ])
40 updateMutedButton(withMuted: micMuted)
41 }
42 }
43
44 func sendCommand(_ command: JitsiMeetCommands, message: [String : Any]?) {
45 if WCSession.isSupported() {
46 let session = WCSession.default
47 var data = [String: Any]()
48
49 if let sessionID = ExtensionDelegate.currentJitsiMeetContext.sessionID {
50 if message != nil {
51 message!.forEach { data[$0] = $1 }
52 }
53
54 data["command"] = command.rawValue;
55 data["sessionID"] = sessionID;
56
57 session.sendMessage(data, replyHandler: nil, errorHandler: nil)
58 }
59 }
60 }
61
62 func updateUI(_ newContext: JitsiMeetContext) {
63 var conferenceURL = newContext.conferenceURL
64
65 if let joinConferenceURL = newContext.joinConferenceURL {
66 sendCommand(JitsiMeetCommands.CMD_JOIN_CONFERENCE, message: [ "data" : joinConferenceURL ])
67 conferenceURL = joinConferenceURL
68 }
69
70 let newRoomName = conferenceURL != nil ? conferenceURL!.components(separatedBy: "/").last : ""
71
72 roomLabel.setText(newRoomName)
73
74 if let newTimestamp = newContext.conferenceTimestamp {
75 restartTimer(newTimestamp)
76 }
77 if let newMuted = newContext.micMuted {
78 updateMutedButton(withMuted: newMuted)
79 }
80 }
81
82 func restartTimer(_ conferenceTimestamp: Int64) {
83 if (conferenceTimestamp != 0) {
84 let newDate = Date(timeIntervalSince1970: TimeInterval(conferenceTimestamp / 1000))
85 timer.setDate(newDate)
86 timer.start();
87 print("WATCH timer set date to: \(newDate) and start")
88 } else {
89 print("WATCH timer stop")
90 timer.stop();
91 }
92 }
93
94 func updateMutedButton(withMuted isMuted: Bool) {
95 if isMuted {
96 mutedButton.setBackgroundImageNamed("mute-on.png")
97 } else {
98 mutedButton.setBackgroundImageNamed("mute-off.png")
99 }
100 }
101
102 override func awake(withContext context: Any?) {
103 super.awake(withContext: context)
104
105 if let data = context as? JitsiMeetContext {
106 updateUI(data)
107 }
108 }
109 }