     @linesRef    = @workspaceRef.child "lines"
     @stateRef    = @workspaceRef.child "state"
     @usersRef    = @workspaceRef.child "users"
+    @drawedQueue = []
+    @userColors  = {}
 
+    @container.on "viewAppended", =>
+      @createCanvas()
+      @setUserColor()
+
+      @bindMouseDownOnCanvas()
+      @bindMouseUpOnCanvas()
+      @bindMouseMoveCanvas()
+
+      @workspaceRef.onDisconnect().remove()  if @amIHost
+      @redrawCanvas()  if @isJoinedASession
+
+      @bindRemoteEvents()
+      @container.addSubView @canvas
+
+  createCanvas: ->
     @canvas      = new KDCustomHTMLView
       tagName    : "canvas"
-      domId      : "paintCanvas"
       bind       : "mousemove mousedown mouseup"
       attributes :
-        width    : 640
-        height   : 480
-        style    : "border: 2px solid #333;"
+        width    : @getWidth()
+        height   : @getHeight()
 
     @context     = @canvas.getElement().getContext "2d"
-    @drawedQueue = []
-    @userColors  = {}
-    @setUserColor()
 
+  redrawCanvas: ->
+    @context.closePath()
+    @linesRef.once "value", (snapshot) =>
+      value = snapshot.val()
+      return unless value
+      @context.beginPath()
+      for own key, points of value
+        pointsArr = points.split "|"
+        [username, color]     = pointsArr.splice 0, 2
+        @userColors[username] = color
+
+        @context.closePath()
+        @context.beginPath()
+        for point, index in pointsArr
+          [x, y] = point.split ","
+          @context.moveTo x, y  if index is 0
+          @addPoint x, y, username
+
+  bindMouseDownOnCanvas: ->
     @canvas.on "mousedown", (e) =>
       KD.utils.stopDOMEvent e
       x             = e.offsetX

class CollaborativeDrawingPane extends CollaborativePane

  constructor: (options = {}, data) ->

    super options, data


      for own key, userData of value
        @userColors[userData.nickname] = userData.color

  addPoint: (x, y, nickname = KD.nick()) ->
    ctx             = @context
    ctx.strokeStyle = @userColors[nickname]
