Skip to content

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

Notifications You must be signed in to change notification settings

developerdizzle/SockPuppet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#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<string> 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<IClientWindow>(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.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published