Home Reference Source Test
import {Socket} from '@mixer/cdk'
public class | source

Socket

Extends:

eventemitter3~EventEmitter → Socket

The socket wraps the RPC instance and provides an event emitter than fires when various Interactive events come in. These events correspond with the onSomething... methods as documented in the protocol specification. The payload of the event corresponds with the params from the events that the Interactive service sends. For example:

mixer.socket.on('onReady', data => {
 console.log('Are the controls ready?', data.isReady);
});
mixer.socket.on('onSceneCreate', scene => {
  // do something with the newly created scene...
});

Method Summary

Public Methods
public

call(method: string, params: *, waitForReply: boolean): Promise.<object> | undefined

Makes a call to the Interactive service.

public

Sets the handler to use when the CDK requests a dump of the current controls state.

Public Methods

public call(method: string, params: *, waitForReply: boolean): Promise.<object> | undefined source

Makes a call to the Interactive service. This is just like sending a call over the Interactive protocol, however the only available methods are giveInput and getTime.

For example:

// All giveInput calls must contain at minimum the event and control ID.
// Everything else is passed through to the game client verbatim.
mixer.socket.call('giveInput', {
  event: 'click',
  controlID: 'my_button',
  moreCustomData: true,
});

Params:

NameTypeAttributeDescription
method string
params *
waitForReply boolean
  • optional
  • default: true

Return:

Promise.<object> | undefined

If waitForReply is true, a promise is returned that resolves once the server responds.

public dumpHandler(fn: function(): IStateDump) source

Sets the handler to use when the CDK requests a dump of the current controls state. It should return metadata about the scenes. This will help in your debugging, but you do not have to implement it.

Params:

NameTypeAttributeDescription
fn function(): IStateDump