Add initial Scarlet impl

This commit is contained in:
Mario Danic 2018-10-08 21:13:08 +02:00
parent d2ec3320c0
commit 66da39a1a1
3 changed files with 111 additions and 0 deletions

View File

@ -190,6 +190,11 @@ dependencies {
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
implementation 'com.kevalpatel2106:emoticongifkeyboard:1.1'
implementation 'com.github.tinder.scarlet:scarlet:0.1.5'
implementation 'com.github.tinder.scarlet:scarlet-stream-adapter-rxjava2:0.1.5'
implementation 'com.github.tinder.scarlet:scarlet-message-adapter-moshi:0.1.5'
implementation 'com.github.tinder.scarlet:scarlet-websocket-okhttp:0.1.5'
testImplementation 'junit:junit:4.12'
androidTestImplementation ('androidx.test.espresso:espresso-core:3.1.0-alpha4', {
exclude group: 'com.android.support', module: 'support-annotations'

View File

@ -0,0 +1,37 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.api;
import com.tinder.scarlet.WebSocket;
import com.tinder.scarlet.ws.Receive;
import io.reactivex.Flowable;
public interface ExternalSignaling {
@Receive
Flowable<WebSocket.Event.OnConnectionOpened> observeOnConnectionOpenedEvent();
@Receive
Flowable<WebSocket.Event.OnConnectionFailed> observeOnConnectionFailedEvent();
@Receive
Flowable<WebSocket.Event.OnConnectionClosed> observeOnConnectionClosedEvent();
}

View File

@ -0,0 +1,69 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.nextcloud.talk.webrtc;
import com.nextcloud.talk.api.ExternalSignaling;
import com.nextcloud.talk.application.NextcloudTalkApplication;
import com.tinder.scarlet.Scarlet;
import com.tinder.scarlet.messageadapter.moshi.MoshiMessageAdapter;
import com.tinder.scarlet.retry.ExponentialBackoffStrategy;
import com.tinder.scarlet.retry.LinearBackoffStrategy;
import com.tinder.scarlet.streamadapter.rxjava2.RxJava2StreamAdapterFactory;
import com.tinder.scarlet.websocket.okhttp.OkHttpClientUtils;
import com.tinder.scarlet.websocket.okhttp.OkHttpWebSocket;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import autodagger.AutoInjector;
import okhttp3.OkHttpClient;
@AutoInjector(NextcloudTalkApplication.class)
public class ScarletHelper {
private Map<String, ExternalSignaling> externalSignalingMap = new HashMap<>();
@Inject
OkHttpClient okHttpClient;
public ScarletHelper() {
NextcloudTalkApplication.getSharedApplication().getComponentApplication().inject(this);
}
public ExternalSignaling getExternalSignalingInstanceForServer(String url) {
if (externalSignalingMap.containsKey(url)) {
return externalSignalingMap.get(url);
} else {
Scarlet scarlet = new Scarlet.Builder()
.backoffStrategy(new LinearBackoffStrategy(500))
.webSocketFactory(OkHttpClientUtils.newWebSocketFactory(okHttpClient, url))
.addMessageAdapterFactory(new MoshiMessageAdapter.Factory())
.addStreamAdapterFactory(new RxJava2StreamAdapterFactory())
.build();
ExternalSignaling externalSignaling = scarlet.create(ExternalSignaling.class);
externalSignalingMap.put(url, externalSignaling);
return externalSignaling;
}
}
}