Nexmo / wsbridge

Other
25 stars 18 forks source link

[OPENTOK-46264] Json mute events #12

Closed brunorib closed 2 years ago

brunorib commented 2 years ago

Add JSON events api, and mute event state change

Fot trying it out: Start WS server (python server.py in wormhole-freeswitch) on port 8000 Go to fs_cli, then:

conference 101 dial {}wsbridge/ws://localhost:8000 and get uuid from created channel after the conference dial (log just after the dial command)

uuid_send_message UUID {"event":"websocket:media:update","method":"update","active":false}

jvm7293 commented 2 years ago

Consider using the following to create an abstraction for a queue. This is an approximation of a C++ class for a queue. Since this is written in C, we can do it this way. All the mutex operations are paired in individual methods which prevents a mutex from getting stuck in a locked state. Try to restructure your code using these functions below.

Take a look at the following. It has sample code for using these functions.

https://github.com/jvm7293/wsbridge/blob/feature/dummy_branch/mod_wsbridge/mod_wsbridge.c

In this file look for "TEST CODE" and you'll see the sample code for using it.

struct Queue {
    switch_queue_t *queue;
    switch_mutex_t *mutex;
    unsigned int count;
    unsigned int size;
};

void Queue_create(struct Queue *q, unsigned int capacity, switch_memory_pool_t *memory_pool) {
    q->count = 0;
    q->size = capacity;
    switch_queue_create(&q->queue, q->size, memory_pool);
    switch_mutex_init(&q->mutex, SWITCH_MUTEX_NESTED, memory_pool);
}

switch_status_t Queue_push(struct Queue *q, void *data) {
    switch_status_t rv = SWITCH_STATUS_FALSE;
    switch_mutex_lock(q->mutex);
    if ((q->count < q->size) && ((rv = switch_queue_trypush(q->queue, data)) == SWITCH_STATUS_SUCCESS)) {
        q->count++;
    }
    switch_mutex_unlock(q->mutex);
    return rv;
}

switch_status_t Queue_pop(struct Queue *q, void **data) {
    switch_status_t rv = SWITCH_STATUS_FALSE;
    *data = NULL;
    switch_mutex_lock(q->mutex);
    if ((q->count > 0) && ((rv = switch_queue_trypop(q->queue, data)) == SWITCH_STATUS_SUCCESS)) {
        q->count--;
    }
    switch_mutex_unlock(q->mutex);
    return rv;
}
odivorra commented 2 years ago

abandoned