Class: SocketController

Controller#SocketController(options:Object)

new SocketController(options:Object)

A Socket controller connects a socket on the client with a sever. This only works if you run the app yourself with a server. And on our website

To connect the controller with a client-mixer, you need to place a controller in both. The client will give you a code like a7fw . Use that code in the client-mixer and receive events.
If configured correctly you should be able to send events to multiple clients.

Parameters:
Name Type Description
options:Object
Implements:
Author:
  • Sense Studios
Source:
Example
// in your client (output)
 // https://virtualmixproject.com/mixer/demo_socket_client

 var socket1 = new SocketController( renderer )
 socket1.debug = true

 // this should log a server welcome object with a uid
 // got command {command: "welcome", payload: "8170"}
 console.log(socket1.target)
 > 8170

 // should give you an string:"8170",
 // make sure your user sees this string, so he can connects his _remote_ to this _client_

 // optionally listen for the ready signal, which gives you the id too
 socket1.addEventListener("ready", function(d) console.log("client id:", d ));
 > client id: 8170

 // write the rest of your listeners
 socket1.addEventListener( 1, function( _arr1 ) {
  // do something with _arr1
 })

 socket1.addEventListener( 2, function( _arr2 ) {
  // do something with _arr2
 })

 socket1.addEventListener( 3, function( _arr3 ) {
  // do something with _arr3
 })

 - - -

 // in your controller (input, 'remote control')
 // https://virtualmixproject.com/remotes/demo_socketcontroller_remote

 var socketcontroller = new SocketController()

 // make a way to enter the client-id: ( in this example: 8170 )
 var get_client_id = ()=> { return document.getElementById('socket_client_id').value }

 // send trigger 1 to socket get_client_id, may send to multiple ids: "8170,af44" always lowecase
 // _commands are mostly arrays of numbers or strings, but can be interpreted on the client.
 // [ "mixer1", "blend", 6 ]
 // [ "mixer1", "pod", gamepad1.x-axis ]
 // etc.

 socketcontroller.send( get_client_id(), 1, [1,1] );
 socketcontroller.send( get_client_id(), 1, [1,0] );

Members

debug

Source:

io

Source:

socket_pairing_id

Source:

target

Source:

Methods

addEventListener(_trigger, _callback)

addEventListener

Parameters:
Name Type Description
_trigger integer

the unique id of the command to be sent

_callback function

a function that executes when the trigger fires

Source:
Example
function doSomething(_arr ) {
   console.log('pressed1', arr)
 }
 socketcontroller.addEventListener(1, function() )

removeEventListener(_trigger)

removeEventListener, removes event listeners.

Parameters:
Name Type Description
_trigger integer

the unique id of the command to be sent

Source:
Example
socketcontroller.removeEventListener(1)

send(_client, _trigger, _commands)

send info, an _commands array, to a client

Parameters:
Name Type Description
_client string

the client uid to be sent to, ie. ad48

_trigger integer

unique id of the command, to be interpreted on the client

_commands array

the actual _commands being send

Source:
Example
socketcontroller.send( "a78r", 0, [ "mixer1", "blend", 6 ] )
 socketcontroller.send( "a78r", 112, [ "mixer1", "pod", gamepad1.x-axis ] )
 socketcontroller.send( "a78r", 15, [ 1, 2, 3, 4 ] )