This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
forked from rokihiro/webrtc-handson
-
Notifications
You must be signed in to change notification settings - Fork 1
2.5.相手へ発信
hkato edited this page Mar 27, 2016
·
4 revisions
Java
// 接続相手を選択する
private void getPeerList(){
if ((null == _peer) || (null == _id) || (0 == _id.length())){
return;
}
_listPeerIds.clear();
_peer.listAllPeers(new OnCallback() {
@Override
public void onCallback(Object object) {
JSONArray peers = (JSONArray) object;
for (int i = 0; peers.length() > i; i++) {
String strValue = "";
try {
strValue = peers.getString(i);
} catch (Exception e) {
e.printStackTrace();
}
if (0 != _id.compareToIgnoreCase(strValue)) {
_listPeerIds.add(strValue);
}
}
if ((null != _listPeerIds) && (0 < _listPeerIds.size())) {
showPeerListDialog();
}
}
});
}
Objective-C
//接続相手を選択する
- (void)getPeerList
{
if ((nil == _peer) || (nil == _id) || (0 == _id.length)){
return;
}
[_peer listAllPeers:^(NSArray* peers)
{
_listPeerIds = [[NSMutableArray alloc] init];
for (NSString* strValue in peers)
{
if (NSOrderedSame == [_id caseInsensitiveCompare:strValue])
{
continue;
}
[_listPeerIds addObject:strValue];
}
if((nil != _listPeerIds) && (0< [_listPeerIds count]))
{
[self showPeerListDialog];
}
}];
}
Swift
func getPeerList(){
if (_peer == nil) || (_id == nil) || (_id?.characters.count == 0) {
return
}
_peer?.listAllPeers({ (peers:[AnyObject]!) -> Void in
self._listPeerIds = []
let peersArray:[String] = peers as! [String]
for strValue:String in peersArray{
if strValue == self._id{
continue
}
self._listPeerIds.append(strValue)
}
if self._listPeerIds.count > 0{
self.showPeerDialog()
}
})
}
Java
// ビデオ通話をかける
private void call(String strPeerId){
CallOption option = new CallOption();
_media = _peer.call(strPeerId, _msLocal, option);
if (null != _media){
setMediaCallback(_media);
_bEstablished = true;
}
updateUI();
}
// ビデオ通話を終了する
private void close(){
if (_bEstablished) {
_bEstablished = false;
if (null != _media) {
_media.close();
}
}
}
Objective-C
- (void)call:(NSString *)strDestId
{
SKWCallOption *option = [[SKWCallOption alloc]init];
_mediaConnection = [_peer callWithId:strDestId stream:_msLocal options:option];
if(_mediaConnection != nil){
[self setMediaCallbacks:_mediaConnection];
_bEstablished = YES;
}
[self updateUI];
}
//ビデオ通話を終了する
- (void)closeChat
{
if (nil != _mediaConnection)
{
if (nil != _msRemote)
{
SKWVideo* video = (SKWVideo *)[self.view viewWithTag:TAG_REMOTE_VIDEO];
if (nil != video)
{
[video removeSrc:_msRemote track:0];
}
[_msRemote close];
_msRemote = nil;
}
[_mediaConnection close];
}
}
Swift
//ビデオ通話を開始する
func call(strDestId: String) {
let option = SKWCallOption()
_mediaConnection = _peer!.callWithId(strDestId, stream: _msLocal, options: option)
if _mediaConnection != nil {
self.setMediaCallbacks(self._mediaConnection!)
_bEstablished = true
}
self.updateUI()
}
//ビデオ通話を終了する
func closeChat(){
if _mediaConnection != nil{
if _msRemote != nil{
let remoteVideoView:SKWVideo = self.view.viewWithTag(ViewTag.TAG_REMOTE_VIDEO.hashValue) as! SKWVideo
remoteVideoView .removeSrc(_msRemote, track: 0)
_msRemote?.close()
_msRemote = nil
}
_mediaConnection?.close()
}
}
- 開発前の準備
- ビデオチャットの作成
- 2.1.サーバへ接続
- 2.2.接続成功・失敗
- 2.3.メディアの取得
- 2.4.相手から着信
- 2.5.相手へ発信
- 2.6.UIのセットアップ
- テキストチャットの作成
- 3.1.サーバへ接続
- 3.2.接続成功・失敗
- 3.3.相手から着信
- 3.4.相手へ発信
- 3.5.UIのセットアップ
- チャレンジ課題