https://github.com/developerdizzle/sockpuppet
Use websockets to link a c# object to a javascript object, and call javascript object methods from your c# strongly typed interface or dynamic object
https://github.com/developerdizzle/sockpuppet
Last synced: 3 months ago
JSON representation
Use websockets to link a c# object to a javascript object, and call javascript object methods from your c# strongly typed interface or dynamic object
- Host: GitHub
- URL: https://github.com/developerdizzle/sockpuppet
- Owner: developerdizzle
- Created: 2012-06-20T03:30:04.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2012-06-22T23:36:34.000Z (almost 14 years ago)
- Last Synced: 2025-01-20T00:53:43.406Z (about 1 year ago)
- Language: C#
- Homepage:
- Size: 508 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
#SockPuppet
Link a .NET object to a Javascript object using HTML5 WebSockets, and call Javascript object methods from your .NET code.
On your web page:
//create a new WebSocket object as usual
var server = new WebSocket("ws://localhost:8181");
//set our context to the window object - all sockpuppet method calls will be performed on this object
server.puppetContext(window);
In your server-side code:
//create a dynamic Sockpuppet, passing a Func used to send a message through your Websocket
dynamic dynamicPuppet = SockPuppet.Puppet.New(r => socket.Send(r));
//call any method on your client-side context object!
dynamicPuppet.document.alert("I'm in your browser calling your methods!");
Also supports interfaces (that do not have to be explicitly implemented!):
//create a strongly typed sockpuppet
IClientWindow windowPuppet = SockPuppet.Puppet.New(r => socket.Send(r));
//call any method on your client-side context object!
windowPuppet.showMessage("This method was called from an interface on the server!");
The demo uses Fleck as a Websocket server, but you are free to use whichever you prefer.