MCPcopy Create free account
hub / github.com/apache/cloudstack / _connect

Method _connect

systemvm/agent/noVNC/core/rfb.js:707–763  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

705 // ===== PRIVATE METHODS =====
706
707 _connect() {
708 Log.Debug(">> RFB.connect");
709
710 if (this._url) {
711 Log.Info(`connecting to ${this._url}`);
712 this._sock.open(this._url, this._wsProtocols);
713 } else {
714 Log.Info(`attaching ${this._rawChannel} to Websock`);
715 this._sock.attach(this._rawChannel);
716
717 if (this._sock.readyState === 'closed') {
718 throw Error("Cannot use already closed WebSocket/RTCDataChannel");
719 }
720
721 if (this._sock.readyState === 'open') {
722 // FIXME: _socketOpen() can in theory call _fail(), which
723 // isn't allowed this early, but I'm not sure that can
724 // happen without a bug messing up our state variables
725 this._socketOpen();
726 }
727 }
728
729 // Make our elements part of the page
730 this._target.appendChild(this._screen);
731
732 this._gestures.attach(this._canvas);
733
734 this._cursor.attach(this._canvas);
735 this._refreshCursor();
736
737 // Monitor size changes of the screen element
738 this._resizeObserver.observe(this._screen);
739
740 // Always grab focus on some kind of click event
741 this._canvas.addEventListener("mousedown", this._eventHandlers.focusCanvas);
742 this._canvas.addEventListener("touchstart", this._eventHandlers.focusCanvas);
743
744 // Mouse events
745 this._canvas.addEventListener('mousedown', this._eventHandlers.handleMouse);
746 this._canvas.addEventListener('mouseup', this._eventHandlers.handleMouse);
747 this._canvas.addEventListener('mousemove', this._eventHandlers.handleMouse);
748 // Prevent middle-click pasting (see handler for why we bind to document)
749 this._canvas.addEventListener('click', this._eventHandlers.handleMouse);
750 // preventDefault() on mousedown doesn't stop this event for some
751 // reason so we have to explicitly block it
752 this._canvas.addEventListener('contextmenu', this._eventHandlers.handleMouse);
753
754 // Wheel events
755 this._canvas.addEventListener("wheel", this._eventHandlers.handleWheel);
756
757 // Gesture events
758 this._canvas.addEventListener("gesturestart", this._eventHandlers.handleGesture);
759 this._canvas.addEventListener("gesturemove", this._eventHandlers.handleGesture);
760 this._canvas.addEventListener("gestureend", this._eventHandlers.handleGesture);
761
762 Log.Debug("<< RFB.connect");
763 }
764

Callers 1

Calls 6

_socketOpenMethod · 0.95
_refreshCursorMethod · 0.95
addEventListenerMethod · 0.80
attachMethod · 0.65
ErrorFunction · 0.50
openMethod · 0.45

Tested by

no test coverage detected