Ruby FFI wrapper of libvncserver
Add this line to your application's Gemfile:
gem 'ffi-rfb'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ffi-rfb
First, become familiar with the libvncserver library: http://libvncserver.sourceforge.net/doc/html/libvncserver_doc.html
Next let's' write a simple server:
require 'ffi'
require 'ffi_rfb'
require 'RMagick'
image = Magick::Image.read('foo.png')[0]
p = FFI::MemoryPointer.new(:int, 1)
p.write_array_of_int([0])
screen = FfiRfb.rfbGetScreen(p, nil, 1024, 768, 8, 3, 4)
screen = FfiRfb::RfbScreenInfo.new(screen)
screen[:desktopName] = FFI::MemoryPointer.from_string('Ruby VNC FTW!')
frame_buffer = FFI::MemoryPointer.new(:char, 1024 * 768 * 4)
frame_buffer.put_bytes(0, image.export_pixels_to_str(0, 0, 1024, 768, 'RGBA'))
screen[:frameBuffer] = frame_buffer
screen[:alwaysShared] = 1
FfiRfb.rfbInitServerWithPthreadsAndZRLE(screen)
while (FfiRfb.rfbIsActive(screen))
usec = screen[:deferUpdateTime] * 1000
FfiRfb.rfbProcessEvents(screen, usec)
end
Finally, build on the above and create something awesome!
-
Functionality provided by libvncserver that is not included with this wrapper:
rfbLogProc - ffi doesn't support varargs in callbacks. see ffi/ffi#161
defaultNewClientHook - I was having trouble getting ffi to match this method definition. If someone can get it working, please submit a pull request.
-
Platform support - this wrapper was built and tested on 64bit linux. it should work on any 64bit operating system, but I haven't tested it.
- Fork it ( http://github.com//ffi-rfb/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request