node.js - Drupal ajax form to upload image can't update nodejs socket content -


i'm trying make chat in drupal7 site.

and choose nodejs_chat.

the module allow input text message each us, not enough .

we need upload image.

so make ajax form under chat in page, can upload image.

the form code :

function _test_form($form, &$form_state) {   $form['image_fid'] = array(     '#title' => t('image'),     '#type' => 'managed_file',     '#default_value' => '',     '#upload_location' => 'public://image_example_images/',   );   $form['submit'] = array(     '#type' => 'submit',     '#value' => t('submit'),     '#submit' => array('_test_form_submit'),     '#validate' => array(),     '#ajax' => array(       'callback' => '_test_ajax_ab_callback',       'progress' => array(         'type' => 'throbber',         'message' => '',       ),      ),   );   return $form; } 

and submit hander code :

function _test_form_submit($form, &$form_state) {   if ($form_state['values']['image_fid'] != 0) {     // new file's status set 0 or temporary , in order ensure     // file not removed after 6 hours need change it's status     // 1. save id of uploaded image later use.     $file = file_load($form_state['values']['image_fid']);     $file->status = file_status_permanent;     file_save($file);      // when module managing file, must manage usage count.     // here increment usage count file_usage_add().     file_usage_add($file, 'test', 'test_image', 1);      // save fid of file module can reference later.      global $user;     $img = theme('image_style', array('path' => $file->uri, 'style_name' => 'medium'));      $message = (object) array(       'channel' => 'chat__testing_test_1',       'callback' => 'nodejschatmessagehandler',       'data' => array(         'uid' => $user->uid,         'name' => $user->name,         'msg' => 'upload image',         'img' => $img,       ),     );     nodejs_send_content_channel_message($message);   } } 

in form submit handler, 2 things:

1) save file, , theme it.

2) use nodejs api nodejs_send_content_channel_message insert content nodejs socket.

but now, there's big problem.

if there're a, b, c people in same chatroom.

when upload image, b , c can see image, can't.

and found drupal ajax have problem, not update nodejs socket content of user ( launch ajax ) .

if use custom ajax ( write $.ajax myself ) , ok.

does have idea ?

thanks

i don't know if can here case:

i modified chatroom module (with drupal nodejs integration module) add image upload.

my submit form yours , result describe here : no image owner before refresh displayed others.

on server, 1 diference between text message , image message cliensocketid. - client id image (not working) - empty text (working)

so modified nodejs integration module, forcing cliensocketid empty.

i still don't know how text message of original chat module has empty cliensocketid , if callback behavior works designed solve problem.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -