Whiteboard.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // Whiteboard.swift
  3. // Nusa
  4. //
  5. // Created by Rifqy Fakhrul Rijal on 21/10/19.
  6. // Copyright © 2019 Development. All rights reserved.
  7. //
  8. // Rn
  9. // forgor ???
  10. import Foundation
  11. import UIKit
  12. public class Whiteboard: WhiteboardDelegate {
  13. var roomId = ""
  14. var canvas : WhiteboardCanvas?
  15. public init(delegated: Bool) {
  16. if(!delegated){
  17. }
  18. }
  19. public func setRoomId(roomId: String){
  20. self.roomId = roomId
  21. canvas?.setDestination(destination: roomId)
  22. }
  23. // public func clearWhiteboard(){
  24. // removeWhiteboard(dest:destination)
  25. // canvas.clear()
  26. // }
  27. public func setPenColor(color: Int){
  28. let hexString = String(format: "%08X", color)
  29. canvas?.setLineColor(color: UIColor(hexString: hexString))
  30. changePenColor(dest: roomId, color: color)
  31. }
  32. public func setPenSize(size: Double){
  33. canvas?.setStrokeSize(size: size)
  34. changePenSize(dest: roomId, size: size)
  35. }
  36. public func changePeerPenColor(color: Int){
  37. let hexString = String(format: "%08X", color)
  38. canvas?.setPeerLineColor(color: UIColor(hexString: hexString))
  39. }
  40. public func changePeerPenSize(size: Double){
  41. canvas?.setPeerStrokeSize(size: size)
  42. }
  43. public func terminate(){
  44. clear()
  45. sendTerminate()
  46. }
  47. public func sendInit(destinations: String){
  48. canvas?.setLineColor(color: UIColor(hexString: "FF000000"))
  49. let me = UserDefaults.standard.string(forKey: "me")!
  50. let tid = CoreMessage_TMessageUtil.getTID()
  51. roomId = "\(me)wbvc\(tid)"
  52. _ = Nexilis.writeDraw(data: "WB/0/\(roomId)/\(destinations)")
  53. }
  54. public func sendJoin(){
  55. canvas?.setLineColor(color: UIColor(hexString: "FF00FF00"))
  56. _ = Nexilis.writeDraw(data: "WB/22/\(roomId)")
  57. }
  58. public func sendTerminate(){
  59. _ = Nexilis.writeDraw(data: "WB/88")
  60. }
  61. func changePenSize(dest: String, size: Double){
  62. // let destId = Nusa.default.getUserId(name: dest, entity: entity!)
  63. // let message = Message.changeWhiteboardPenSize(originator: originId as! String, destination: String(destId), size: size)
  64. // App.write(message: message)
  65. }
  66. func changePenColor(dest: String, color: Int){
  67. // let destId = Nusa.default.getUserId(name: dest, entity: entity!)
  68. // let message = Message.changeWhiteboardPenColor(originator: originId as! String, destination: String(destId), color: color)
  69. // App.write(message: message)
  70. }
  71. public func draw(x: String, y: String, w: String, h: String, fc: String, sw: String, xo: String, yo: String, data: String) {
  72. //print(("Draw whiteboard: "+x+","+y+","+w+","+h+","+fc+","+sw+","+xo+","+yo)
  73. canvas?.incomingData(x: x,y: y,w: w,h: h,fc: fc,sw: sw,xo: xo,yo: yo)
  74. }
  75. public func sendClear(){
  76. let ms = Date().currentTimeMillis()
  77. _ = Nexilis.writeDraw(data: "WB/3/\(ms)")
  78. }
  79. public func clear() {
  80. //print(("Clear whiteboard")
  81. DispatchQueue.main.async {
  82. self.canvas?.clear()
  83. }
  84. }
  85. }