Mixer Interactive C++ SDK
interactivity.h
1 //*********************************************************
2 //
3 // Copyright (c) Microsoft. All rights reserved.
4 // THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
5 // ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
6 // IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
7 // PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
8 //
9 //*********************************************************
10 #pragma once
11 
23 extern "C" {
24 
29  {
30  const char* id;
31  size_t idLength;
32  };
38  int interactive_auth_get_short_code(const char* clientId, const char* clientSecret, char* shortCode, size_t* shortCodeLength, char* shortCodeHandle, size_t* shortCodeHandleLength);
45 
53  int interactive_auth_wait_short_code(const char* clientId, const char* clientSecret, const char* shortCodeHandle, char* refreshToken, size_t* refreshTokenLength);
54 
58  int interactive_auth_is_token_stale(const char* token, bool* isStale);
59 
66  int interactive_auth_refresh_token(const char* clientId, const char* clientSecret, const char* staleToken, char* refreshToken, size_t* refreshTokenLength);
67 
71  int interactive_auth_parse_refresh_token(const char* token, char* authorization, size_t* authorizationLength);
77  typedef void* interactive_session;
81 
90 
99  int interactive_connect(interactive_session session, const char* auth, const char* versionId, const char* shareCode, bool setReady);
100 
108  int interactive_set_ready(interactive_session session, bool isReady);
109 
116  int interactive_run(interactive_session session, unsigned int maxEventsToProcess);
117 
118  enum interactive_state
119  {
120  interactive_disconnected,
121  interactive_connecting,
122  interactive_connected,
123  interactive_ready
124  };
125 
129  int interactive_get_state(interactive_session session, interactive_state* state);
130 
134  int interactive_set_session_context(interactive_session session, void* context);
135 
139  int interactive_get_session_context(interactive_session session, void** context);
140 
141  enum interactive_throttle_type
142  {
143  throttle_global,
144  throttle_input,
145  throttle_participant_join,
146  throttle_participant_leave
147  };
148 
155  int interactive_set_bandwidth_throttle(interactive_session session, interactive_throttle_type throttleType, unsigned int maxBytes, unsigned int bytesPerSecond);
156 
162  int interactive_capture_transaction(interactive_session session, const char* transactionId);
163 
178  struct interactive_user
182  {
183  unsigned int id;
184  const char* userName;
185  bool isBroadcasting;
186  unsigned int level;
187  unsigned int experience;
188  unsigned int sparks;
189  const char* avatarUrl;
190  };
191 
195  typedef void(*on_interactive_user)(void* context, interactive_session session, const interactive_user* user);
196 
204 
210  {
211  const char* kind;
212  size_t kindLength;
213  };
214 
215  enum interactive_control_event
216  {
217  interactive_control_created,
218  interactive_control_updated,
219  interactive_control_deleted
220  };
221 
222  // Known control properties
223  #define CONTROL_PROP_DISABLED "disabled"
224  #define CONTROL_PROP_POSITION "position"
225 
226  #define BUTTON_PROP_KEY_CODE "keyCode"
227  #define BUTTON_PROP_TEXT "text"
228  #define BUTTON_PROP_TOOLTIP "tooltip"
229  #define BUTTON_PROP_COST "cost"
230  #define BUTTON_PROP_PROGRESS "progress"
231  #define BUTTON_PROP_COOLDOWN "cooldown"
232 
233  #define JOYSTICK_PROP_SAMPLE_RATE "sampleRate"
234  #define JOYSTICK_PROP_ANGLE "angle"
235  #define JOYSTICK_PROP_INTENSITY "intensity"
236 
237  enum interactive_property_type
238  {
239  interactive_unknown_t,
240  interactive_int_t,
241  interactive_bool_t,
242  interactive_float_t,
243  interactive_string_t,
244  interactive_array_t,
245  interactive_object_t
246  };
247 
248  typedef void(*on_control_enumerate)(void* context, interactive_session session, const interactive_control* control);
249 
253  int interactive_control_trigger_cooldown(interactive_session session, const char* controlId, const unsigned long long cooldownMs);
254 
258  int interactive_control_get_property_count(interactive_session session, const char* controlId, size_t* count);
259 
263  int interactive_control_get_property_data(interactive_session session, const char* controlId, size_t index, char* propName, size_t* propNameLength, interactive_property_type* type);
264 
268  int interactive_control_get_meta_property_count(interactive_session session, const char* controlId, size_t* count);
269 
273  int interactive_control_get_meta_property_data(interactive_session session, const char* controlId, size_t index, char* propName, size_t* propNameLength, interactive_property_type* type);
274 
278  int interactive_control_get_property_int(interactive_session session, const char* controlId, const char* key, int* property);
279 
283  int interactive_control_get_property_int64(interactive_session session, const char* controlId, const char* key, long long* property);
284 
288  int interactive_control_get_property_bool(interactive_session session, const char* controlId, const char* key, bool* property);
289 
293  int interactive_control_get_property_float(interactive_session session, const char* controlId, const char* key, float* property);
294 
298  int interactive_control_get_property_string(interactive_session session, const char* controlId, const char* key, char* property, size_t* propertyLength);
299 
303  int interactive_control_set_property_null(interactive_session session, const char* controlId, const char* key);
304 
308  int interactive_control_set_property_int(interactive_session session, const char* controlId, const char* key, int property);
309 
313  int interactive_control_set_property_int64(interactive_session session, const char* controlId, const char* key, long long property);
314 
318  int interactive_control_set_property_bool(interactive_session session, const char* controlId, const char* key, bool property);
319 
323  int interactive_control_set_property_float(interactive_session session, const char* controlId, const char* key, float property);
324 
328  int interactive_control_set_property_string(interactive_session session, const char* controlId, const char* key, char* property);
329 
333  int interactive_control_get_meta_property_int(interactive_session session, const char* controlId, const char* key, int* property);
334 
338  int interactive_control_get_meta_property_int64(interactive_session session, const char* controlId, const char* key, long long* property);
339 
343  int interactive_control_get_meta_property_bool(interactive_session session, const char* controlId, const char* key, bool* property);
344 
348  int interactive_control_get_meta_property_float(interactive_session session, const char* controlId, const char* key, float* property);
349 
353  int interactive_control_get_meta_property_string(interactive_session session, const char* controlId, const char* key, char* property, size_t* propertyLength);
361  {
362  const char* sceneId;
363  size_t sceneIdLength;
364  };
365 
369  typedef void(*on_group_enumerate)(void* context, interactive_session session, const interactive_group* group);
370 
375 
380  int interactive_create_group(interactive_session session, const char* groupId, const char* sceneId);
381 
385  int interactive_group_set_scene(interactive_session session, const char* groupId, const char* sceneId);
393  {
394  };
395 
399  typedef void(*on_scene_enumerate)(void* context, interactive_session session, const interactive_scene* scene);
400 
405 
409  int interactive_scene_get_groups(interactive_session session, const char* sceneId, on_group_enumerate onGroup);
410 
414  int interactive_scene_get_controls(interactive_session session, const char* sceneId, on_control_enumerate onControl);
420  typedef void(*on_error)(void* context, interactive_session session, int errorCode, const char* errorMessage, size_t errorMessageLength);
427 
431  typedef void(*on_state_changed)(void* context, interactive_session session, interactive_state previousState, interactive_state newState);
432 
433  enum interactive_input_type
434  {
435  input_type_key,
436  input_type_click,
437  input_type_move,
438  input_type_custom
439  };
440 
441  enum interactive_button_action
442  {
443  interactive_button_action_up,
444  interactive_button_action_down
445  };
446 
448  {
449  interactive_control control;
450  interactive_input_type type;
451  const char* participantId;
452  size_t participantIdLength;
453  const char* jsonData;
454  size_t jsonDataLength;
455  const char* transactionId;
456  size_t transactionIdLength;
457  struct buttonData
458  {
459  interactive_button_action action;
460  } buttonData;
462  {
463  float x;
464  float y;
465  } coordinateData;
466  };
467 
471  typedef void(*on_input)(void* context, interactive_session session, const interactive_input* input);
472 
474  {
475  unsigned int userId;
476  const char* userName;
477  size_t usernameLength;
478  unsigned int level;
479  unsigned long long lastInputAtMs;
480  unsigned long long connectedAtMs;
481  bool disabled;
482  const char* groupId;
483  size_t groupIdLength;
484  };
485 
486  enum interactive_participant_action
487  {
488  participant_join,
489  participant_leave,
490  participant_update
491  };
492 
496  typedef void(*on_participants_changed)(void* context, interactive_session session, interactive_participant_action action, const interactive_participant* participant);
497 
501  typedef void(*on_transaction_complete)(void* context, interactive_session session, const char* transactionId, size_t transactionIdLength, unsigned int error, const char* errorMessage, size_t errorMessageLength);
502 
506  typedef void(*on_control_changed)(void* context, interactive_session session, interactive_control_event eventType, const interactive_control* control);
507 
511  typedef void(*on_unhandled_method)(void* context, interactive_session session, const char* methodJson, size_t methodJsonLength);
512 
517 
522 
527 
532 
537 
542 
553  typedef void(*on_participant_enumerate)(void* context, interactive_session session, const interactive_participant* participant);
554 
558  int interactive_get_participants(interactive_session session, on_participant_enumerate onParticipant);
559 
563  int interactive_participant_set_group(interactive_session session, const char* participantId, const char* groupId);
564 
568  int interactive_participant_get_user_id(interactive_session session, const char* participantId, unsigned int* userId);
569 
573  int interactive_participant_get_user_name(interactive_session session, const char* participantId, char* userName, size_t* userNameLength);
574 
578  int interactive_participant_get_level(interactive_session session, const char* participantId, unsigned int* level);
579 
583  int interactive_participant_get_last_input_at(interactive_session session, const char* participantId, unsigned long long* lastInputAt);
584 
588  int interactive_participant_get_connected_at(interactive_session session, const char* participantId, unsigned long long* connectedAt);
589 
593  int interactive_participant_is_disabled(interactive_session session, const char* participantId, bool* isDisabled);
594 
598  int interactive_participant_get_group(interactive_session session, const char* participantId, char* group, size_t* groupLength);
605  typedef void(*on_method_reply)(void* context, interactive_session session, const char* replyJson, size_t replyJsonLength);
606 
611  int interactive_queue_method(interactive_session session, const char* method, const char* paramsJson, const on_method_reply onReply);
612 
618  enum interactive_debug_level
619  {
620  interactive_debug_none = 0,
621  interactive_debug_error,
622  interactive_debug_warning,
623  interactive_debug_info,
624  interactive_debug_trace
625  };
626 
630  typedef void(*on_debug_msg)(const interactive_debug_level dbgMsgType, const char* dbgMsg, size_t dbgMsgSize);
631 
635  void interactive_config_debug_level(const interactive_debug_level dbgLevel);
636 
640  void interactive_config_debug(const interactive_debug_level dbgLevel, on_debug_msg dbgCallback);
646  typedef enum mixer_result_code
647  {
648  MIXER_OK,
649  MIXER_ERROR,
650  MIXER_ERROR_AUTH,
651  MIXER_ERROR_AUTH_DENIED,
652  MIXER_ERROR_AUTH_INVALID_TOKEN,
653  MIXER_ERROR_BUFFER_SIZE,
654  MIXER_ERROR_CANCELLED,
655  MIXER_ERROR_HTTP,
656  MIXER_ERROR_INIT,
657  MIXER_ERROR_INVALID_CALLBACK,
658  MIXER_ERROR_INVALID_CLIENT_ID,
659  MIXER_ERROR_INVALID_OPERATION,
660  MIXER_ERROR_INVALID_POINTER,
661  MIXER_ERROR_INVALID_PROPERTY_TYPE,
662  MIXER_ERROR_INVALID_VERSION_ID,
663  MIXER_ERROR_JSON_PARSE,
664  MIXER_ERROR_METHOD_CREATE,
665  MIXER_ERROR_NO_HOST,
666  MIXER_ERROR_NO_REPLY,
667  MIXER_ERROR_OBJECT_NOT_FOUND,
668  MIXER_ERROR_PROPERTY_NOT_FOUND,
669  MIXER_ERROR_TIMED_OUT,
670  MIXER_ERROR_UNKNOWN_METHOD,
671  MIXER_ERROR_UNRECOGNIZED_DATA_FORMAT,
672  MIXER_ERROR_WS_CLOSED,
673  MIXER_ERROR_WS_CONNECT_FAILED,
674  MIXER_ERROR_WS_DISCONNECT_FAILED,
675  MIXER_ERROR_WS_READ_FAILED,
676  MIXER_ERROR_WS_SEND_FAILED,
677  MIXER_ERROR_NOT_CONNECTED,
678  MIXER_ERROR_OBJECT_EXISTS,
679  MIXER_ERROR_INVALID_STATE
680  } mixer_result_code;
683 }
684 
int interactive_control_get_meta_property_float(interactive_session session, const char *controlId, const char *key, float *property)
Get a float meta property value by name.
int interactive_control_set_property_string(interactive_session session, const char *controlId, const char *key, char *property)
Set a char* property value by name.
int interactive_control_get_meta_property_int(interactive_session session, const char *controlId, const char *key, int *property)
Get an int meta property value by name.
int interactive_set_input_handler(interactive_session session, on_input onInput)
Set the handler function for interactive input. This function is called by your own thread during int...
void(* on_group_enumerate)(void *context, interactive_session session, const interactive_group *group)
Callback for interactive_get_groups.
Definition: interactivity.h:369
Definition: interactivity.h:209
int interactive_control_set_property_int(interactive_session session, const char *controlId, const char *key, int property)
Set an int property value by name.
int interactive_get_user(interactive_session session, on_interactive_user onUser)
Get the current authenticated user's data. onUser will be called when the request completes...
int interactive_control_get_meta_property_string(interactive_session session, const char *controlId, const char *key, char *property, size_t *propertyLength)
Get a char* meta property value by name.
int interactive_control_set_property_float(interactive_session session, const char *controlId, const char *key, float property)
Set a float property value by name.
int interactive_control_get_meta_property_count(interactive_session session, const char *controlId, size_t *count)
Get the number of meta properties on the control.
int interactive_set_error_handler(interactive_session session, on_error onError)
Set the handler function for errors. This function may be called by a background thread so be careful...
int interactive_control_get_property_string(interactive_session session, const char *controlId, const char *key, char *property, size_t *propertyLength)
Get a char* property value by name.
int interactive_control_get_meta_property_bool(interactive_session session, const char *controlId, const char *key, bool *property)
Get a bool meta property value by name.
int interactive_auth_get_short_code(const char *clientId, const char *clientSecret, char *shortCode, size_t *shortCodeLength, char *shortCodeHandle, size_t *shortCodeHandleLength)
Get a short code that can be used to obtain an OAuth token from https://www.mixer.com/go?code=SHORTCODE.
int interactive_get_groups(interactive_session session, on_group_enumerate onGroup)
Get the interactive groups for the specified session.
int interactive_set_state_changed_handler(interactive_session session, on_state_changed onStateChanged)
Set the handler function for state changes. This function is called by your own thread during interac...
void(* on_scene_enumerate)(void *context, interactive_session session, const interactive_scene *scene)
Callback for interactive_get_scenes
Definition: interactivity.h:399
User data for the connected user. Call interactive_get_user after connecting.
Definition: interactivity.h:181
int interactive_capture_transaction(interactive_session session, const char *transactionId)
Capture a transaction to charge a participant the input's spark cost. This should be called before ta...
int interactive_participant_get_connected_at(interactive_session session, const char *participantId, unsigned long long *connectedAt)
Get the participant's unix millisecond timestamp when they connected to the session.
int interactive_get_session_context(interactive_session session, void **context)
Get the previously set session context. Context will be nullptr on return if no context has been set...
int interactive_participant_get_level(interactive_session session, const char *participantId, unsigned int *level)
Get the participant's level.
Definition: interactivity.h:461
int interactive_participant_get_group(interactive_session session, const char *participantId, char *group, size_t *groupLength)
Get the participant's group name.
Definition: interactivity.h:392
int interactive_control_get_property_count(interactive_session session, const char *controlId, size_t *count)
Get the number of properties on the control.
int interactive_set_participants_changed_handler(interactive_session session, on_participants_changed onParticipantsChanged)
Set the handler function for participants changing. This function is called by your own thread during...
int interactive_scene_get_controls(interactive_session session, const char *sceneId, on_control_enumerate onControl)
Get a scene's controls for the specified session.
void * interactive_session
An opaque handle to an interactive session.
Definition: interactivity.h:80
void(* on_transaction_complete)(void *context, interactive_session session, const char *transactionId, size_t transactionIdLength, unsigned int error, const char *errorMessage, size_t errorMessageLength)
Callback when a transaction completes.
Definition: interactivity.h:501
void(* on_unhandled_method)(void *context, interactive_session session, const char *methodJson, size_t methodJsonLength)
Callback when any method is called that is not handled by the existing callbacks. This may be useful ...
Definition: interactivity.h:511
void(* on_state_changed)(void *context, interactive_session session, interactive_state previousState, interactive_state newState)
Callback when the interactive state changes between disconnected, ready, and not ready.
Definition: interactivity.h:431
int interactive_get_scenes(interactive_session session, on_scene_enumerate onScene)
Get all scenes for the specified session.
int interactive_control_trigger_cooldown(interactive_session session, const char *controlId, const unsigned long long cooldownMs)
Trigger a cooldown on a control for the specified number of milliseconds.
int interactive_create_group(interactive_session session, const char *groupId, const char *sceneId)
Create a new group for the specified session with the specified scene for participants in this group...
void(* on_debug_msg)(const interactive_debug_level dbgMsgType, const char *dbgMsg, size_t dbgMsgSize)
Callback whenever a debug event happens.
Definition: interactivity.h:630
void interactive_config_debug(const interactive_debug_level dbgLevel, on_debug_msg dbgCallback)
Configure the debug verbosity and set the debug callback function for all interactive sessions in the...
int interactive_auth_refresh_token(const char *clientId, const char *clientSecret, const char *staleToken, char *refreshToken, size_t *refreshTokenLength)
Refresh a stale refreshToken.
int interactive_participant_get_last_input_at(interactive_session session, const char *participantId, unsigned long long *lastInputAt)
Get the participant's last input time as a unix millisecond timestamp.
int interactive_set_unhandled_method_handler(interactive_session session, on_unhandled_method onUnhandledMethod)
Set the handler function for unhandled methods. This may be useful for more advanced scenarios or fut...
Definition: interactivity.h:457
void(* on_control_changed)(void *context, interactive_session session, interactive_control_event eventType, const interactive_control *control)
Callback when a control is created, added, or deleted.
Definition: interactivity.h:506
int interactive_participant_set_group(interactive_session session, const char *participantId, const char *groupId)
Change the participant's group Use this along with interactive_group_set_scene to configure which sce...
int interactive_set_transaction_complete_handler(interactive_session session, on_transaction_complete onTransactionComplete)
Set the handler function for spark transaction completion. This function is called by your own thread...
void(* on_participants_changed)(void *context, interactive_session session, interactive_participant_action action, const interactive_participant *participant)
Callback when an interactive participant changes.
Definition: interactivity.h:496
int interactive_auth_is_token_stale(const char *token, bool *isStale)
Determine if a refreshToken returned by interactive_auth_wait_short_code is stale. A token is stale if it has exceeded its half-life.
int interactive_control_get_property_int64(interactive_session session, const char *controlId, const char *key, long long *property)
Get a long long property value by name.
void interactive_close_session(interactive_session session)
Disconnect from an interactive session and clean up memory.
int interactive_set_control_changed_handler(interactive_session session, on_control_changed onControlChanged)
Set the handler function for changes to controls. This function is called by your own thread during i...
void(* on_input)(void *context, interactive_session session, const interactive_input *input)
Callback when an interactive participant gives input during the session.
Definition: interactivity.h:471
int interactive_group_set_scene(interactive_session session, const char *groupId, const char *sceneId)
Set a group's scene for the specified session. Use this and interative_set_participant_group to manag...
int interactive_queue_method(interactive_session session, const char *method, const char *paramsJson, const on_method_reply onReply)
Send a method to the interactive session. This may be used to interface with the interactive protocol...
void(* on_error)(void *context, interactive_session session, int errorCode, const char *errorMessage, size_t errorMessageLength)
Callback for any errors that may occur during the session.
Definition: interactivity.h:426
int interactive_control_get_property_data(interactive_session session, const char *controlId, size_t index, char *propName, size_t *propNameLength, interactive_property_type *type)
Get the name and type of the property at the given index.
int interactive_control_get_property_float(interactive_session session, const char *controlId, const char *key, float *property)
Get a float property value by name.
int interactive_get_state(interactive_session session, interactive_state *state)
Get the current interactive_state for the specified session.
int interactive_participant_is_disabled(interactive_session session, const char *participantId, bool *isDisabled)
Is the participant's input disabled?
int interactive_control_get_meta_property_data(interactive_session session, const char *controlId, size_t index, char *propName, size_t *propNameLength, interactive_property_type *type)
Get the name and type of the meta property at the given index.
int interactive_control_set_property_bool(interactive_session session, const char *controlId, const char *key, bool property)
Set a bool property value by name.
int interactive_control_get_property_bool(interactive_session session, const char *controlId, const char *key, bool *property)
Get a bool property value by name.
Definition: interactivity.h:360
int interactive_control_get_property_int(interactive_session session, const char *controlId, const char *key, int *property)
Get an int property value by name.
Definition: interactivity.h:473
Definition: interactivity.h:447
int interactive_control_set_property_int64(interactive_session session, const char *controlId, const char *key, long long property)
Set a long long property value by name.
int interactive_auth_wait_short_code(const char *clientId, const char *clientSecret, const char *shortCodeHandle, char *refreshToken, size_t *refreshTokenLength)
Wait for a shortCode to be authorized or rejected after presenting the OAuth short code web page...
int interactive_set_ready(interactive_session session, bool isReady)
Set the ready state for specified session. No participants will be able to see interactive scenes or ...
int interactive_open_session(interactive_session *session)
Open an interactive_session. A pointer to an interactive_session that will be allocated internally...
int interactive_auth_parse_refresh_token(const char *token, char *authorization, size_t *authorizationLength)
Parse a refreshToken to get the authorization header that should be passed to interactive_open_sessio...
int interactive_participant_get_user_id(interactive_session session, const char *participantId, unsigned int *userId)
Get the participant's user id.
int interactive_scene_get_groups(interactive_session session, const char *sceneId, on_group_enumerate onGroup)
Get each group that this scene belongs to for the specified session.
int interactive_get_participants(interactive_session session, on_participant_enumerate onParticipant)
Get all participants (viewers) for the specified session.
int interactive_run(interactive_session session, unsigned int maxEventsToProcess)
This function processes the specified number of events from the interactive service and calls back on...
void interactive_config_debug_level(const interactive_debug_level dbgLevel)
Configure the debug verbosity for all interactive sessions in the current process.
Definition: interactivity.h:28
int interactive_participant_get_user_name(interactive_session session, const char *participantId, char *userName, size_t *userNameLength)
Get the participant's user name.
int interactive_set_session_context(interactive_session session, void *context)
Set a session context that will be passed to every event callback. This context pointer is not read o...
int interactive_connect(interactive_session session, const char *auth, const char *versionId, const char *shareCode, bool setReady)
Asynchronously connect an interactive session. Call interactive_run to bootstrap the connection and c...
int interactive_set_bandwidth_throttle(interactive_session session, interactive_throttle_type throttleType, unsigned int maxBytes, unsigned int bytesPerSecond)
Set a throttle for server to client messages on this interactive session.
void(* on_interactive_user)(void *context, interactive_session session, const interactive_user *user)
Callback for interactive_get_user when the user's data is ready.
Definition: interactivity.h:195
int interactive_control_set_property_null(interactive_session session, const char *controlId, const char *key)
Set a control property to null.
int interactive_control_get_meta_property_int64(interactive_session session, const char *controlId, const char *key, long long *property)
Get a long long meta property value by name.