Esempio n. 1
0
int main(void){
  ortc_context *context;

  isWaiting = 1;

  context = ortc_create_context();
  ortc_set_cluster(context, ORTC_CLUSTER);

  ortc_set_onConnected   (context, onConnected);
  ortc_set_onDisconnected(context, onDisconnected);
  ortc_set_onSubscribed  (context, onSubscribed);

  ortc_connect(context, ORTC_APP_KEY, ORTC_AUTH_TOKEN);

  while(isWaiting)
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
	Sleep(1000);
#else
	sleep(1);
#endif

  ortc_free_context(context);
}
int main(void){
  char key = ' ';
  ortc_context *context;
  ortc_channelPermissions chPerm[] = { 
    {"yellow", "rwp"},
    {"blue", "rw"},
    {"black", "w"}
  };

#if _MSC_VER
  SetConsoleOutputCP(65001);
#endif

  context = ortc_create_context();
  ortc_set_cluster(context, ORTC_CLUSTER);
  ortc_set_connection_metadata(context, "api c example metadata");

  ortc_set_onConnected   (context, onConnected);
  ortc_set_onDisconnected(context, onDisconnected);
  ortc_set_onSubscribed  (context, onSubscribed);
  ortc_set_onUnsubscribed(context, onUnsubscribed);
  ortc_set_onException   (context, onException);
  ortc_set_onReconnected (context, onReconnected);
  ortc_set_onReconnecting(context, onReconnecting);

  print_help();
  while(key!='q'){
    key = getchar();
    switch(key) {
    case 'h':
      print_help();
      break;
    case 'v':
      print_version();
      break;
    case 'c':
      ortc_connect(context, ORTC_APP_KEY, ORTC_AUTH_TOKEN);
      break;
    case 'd':
      ortc_disconnect(context);
      break;
    case 's':
      ortc_subscribe(context, DEFAULT_CHANNEL, 1, onMessage);
      break;
    case 'u':
      ortc_unsubscribe(context, DEFAULT_CHANNEL);
      break;
    case 'm':
      ortc_send(context, DEFAULT_CHANNEL, "api C message");
      break;
    case 'p':
      ortc_presence(context, DEFAULT_CHANNEL, onPresence);
      break;
    case 'e':
      ortc_presence_ex(context, ORTC_CLUSTER, 1, ORTC_APP_KEY, ORTC_AUTH_TOKEN, DEFAULT_CHANNEL, onPresence);
      break;
    case 'i':
      printf("Is subscribed? %s\n", (ortc_is_subscribed(context, DEFAULT_CHANNEL)?"true":"false"));
      break;
    case '1':
      ortc_enable_presence(context, ORTC_PRV_KEY, DEFAULT_CHANNEL, 1, onPresenceCommand);
      break;
    case '0':
      printf("Is connected? %s\n", (ortc_is_connected(context)?"true":"false"));
      break;
    case '2':
      ortc_disable_presence(context, ORTC_PRV_KEY, DEFAULT_CHANNEL, onPresenceCommand);
      break;
    case '3':
      ortc_enable_presence_ex(context, ORTC_CLUSTER, 1, ORTC_APP_KEY, ORTC_PRV_KEY, DEFAULT_CHANNEL, 1, onPresenceCommand);
      break;
    case '4':
      ortc_disable_presence_ex(context, ORTC_CLUSTER, 1, ORTC_APP_KEY, ORTC_PRV_KEY, DEFAULT_CHANNEL, onPresenceCommand);
      break;
    case 'a':
      ortc_save_authentication(context, ORTC_AUTH_TOKEN, 0, 3600, ORTC_PRV_KEY, chPerm, 3, onAuthentication);
      break;
    case '5':
      ortc_save_authentication_ex(context, ORTC_CLUSTER, 1, ORTC_AUTH_TOKEN, 0, ORTC_APP_KEY, 3600, ORTC_PRV_KEY, chPerm, 3, onAuthentication);
      break;
    case 'z':
      printf("Session ID: %s\n", ortc_get_sessionId(context));
      break;
    }
  }
  ortc_free_context(context);
  return 0;
}