Example #1
0
void Core::onAvCancel(void* _toxav, int32_t callId, void* core)
{
    ToxAv* toxav = static_cast<ToxAv*>(_toxav);

    int friendId = toxav_get_peer_id(toxav, callId, 0);
    if (friendId < 0)
    {
        qWarning() << "Core: Received invalid AV cancel";
        return;
    }
    qDebug() << QString("Core: AV cancel from %1").arg(friendId);

    calls[callId].active = false;

#ifdef QTOX_FILTER_AUDIO
    if (filterer[callId])
    {
        filterer[callId]->closeFilter();
        delete filterer[callId];
        filterer[callId] = nullptr;
    }
#endif

    emit static_cast<Core*>(core)->avCancel(friendId, callId);
}
Example #2
0
static void friendlist_onAv(ToxWindow *self, ToxAv *av)
{
    int id = toxav_get_peer_id(av, 0);
    id++;
    if ( id >= max_friends_index)
        return;
    
    Tox* m = toxav_get_tox(av);
    
    if (friends[id].chatwin == -1) {
        if (get_num_active_windows() < MAX_WINDOWS_NUM) {
            friends[id].chatwin = add_window(m, new_chat(m, friends[id].num));
        } else {
            uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
            tox_get_name(m, id, nick);
            nick[TOXIC_MAX_NAME_LENGTH] = '\0';
            wprintw(prompt->window, "Audio action from: %s!\n", nick);
            
            prep_prompt_win();
            wattron(prompt->window, COLOR_PAIR(RED));
            wprintw(prompt->window, "* Warning: Too many windows are open.\n");
            wattron(prompt->window, COLOR_PAIR(RED));
            
            alert_window(prompt, WINDOW_ALERT_0, true);
        }
    }
}
Example #3
0
void Core::onAvMediaChange(void* toxav, int32_t callId, void* core)
{
    int friendId;
    int cap = toxav_capability_supported((ToxAv*)toxav, callId,
                        (ToxAvCapabilities)(av_VideoEncoding|av_VideoDecoding));
    if (!cap)
        goto fail;

    friendId  = toxav_get_peer_id((ToxAv*)toxav, callId, 0);
    if (friendId < 0)
        goto fail;

    qDebug() << "Core: Received media change from friend "<<friendId;

    if (cap == (av_VideoEncoding|av_VideoDecoding)) // Video call
    {
        Camera::getInstance()->subscribe();
        calls[callId].videoEnabled = true;
        calls[callId].sendVideoTimer->start();
        emit ((Core*)core)->avMediaChange(friendId, callId, true);
    }
    else // Audio call
    {
        calls[callId].videoEnabled = false;
        calls[callId].sendVideoTimer->stop();
        Camera::getInstance()->unsubscribe();
        emit ((Core*)core)->avMediaChange(friendId, callId, false);
    }

    return;

fail: // Centralized error handling
    qWarning() << "Core: Toxcore error while receiving media change on call "<<callId;
    return;
}
Example #4
0
void Core::answerCall(int32_t callId)
{
    int friendId = toxav_get_peer_id(toxav, callId, 0);
    if (friendId < 0)
    {
        qWarning() << "Core: Received invalid AV answer peer ID";
        return;
    }

    ToxAvCSettings* transSettings = new ToxAvCSettings;
    int err = toxav_get_peer_csettings(toxav, callId, 0, transSettings);
    if (err != av_ErrorNone)
    {
         qWarning() << "Core::answerCall: error getting call settings";
         delete transSettings;
         return;
    }

    if (transSettings->call_type == av_TypeVideo)
    {
        qDebug() << QString("Core: answering call %1 with video").arg(callId);
        toxav_answer(toxav, callId, transSettings);
    }
    else
    {
        qDebug() << QString("Core: answering call %1 without video").arg(callId);
        toxav_answer(toxav, callId, transSettings);
    }

    delete transSettings;
}
Example #5
0
static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index)
{
    int id = toxav_get_peer_id(av, call_index, 0);

    if ( id != av_ErrorUnknown && id >= Friends.max_idx)
        return;

    Tox *m = toxav_get_tox(av);

    if (Friends.list[id].chatwin == -1) {
        if (get_num_active_windows() < MAX_WINDOWS_NUM) {
            if (toxav_get_call_state(av, call_index) == av_CallStarting) { /* Only open windows when call is incoming */
                Friends.list[id].chatwin = add_window(m, new_chat(m, Friends.list[id].num));
            }            
        } else {
            char nick[TOX_MAX_NAME_LENGTH];
            get_nick_truncate(m, nick, Friends.list[id].num);
            line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Audio action from: %s!", nick);

            const char *errmsg = "* Warning: Too many windows are open.";
            line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
            
            sound_notify(prompt, error, NT_WNDALERT_1, NULL);
        }
    }
}
Example #6
0
static void friendlist_onAv(ToxWindow *self, ToxAv *av, int call_index)
{
    int id = toxav_get_peer_id(av, call_index, 0);

    /*id++;*/
    if ( id != ErrorInternal && id >= max_friends_index)
        return;

    Tox *m = toxav_get_tox(av);

    if (friends[id].chatwin == -1) {
        if (get_num_active_windows() < MAX_WINDOWS_NUM) {
            friends[id].chatwin = add_window(m, new_chat(m, friends[id].num));
        } else {
            uint8_t nick[TOX_MAX_NAME_LENGTH] = {'\0'};
            int n_len = tox_get_name(m, id, nick);

            n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
            nick[n_len] = '\0';

            uint8_t msg[MAX_STR_SIZE];
            snprintf(msg, sizeof(msg), "Audio action from: %s!", nick);
            line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, 0);

            uint8_t *errmsg = "* Warning: Too many windows are open.";
            line_info_add(prompt, NULL, NULL, NULL, errmsg, SYS_MSG, 0, RED);

            alert_window(prompt, WINDOW_ALERT_0, true);
        }
    }
}
Example #7
0
void Core::onAvStart(void* _toxav, int32_t call_index, void* core)
{
    ToxAv* toxav = static_cast<ToxAv*>(_toxav);

    int friendId = toxav_get_peer_id(toxav, call_index, 0);
    if (friendId < 0)
    {
        qWarning() << "Core: Received invalid AV start";
        return;
    }

    ToxAvCSettings* transSettings = new ToxAvCSettings;
    int err = toxav_get_peer_csettings(toxav, call_index, 0, transSettings);
    if (err != av_ErrorNone)
    {
        qWarning() << "Core::onAvStart: error getting call type";
        delete transSettings;
        return;
    }

    if (transSettings->call_type == av_TypeVideo)
    {
        qDebug() << QString("Core: AV start from %1 with video").arg(friendId);
        prepareCall(friendId, call_index, toxav, true);
        emit static_cast<Core*>(core)->avStart(friendId, call_index, true);
    }
    else
    {
        qDebug() << QString("Core: AV start from %1 without video").arg(friendId);
        prepareCall(friendId, call_index, toxav, false);
        emit static_cast<Core*>(core)->avStart(friendId, call_index, false);
    }

    delete transSettings;
}
Example #8
0
void chat_onRinging (ToxWindow *self, ToxAv *av, int call_index)
{
    if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
        return;

    line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Ringing...\"cancel\" ?");
    
#ifdef _SOUND_NOTIFY
    if (self->active_sound == -1)
        self->active_sound = notify(self, call_outgoing, NT_LOOP);
#endif /* _SOUND_NOTIFY */
}
Example #9
0
void chat_onRequestTimeout (ToxWindow *self, ToxAv *av, int call_index)
{
    if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
        return;

    self->call_idx = -1;
    line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No answer!");
    
#ifdef _SOUND_NOTIFY
    stop_sound(self->active_sound);
    self->active_sound = -1;
#endif /* _SOUND_NOTIFY */
}
Example #10
0
void chat_onPeerTimeout (ToxWindow *self, ToxAv *av, int call_index)
{
    if (!self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
        return;

    kill_infobox(self);
    self->call_idx = -1;
    line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Peer disconnected; call ended!");
    
#ifdef _SOUND_NOTIFY
    stop_sound(self->active_sound);
    self->active_sound = -1;
#endif /* _SOUND_NOTIFY */
}
Example #11
0
void Core::onAvReject(void* _toxav, int32_t callId, void* core)
{
    ToxAv* toxav = static_cast<ToxAv*>(_toxav);
    int friendId = toxav_get_peer_id(toxav, callId, 0);
    if (friendId < 0)
    {
        qWarning() << "Core: Received invalid AV reject";
        return;
    }

    qDebug() << QString("Core: AV reject from %1").arg(friendId);

    emit static_cast<Core*>(core)->avRejected(friendId, callId);
}
Example #12
0
void chat_onStart (ToxWindow *self, ToxAv *av, int call_index)
{
    if ( !self || self->call_idx != call_index || self->num != toxav_get_peer_id(av, call_index, 0))
        return;

    init_infobox(self);

    line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Call started! Type: \"/hangup\" to end it.");
    
#ifdef _SOUND_NOTIFY
    stop_sound(self->active_sound);
    self->active_sound = -1;
#endif /* _SOUND_NOTIFY */
}
Example #13
0
void callback_av_start(ToxAv *av, int32_t call_index, void *that)
{
    qDebug() << "was called";
    Cyanide *cyanide = (Cyanide*)that;
    ToxAvCSettings peer_settings;
    int fid = toxav_get_peer_id(av, call_index, 0);
    toxav_get_peer_csettings(av, call_index, 0, &peer_settings);
    bool video = peer_settings.call_type == av_TypeVideo;
    if(toxav_prepare_transmission(av, call_index, 1) == 0) {
        // call started
    } else {
        qDebug() << "toxav_prepare_transmission() failed";
        return;
    }
}
Example #14
0
void chat_onInvite (ToxWindow *self, ToxAv *av, int call_index)
{
    if (!self || self->num != toxav_get_peer_id(av, call_index, 0))
        return;

    /* call_index is set here and reset on call end */
    
    self->call_idx = call_index;
    line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Incoming audio call! Type: \"/answer\" or \"/reject\"");
    
#ifdef _SOUND_NOTIFY
    if (self->active_sound == -1)
        self->active_sound = notify(self, call_incoming, NT_LOOP | NT_WNDALERT_0);
#endif /* _SOUND_NOTIFY */
}
Example #15
0
void Core::onAvCancel(void* _toxav, int32_t callId, void* core)
{
    ToxAv* toxav = static_cast<ToxAv*>(_toxav);

    int friendId = toxav_get_peer_id(toxav, callId, 0);
    if (friendId < 0)
    {
        qWarning() << "Core: Received invalid AV cancel";
        return;
    }
    qDebug() << QString("Core: AV cancel from %1").arg(friendId);

    calls[callId].active = false;

    emit static_cast<Core*>(core)->avCancel(friendId, callId);
}
Example #16
0
void Core::onAvPeerTimeout(void* _toxav, int32_t call_index, void* core)
{
    ToxAv* toxav = static_cast<ToxAv*>(_toxav);

    int friendId = toxav_get_peer_id(toxav, call_index, 0);
    if (friendId < 0)
    {
        qWarning() << "Core: Received invalid AV peer timeout";
        return;
    }
    qDebug() << QString("Core: AV peer timeout with %1").arg(friendId);

    cleanupCall(call_index);

    emit static_cast<Core*>(core)->avPeerTimeout(friendId, call_index);
}
Example #17
0
void callback_av_invite(ToxAv *av, int32_t call_index, void *that)
{
    qDebug() << "was called";
    Cyanide *cyanide = (Cyanide*)that;

    int fid = toxav_get_peer_id(av, call_index, 0);
    Friend *f = &cyanide->friends[fid];

    ToxAvCSettings peer_settings ;
    toxav_get_peer_csettings(av, call_index, 0, &peer_settings);
    bool video = peer_settings.call_type == av_TypeVideo;

    f->call_index = call_index;
    f->callstate = -2;
    emit cyanide->signal_friend_callstate(fid, f->callstate);
    emit cyanide->signal_av_invite(fid);
}
Example #18
0
void Core::onAvRinging(void* _toxav, int32_t call_index, void* core)
{
    ToxAv* toxav = static_cast<ToxAv*>(_toxav);

    int friendId = toxav_get_peer_id(toxav, call_index, 0);
    if (friendId < 0)
    {
        qWarning() << "Core: Received invalid AV ringing";
        return;
    }

    if (calls[call_index].videoEnabled)
    {
        qDebug() << QString("Core: AV ringing with %1 with video").arg(friendId);
        emit static_cast<Core*>(core)->avRinging(friendId, call_index, true);
    }
    else
    {
        qDebug() << QString("Core: AV ringing with %1 without video").arg(friendId);
        emit static_cast<Core*>(core)->avRinging(friendId, call_index, false);
    }
}
Example #19
0
void Core::onAvMediaChange(void* toxav, int32_t callId, void* core)
{
    ToxAvCSettings settings;
    toxav_get_peer_csettings((ToxAv*)toxav, callId, 0, &settings);
    int friendId = toxav_get_peer_id((ToxAv*)toxav, callId, 0);

    qWarning() << "Core: Received media change from friend "<<friendId;

    if (settings.call_type == TypeAudio)
    {
        calls[callId].videoEnabled = false;
        calls[callId].sendVideoTimer->stop();
        Widget::getInstance()->getCamera()->unsuscribe();
        emit ((Core*)core)->avMediaChange(friendId, callId, false);
    }
    else
    {
        Widget::getInstance()->getCamera()->suscribe();
        calls[callId].videoEnabled = true;
        calls[callId].sendVideoTimer->start();
        emit ((Core*)core)->avMediaChange(friendId, callId, true);
    }
}