Skip to content

Commit

Permalink
Merge pull request #13 from yukirin000/master
Browse files Browse the repository at this point in the history
new version
  • Loading branch information
yukirin000 authored Jan 14, 2021
2 parents 2e40736 + c591777 commit 13598bf
Show file tree
Hide file tree
Showing 81 changed files with 19,008 additions and 1,807 deletions.
24 changes: 24 additions & 0 deletions JMRTCRN.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'json'
pjson = JSON.parse(File.read('package.json'))

Pod::Spec.new do |s|

s.name = "JMRTCRN"
s.version = pjson["version"]
s.homepage = "https://github.com/jpush/jmrtc-react-native"
s.summary = pjson["description"]
s.license = pjson["license"]
s.author = { "huminios" => "380108184@qq.com" }

s.ios.deployment_target = '7.0'

s.source = { :git => "https://github.com/jpush/jmrtc-react-native.git", :tag => "#{s.version}" }
s.source_files = 'ios/RCTJMRTCModule/*.{h,m}'
s.preserve_paths = "*.js"
s.frameworks = 'UIKit','CFNetwork','CoreFoundation','CoreTelephony','SystemConfiguration','CoreGraphics','Foundation','Security','CoreLocation','CoreAudio','AudioToolbox','AVFoundation','VideoToolbox'
s.weak_frameworks = 'UserNotifications'
s.libraries = 'z','resolv','sqlite3.0'
s.vendored_frameworks = "ios/RCTJMRTCModule/*.framework"
s.dependency 'React'
s.dependency 'JMessageRN'
end
2 changes: 1 addition & 1 deletion android/src/io/jmrtc/android/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public class Constant {
public static final String SPEAKERPHONE_ENABLED = "speakerphoneEnabled";
public static final String VIDEO_STREAM_ENABLED = "videoStreamEnabled";
public static final String SESSION = "session";
public static final String USER_INFO = "userInfo";
public static final String USER = "user";
public static final String CHANNEL_ID = "channelId";
public static final String MEDIA_TYPE = "mediaType";
public static final String INVITER = "inviter";
Expand Down
45 changes: 22 additions & 23 deletions android/src/io/jmrtc/android/JMRTCModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -298,27 +298,32 @@ public void gotResult(int status, String desc) {
@ReactMethod
public void inviteUsers(ReadableMap map, final Callback success, final Callback fail) {
try {
ReadableArray array = map.getArray(Constant.USERNAMES);
final ReadableArray array = map.getArray(Constant.USERNAMES);
final List<UserInfo> userInfos = new ArrayList<>();
final int[] cnt = {0};
for (int i = 0; i < array.size(); i++) {
JMessageClient.getUserInfo(array.getString(i), new GetUserInfoCallback() {
@Override
public void gotResult(int status, String desc, UserInfo userInfo) {
++cnt[0];
if (status == 0) {
userInfos.add(userInfo);
if (cnt[0] == array.size()) {
JMRtcClient.getInstance().invite(userInfos, new BasicCallback() {
@Override
public void gotResult(int status, String desc) {
mJMessageUtils.handleCallback(status, desc, success, fail);
}
});
}
} else {
mJMessageUtils.handleError(fail, status, desc);
}
}
});
}

JMRtcClient.getInstance().invite(userInfos, new BasicCallback() {
@Override
public void gotResult(int status, String desc) {
mJMessageUtils.handleCallback(status, desc, success, fail);
}
});


} catch (Exception e) {
e.printStackTrace();
Expand All @@ -331,7 +336,7 @@ public void gotResult(int status, String desc) {
public void setIsMuted(ReadableMap map) {
try {
boolean muted = map.getBoolean(Constant.MUTED);
JMRtcClient.getInstance().enableAudio(muted);
JMRtcClient.getInstance().enableAudio(!muted);
} catch (Exception e) {
e.printStackTrace();
Logger.d(TAG, ERR_MSG_PARAMETER);
Expand Down Expand Up @@ -374,8 +379,7 @@ public void onEngineInitComplete(final int errCode, final String errDesc) {
public void onCallOutgoing(JMRtcSession callSession) {// 通话已播出
super.onCallOutgoing(callSession);
Logger.d(TAG, "onCallOutgoing invoked!. session = " + callSession);
WritableMap map = Arguments.createMap();
map.putMap(Constant.SESSION, ResultUtils.toJSObject(callSession));
WritableMap map = ResultUtils.toJSObject(callSession);
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(CALL_OUT_GOING, map);
session = callSession;
Expand All @@ -385,8 +389,7 @@ public void onCallOutgoing(JMRtcSession callSession) {// 通话已播出
public void onCallInviteReceived(JMRtcSession callSession) {// 收到通话邀请
super.onCallInviteReceived(callSession);
Logger.d(TAG, "onCallInviteReceived invoked!. session = " + callSession);
WritableMap map = Arguments.createMap();
map.putMap(Constant.SESSION, ResultUtils.toJSObject(callSession));
WritableMap map = ResultUtils.toJSObject(callSession);
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(CALL_RECEIVE_INVITE, map);
session = callSession;
Expand All @@ -410,11 +413,10 @@ public void onCallOtherUserInvited(UserInfo fromUserInfo, List<UserInfo> invited
public void onCallConnected(JMRtcSession callSession, SurfaceView localSurfaceView) {//通话连接已建立
super.onCallConnected(callSession, localSurfaceView);
Logger.d(TAG, "onCallConnected invoked!. session = " + callSession + " localSerfaceView = " + localSurfaceView);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 1);
localSurfaceView.setLayoutParams(layoutParams);
surfaceViewCache.put(JMessageClient.getMyInfo().getUserName(), localSurfaceView);
WritableMap map = Arguments.createMap();
map.putMap(Constant.SESSION, ResultUtils.toJSObject(callSession));
WritableMap map = ResultUtils.toJSObject(callSession);
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(CALL_CONNECTED, map);
session = callSession;
Expand All @@ -426,11 +428,10 @@ public void onCallConnected(JMRtcSession callSession, SurfaceView localSurfaceVi
public void onCallMemberJoin(UserInfo joinedUserInfo, SurfaceView remoteSurfaceView) {//有其他人加入通话
super.onCallMemberJoin(joinedUserInfo, remoteSurfaceView);
Logger.d(TAG, "onCallMemberJoin invoked!. joined user = " + joinedUserInfo + " remoteSerfaceView = " + remoteSurfaceView);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 1);
remoteSurfaceView.setLayoutParams(layoutParams);
surfaceViewCache.put(joinedUserInfo.getUserName(), remoteSurfaceView);
WritableMap map = Arguments.createMap();
map.putMap(Constant.USER_INFO, ResultUtils.toJSObject(joinedUserInfo));
WritableMap map = ResultUtils.toJSObject(joinedUserInfo);
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(CALL_MEMBER_JOIN, map);
}
Expand All @@ -457,7 +458,7 @@ public void onCallMemberOffline(final UserInfo leavedUserInfo, JMRtcClient.Disco
}

WritableMap map = Arguments.createMap();
map.putMap(Constant.USER_INFO, ResultUtils.toJSObject(leavedUserInfo));
map.putMap(Constant.USER, ResultUtils.toJSObject(leavedUserInfo));
map.putString(Constant.REASON, reason.toString());
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(CALL_MEMBER_LEAVE, map);
Expand All @@ -481,8 +482,7 @@ public void onCallDisconnected(JMRtcClient.DisconnectReason reason) {//本地通
public void onCallError(int errorCode, String desc) {//通话发生错误
super.onCallError(errorCode, desc);
Logger.d(TAG, "onCallError invoked!. errCode = " + errorCode + " desc = " + desc);
WritableMap map = Arguments.createMap();
map.putMap(Constant.SESSION, ResultUtils.toJSObject(session));
WritableMap map = ResultUtils.toJSObject(session);
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(CALL_ERROR, map);
session = null;
Expand All @@ -492,8 +492,7 @@ public void onCallError(int errorCode, String desc) {//通话发生错误
public void onRemoteVideoMuted(UserInfo remoteUser, boolean isMuted) {
super.onRemoteVideoMuted(remoteUser, isMuted);
Logger.d(TAG, "onRemoteVideoMuted invoked!. remote user = " + remoteUser + " isMuted = " + isMuted);
WritableMap map = Arguments.createMap();
map.putMap(Constant.USER_INFO, ResultUtils.toJSObject(remoteUser));
WritableMap map = ResultUtils.toJSObject(remoteUser);
map.putBoolean(Constant.ENABLE, isMuted);
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(CALL_USER_VIDEOSTREAM_ENABLED, map);
Expand Down
17 changes: 3 additions & 14 deletions android/src/io/jmrtc/android/JMRTCReactPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,25 @@
import com.facebook.react.uimanager.ViewManager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import io.jmrtc.android.utils.Logger;

public class JMRTCReactPackage implements ReactPackage {

private boolean mShutdownToast;

public JMRTCReactPackage(boolean shutdownToast, boolean shutdownLog) {
Logger.SHUTDOWNTOAST = shutdownToast;
Logger.SHUTDOWNLOG = shutdownLog;
mShutdownToast = shutdownToast;
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> result = new ArrayList<>();
result.add(new JMRTCModule(reactContext, mShutdownToast));
return result;
return Arrays.<NativeModule>asList(new JMRTCModule(reactContext, false));
}

public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
List<ViewManager> viewManagers = new ArrayList<>();
viewManagers.add(new RNJMRTCViewManager());
return viewManagers;
}

}
89 changes: 66 additions & 23 deletions android/src/io/jmrtc/android/RNJMRTCViewManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.jmrtc.android;

import android.util.Log;
import android.content.Context;
import android.view.Choreographer;
import android.view.SurfaceView;
import android.view.View;
import android.widget.FrameLayout;

import com.facebook.react.uimanager.ThemedReactContext;
Expand All @@ -14,58 +16,99 @@

import io.jmrtc.android.event.AddSurfaceViewEvent;
import io.jmrtc.android.event.RemoveSurfaceViewEvent;
import io.jmrtc.android.utils.Logger;

public class RNJMRTCViewManager extends ViewGroupManager<FrameLayout> {
public class RNJMRTCViewManager extends ViewGroupManager<VideoLayout> {

private static final String TAG = RNJMRTCViewManager.class.getSimpleName();

private String username;

private FrameLayout frameLayout;

@Override
public String getName() {
return "RTCJMRTCView";
}


@Override
protected FrameLayout createViewInstance(ThemedReactContext reactContext) {
protected VideoLayout createViewInstance(ThemedReactContext reactContext) {
return new VideoLayout(reactContext);
}

@ReactProp(name = "username")
public void setUsername(final VideoLayout view, String username) {
view.username = username;
}



@Override
public void onDropViewInstance(VideoLayout view) {
super.onDropViewInstance(view);
EventBus.getDefault().unregister(view);
}
}



class VideoLayout extends FrameLayout {
private static final String TAG = VideoLayout.class.getSimpleName();

public String username;
public VideoLayout(Context context) {
super(context);
if (!EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().register(this);
}
frameLayout = new FrameLayout(reactContext, null);
return frameLayout;
Choreographer.getInstance().postFrameCallback(new Choreographer.FrameCallback() {
@Override
public void doFrame(long frameTimeNanos) {
for (int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(View.MeasureSpec.makeMeasureSpec(getMeasuredWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(getMeasuredHeight(), View.MeasureSpec.EXACTLY));
child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight());
}
getViewTreeObserver().dispatchOnGlobalLayout();
}
});
}

@ReactProp(name = "username")
public void setUsername(final FrameLayout view, String username) {
Log.i(TAG, "username:" + username);
this.username = username;


@Override
public void requestLayout() {
super.requestLayout();
post(measureAndLayout);
}

private final Runnable measureAndLayout = new Runnable() {
@Override
public void run() {
measure(
MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
layout(getLeft(), getTop(), getRight(), getBottom());
}
};



@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(AddSurfaceViewEvent event) {
Logger.d(TAG,"AddSurfaceViewEvent: " + username + " ," + event.getUsername());
if (username.equals(event.getUsername())) {
SurfaceView surfaceView = JMRTCModule.surfaceViewCache.get(username);
if (surfaceView != null) {
frameLayout.addView(surfaceView);
removeAllViews();
addView(surfaceView);
}
}
}

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(RemoveSurfaceViewEvent event) {
if (username.equals(event.getUsername())) {
if (frameLayout.getChildCount() > 0)
frameLayout.removeAllViews();
if (getChildCount() > 0)
removeAllViews();
}
}

@Override
public void onDropViewInstance(FrameLayout view) {
super.onDropViewInstance(view);
EventBus.getDefault().unregister(this);
}
}
}
3 changes: 0 additions & 3 deletions example/.babelrc

This file was deleted.

4 changes: 4 additions & 0 deletions example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native-community',
};
Loading

0 comments on commit 13598bf

Please sign in to comment.