forked from AgoraIO/API-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
144 lines (119 loc) · 7.66 KB
/
ViewController.swift
File metadata and controls
144 lines (119 loc) · 7.66 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//
// ViewController.swift
// APIExample
//
// Created by 张乾泽 on 2020/8/28.
// Copyright © 2020 Agora Corp. All rights reserved.
//
import Cocoa
struct MenuItem {
var name: String
var identifier: String
var controller: String?
var storyboard: String?
}
class MenuController: NSViewController {
let settings = MenuItem(name: "Global settings".localized, identifier: "menuCell", controller: "Settings", storyboard: "Settings")
var menus:[MenuItem] = [
MenuItem(name: "Basic", identifier: "headerCell"),
MenuItem(name: "Join a channel (Token)".localized, identifier: "menuCell", controller: "JoinChannelVideoToken", storyboard: "JoinChannelVideoToken"),
MenuItem(name: "Join a channel (Video)".localized, identifier: "menuCell", controller: "JoinChannelVideo", storyboard: "JoinChannelVideo"),
MenuItem(name: "Join a channel (Audio)".localized, identifier: "menuCell", controller: "JoinChannelAudio", storyboard: "JoinChannelAudio"),
MenuItem(name: "Local or remote recording".localized, identifier: "menuCell", controller: "JoinChannelVideoRecorder", storyboard: "JoinChannelVideoRecorder"),
MenuItem(name: "Anvanced", identifier: "headerCell"),
MenuItem(name: "Live Streaming".localized, identifier: "menuCell", controller: "LiveStreaming", storyboard: "LiveStreaming"),
MenuItem(name: "RTMP Streaming".localized, identifier: "menuCell", controller: "RTMPStreaming", storyboard: "RTMPStreaming"),
MenuItem(name: "Custom Video Source(Push)".localized, identifier: "menuCell", controller: "CustomVideoSourcePush", storyboard: "CustomVideoSourcePush"),
MenuItem(name: "Custom Video Source(Multi)".localized, identifier: "menuCell", controller: "CustomVideoSourcePushMulti", storyboard: "CustomVideoSourcePushMulti"),
MenuItem(name: "Custom Video Render".localized, identifier: "menuCell", controller: "CustomVideoRender", storyboard: "CustomVideoRender"),
MenuItem(name: "Custom Audio Source".localized, identifier: "menuCell", controller: "CustomAudioSource", storyboard: "CustomAudioSource"),
MenuItem(name: "Custom Audio Render".localized, identifier: "menuCell", controller: "CustomAudioRender", storyboard: "CustomAudioRender"),
// MenuItem(name: "Raw Media Data".localized, identifier: "menuCell", controller: "RawMediaData", storyboard: "RawMediaData"),
MenuItem(name: "Raw Video Data".localized, identifier: "menuCell", controller: "RawVideoData", storyboard: "RawVideoData"),
MenuItem(name: "Raw Audio Data".localized, identifier: "menuCell", controller: "RawAudioData", storyboard: "RawAudioData"),
MenuItem(name: "Join Multiple Channels".localized, identifier: "menuCell", controller: "JoinMultipleChannel", storyboard: "JoinMultiChannel"),
MenuItem(name: "Stream Encryption".localized, identifier: "menuCell", controller: "StreamEncryption", storyboard: "StreamEncryption"),
MenuItem(name: "Screen Share".localized, identifier: "menuCell", controller: "ScreenShare", storyboard: "ScreenShare"),
MenuItem(name: "Local composite graph".localized, identifier: "menuCell", controller: "LocalCompositeGraph", storyboard: "LocalCompositeGraph"),
MenuItem(name: "Media Channel Relay".localized, identifier: "menuCell", controller: "ChannelMediaRelay", storyboard: "ChannelMediaRelay"),
MenuItem(name: "Audio Mixing".localized, identifier: "menuCell", controller: "AudioMixing", storyboard: "AudioMixing"),
MenuItem(name: "Voice Changer".localized, identifier: "menuCell", controller: "VoiceChanger", storyboard: "VoiceChanger"),
MenuItem(name: "Precall Test".localized, identifier: "menuCell", controller: "PrecallTest", storyboard: "PrecallTest"),
MenuItem(name: "Create Data Stream".localized, identifier: "menuCell", controller: "CreateDataStream", storyboard: "CreateDataStream"),
MenuItem(name: "Simple Filter".localized, identifier: "menuCell", controller: "SimpleFilter", storyboard: "SimpleFilter"),
MenuItem(name: "Video Process".localized, identifier: "menuCell", controller: "Video Process", storyboard: "VideoProcess"),
MenuItem(name: "Media Player".localized, identifier: "menuCell", controller: "MediaPlayer", storyboard: "MediaPlayer"),
MenuItem(name: "Quick Switch Channel".localized, identifier: "menuCell", controller: "QuickSwitchChannel", storyboard: "QuickSwitchChannel"),
MenuItem(name: "Spatial Audio".localized, identifier: "menuCell", controller: "SpatialAudio", storyboard: "SpatialAudio"),
MenuItem(name: "Content Inspect".localized, identifier: "menuCell", controller: "ContentInspect", storyboard: "ContentInspect"),
MenuItem(name: "Multi Camera Sourece".localized, identifier: "menuCell", controller: "MultiCameraSourece", storyboard: "MultiCameraSourece"),
]
@IBOutlet weak var tableView:NSTableView!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func onClickSetting(_ sender: NSButton) {
let selectedRow = tableView.selectedRow
if (selectedRow >= 0) {
tableView.deselectRow(selectedRow)
}
loadSplitViewItem(item: settings)
}
func loadSplitViewItem(item: MenuItem) {
var storyboardName = ""
if let name = item.storyboard {
storyboardName = name
} else {
storyboardName = "Main"
}
let board: NSStoryboard = NSStoryboard(name: storyboardName, bundle: nil)
guard let splitViewController = self.parent as? NSSplitViewController,
let controllerIdentifier = item.controller,
let viewController = board.instantiateController(withIdentifier: controllerIdentifier) as? BaseView else { return }
let splititem = NSSplitViewItem(viewController: viewController as NSViewController)
let detailItem = splitViewController.splitViewItems[1]
if let detailViewController = detailItem.viewController as? BaseView {
detailViewController.viewWillBeRemovedFromSplitView()
}
splitViewController.removeSplitViewItem(detailItem)
splitViewController.addSplitViewItem(splititem)
}
}
extension MenuController: NSTableViewDataSource, NSTableViewDelegate {
func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {
let item = menus[row]
return item.identifier == "menuCell" ? 32 : 18
}
func numberOfRows(in tableView: NSTableView) -> Int {
return menus.count
}
func tableView(_ tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
let item = menus[row]
return item.identifier != "headerCell"
}
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
let item = menus[row]
// Get an existing cell with the MyView identifier if it exists
let view = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: item.identifier), owner: self) as? NSTableCellView
view?.imageView?.image = nil
view?.textField?.stringValue = item.name
// Return the result
return view;
}
func tableViewSelectionDidChange(_ notification: Notification) {
if tableView.selectedRow >= 0 && tableView.selectedRow < menus.count {
loadSplitViewItem(item: menus[tableView.selectedRow])
}
}
}
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}