|
|
|
|
@ -2,24 +2,13 @@
|
|
|
|
|
// ViewController.swift
|
|
|
|
|
// Runner
|
|
|
|
|
//
|
|
|
|
|
// Created by Mohammad Aljammal on 24/06/20.
|
|
|
|
|
// Copyright © 2020 tokbox. All rights reserved.
|
|
|
|
|
// Created by Mohammad Aljammal & Elham on 23/6/20.
|
|
|
|
|
// Copyright © 2020 The Chromium Authors. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
import OpenTok
|
|
|
|
|
|
|
|
|
|
let kWidgetRatio: CGFloat = 1.333
|
|
|
|
|
|
|
|
|
|
// *** Fill the following variables using your own Project info ***
|
|
|
|
|
// *** https://tokbox.com/account/#/ ***
|
|
|
|
|
// Replace with your OpenTok API key
|
|
|
|
|
let kApiKey = "46803224"
|
|
|
|
|
// Replace with your generated session ID
|
|
|
|
|
let kSessionId = "2_MX40NjgwMzIyNH5-MTU5MzA3NDk2MjQxNH5QekwrY1oyaHdnbjVSaENkemlvNFVqeEJ-fg"
|
|
|
|
|
// Replace with your generated token
|
|
|
|
|
let kToken = "T1==cGFydG5lcl9pZD00NjgwMzIyNCZzaWc9ZTUxZGI0NGJiNjhjOGY2YzZkZGVjNTQ0M2Q5ZDJkODY2MjBlYjJjYTpzZXNzaW9uX2lkPTJfTVg0ME5qZ3dNekl5Tkg1LU1UVTVNekEzTkRrMk1qUXhOSDVRZWt3clkxb3lhSGRuYmpWU2FFTmtlbWx2TkZWcWVFSi1mZyZjcmVhdGVfdGltZT0xNTkzMDc1MDA3Jm5vbmNlPTAuNjQ2OTA2MTAwMTU0ODY3NSZyb2xlPXB1Ymxpc2hlciZleHBpcmVfdGltZT0xNTkzNjc5ODA2JmluaXRpYWxfbGF5b3V0X2NsYXNzX2xpc3Q9"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ViewController: UIViewController {
|
|
|
|
|
|
|
|
|
|
@ -27,6 +16,12 @@ class ViewController: UIViewController {
|
|
|
|
|
var publisher: OTPublisher?
|
|
|
|
|
var subscriber: OTSubscriber?
|
|
|
|
|
|
|
|
|
|
var kApiKey:String = ""
|
|
|
|
|
|
|
|
|
|
var kSessionId:String = ""
|
|
|
|
|
|
|
|
|
|
var kToken:String = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
@ -77,7 +72,7 @@ class ViewController: UIViewController {
|
|
|
|
|
|
|
|
|
|
@IBAction func didClickSpeakerButton(_ sender: UIButton) {
|
|
|
|
|
sender.isSelected = !sender.isSelected
|
|
|
|
|
subscriber!.subscribeToAudio = !sender.isSelected
|
|
|
|
|
subscriber?.subscribeToAudio = !sender.isSelected
|
|
|
|
|
// resetHideButtonsTimer()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -218,26 +213,6 @@ extension ViewController: OTSessionDelegate {
|
|
|
|
|
func sessionDidConnect(_ session: OTSession) {
|
|
|
|
|
print("The client connected to the OpenTok session.")
|
|
|
|
|
|
|
|
|
|
// let settings = OTPublisherSettings()
|
|
|
|
|
// settings.name = UIDevice.current.name
|
|
|
|
|
// guard let publisher = OTPublisher(delegate: self, settings: settings) else {
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// var error: OTError?
|
|
|
|
|
// session.publish(publisher, error: &error)
|
|
|
|
|
// guard error == nil else {
|
|
|
|
|
// print(error!)
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// guard let publisherView = publisher.view else {
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// let screenBounds = UIScreen.main.bounds
|
|
|
|
|
// publisherView.frame = CGRect(x: screenBounds.width - 150 - 20, y: screenBounds.height - 150 - 20, width: 150, height: 150)
|
|
|
|
|
// view.addSubview(publisherView)
|
|
|
|
|
//
|
|
|
|
|
setupPublisher()
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -266,6 +241,17 @@ extension ViewController: OTSessionDelegate {
|
|
|
|
|
print("The client failed to connect to the OpenTok session: \(error).")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func session(
|
|
|
|
|
_ session: OTSession,
|
|
|
|
|
connectionDestroyed connection: OTConnection
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
if subscriber?.stream!.connection.connectionId == connection.connectionId {
|
|
|
|
|
cleanupSubscriber()
|
|
|
|
|
}
|
|
|
|
|
sessionDisconnect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func session(_ session: OTSession, streamCreated stream: OTStream) {
|
|
|
|
|
subscriber = OTSubscriber(stream: stream, delegate: self)
|
|
|
|
|
|