-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for non-binary WebMKS websocket
Until now, 'binary' protocol for websockets was assumed. But VMware vCloud console access only works via legacy 'uint8utf8' protocol. To make it even more interesting, vCloud's JavaScript SDK actually thinks it supports 'binary', but in fact it doesn't. Well 'binary' protocol works when connecting to vCenter (i.e. `Vmware::InfraManager`), but not for vCloud (`Vmware::CloudManager`). With this commit we implement websocket proxy client for 'uint8utf8' protocol and remove 'binary' from list of offered protocols when 'uint8utf8' is used to make sure JavaScript SDK doesn't overestimate itself (and then fail). Signed-off-by: Miha Pleško <[email protected]>
- Loading branch information
1 parent
1d647ba
commit 05d8575
Showing
3 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class WebsocketWebmksUint8utf8 < WebsocketSSLSocket | ||
attr_accessor :url | ||
|
||
def initialize(socket, model) | ||
super(socket, model) | ||
@url = URI::Generic.build(:scheme => 'wss', | ||
:host => @model.host_name, | ||
:port => @model.port, | ||
:path => @model.url).to_s | ||
|
||
@driver = WebSocket::Driver.client(self, :protocols => ['uint8utf8']) | ||
@driver.on(:close) { socket.close unless socket.closed? } | ||
@driver.start | ||
end | ||
|
||
def fetch(length) | ||
# WebSocket::Driver requires an event handler that should be registered only once | ||
@driver.on(:message) { |msg| yield(msg.data) } if @driver.listeners(:message).length.zero? | ||
|
||
data = @ssl.sysread(length) | ||
@driver.parse(data) | ||
end | ||
|
||
def issue(data) | ||
@driver.frame(data) | ||
end | ||
|
||
def write(data) | ||
@ssl.syswrite(data) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters