123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // Whiteboard.swift
- // Nusa
- //
- // Created by Rifqy Fakhrul Rijal on 21/10/19.
- // Copyright © 2019 Development. All rights reserved.
- //
- // Rn
- // forgor ???
- import Foundation
- import UIKit
- public class Whiteboard: WhiteboardDelegate {
-
- var roomId = ""
- var canvas : WhiteboardCanvas?
-
- public init(delegated: Bool) {
- if(!delegated){
-
- }
- }
-
- public func setRoomId(roomId: String){
- self.roomId = roomId
- canvas?.setDestination(destination: roomId)
- }
-
- // public func clearWhiteboard(){
- // removeWhiteboard(dest:destination)
- // canvas.clear()
- // }
-
- public func setPenColor(color: Int){
- let hexString = String(format: "%08X", color)
- canvas?.setLineColor(color: UIColor(hexString: hexString))
- changePenColor(dest: roomId, color: color)
- }
-
- public func setPenSize(size: Double){
- canvas?.setStrokeSize(size: size)
- changePenSize(dest: roomId, size: size)
- }
-
- public func changePeerPenColor(color: Int){
- let hexString = String(format: "%08X", color)
- canvas?.setPeerLineColor(color: UIColor(hexString: hexString))
- }
-
- public func changePeerPenSize(size: Double){
- canvas?.setPeerStrokeSize(size: size)
- }
-
- public func terminate(){
- clear()
- sendTerminate()
- }
-
- public func sendInit(destinations: String){
- canvas?.setLineColor(color: UIColor(hexString: "FF000000"))
- let me = UserDefaults.standard.string(forKey: "me")!
- let tid = CoreMessage_TMessageUtil.getTID()
- roomId = "\(me)wbvc\(tid)"
- _ = Nexilis.writeDraw(data: "WB/0/\(roomId)/\(destinations)")
- }
-
- public func sendJoin(){
- canvas?.setLineColor(color: UIColor(hexString: "FF00FF00"))
- _ = Nexilis.writeDraw(data: "WB/22/\(roomId)")
- }
-
- public func sendTerminate(){
- _ = Nexilis.writeDraw(data: "WB/88")
- }
-
- func changePenSize(dest: String, size: Double){
- // let destId = Nusa.default.getUserId(name: dest, entity: entity!)
- // let message = Message.changeWhiteboardPenSize(originator: originId as! String, destination: String(destId), size: size)
- // App.write(message: message)
- }
-
- func changePenColor(dest: String, color: Int){
- // let destId = Nusa.default.getUserId(name: dest, entity: entity!)
- // let message = Message.changeWhiteboardPenColor(originator: originId as! String, destination: String(destId), color: color)
- // App.write(message: message)
- }
-
- public func draw(x: String, y: String, w: String, h: String, fc: String, sw: String, xo: String, yo: String, data: String) {
- //print(("Draw whiteboard: "+x+","+y+","+w+","+h+","+fc+","+sw+","+xo+","+yo)
- canvas?.incomingData(x: x,y: y,w: w,h: h,fc: fc,sw: sw,xo: xo,yo: yo)
- }
-
- public func sendClear(){
- let ms = Date().currentTimeMillis()
- _ = Nexilis.writeDraw(data: "WB/3/\(ms)")
- }
-
- public func clear() {
- //print(("Clear whiteboard")
- DispatchQueue.main.async {
- self.canvas?.clear()
- }
- }
-
- }
|