我想在IOS(Swift)项目中使用webrtc。我发现正确实施它有很多困难。所以我搜索了一个库,这样我就可以了解它是如何实现的,以便以后自己完成。
我找到了这个项目: https://github.com/sushilthe/webrtc-ios-swift
它适用于https://apprtc.appspot.com。但它正在发布一个帖子?当你想加入一个房间时请求:
基本网址: https://apprtc.appspot.com/
附加到基地的部分:
static NSString * kARDRoomServerRegisterFormat = @ “%@ /加入/%@”;
结果:
https://apprtc.appspot.com/join/ 'roomnr'
我使用互联网上的一些资源构建了一个服务器:
$(document).ready(function() { //wait for DOM to be ready for JS execution
easyrtc.setVideoDims(1280, 768);
easyrtc.easyApp('vcdemo', 'self', ['peer'], connectSuccess, failureCallback); //connect to easyrtc app; initiate media sources and elements
});
//global state variables
var myEasyrtcId; //id of client in the signaling framework
//global functions
var connectSuccess = function(easyrtcid) { //join room as defined by "room" parameter in URL
myEasyrtcId = easyrtcid;
console.log('Connect successful. My id is ' + myEasyrtcId + '.');
var room = decodeURIComponent((new RegExp('[?|&]room=' + '([^&;]+?)(&|#|;|$)'). //retrieve room name from URL
exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
console.log('join room: ' + room);
easyrtc.joinRoom(room, null, joinSuccess, failureCallback);
};
var failureCallback = function(errorCode, errorMsg) { //log error
console.log(errorCode);
console.log(errorMsg);
};
var joinSuccess = function(roomName) { //listen for peers joining the room
setTimeout(function() {
console.log('successfully joined room: ' + roomName);
var peers = easyrtc.getRoomOccupantsAsArray(roomName) || []; //get list of client connected to room
console.log('peers: ' + peers);
var peersLength = peers.length;
if (peersLength > 2) { //support only 1-1 video conferences
alert('The meeting room is already full. ' +
'Only the two peers connecting first will be allowed access.');
} else if(peersLength === 1) { //if no other peer is connected
console.log('waiting for peer to connect...');
} else if(peers[0] != myEasyrtcId) {//get peer id
easyrtc.call(peers[0]);
} else {
easyrtc.call(peers[1]);
}
}, 100);
};
这可以通过这个网址完美地在chrome和firefox中使用:
本地主机:8080 /间= 123
当我重复使用该房间号时,我可以连接到该流。完美!
所以我认为我可以在应用程序中实现它,我已将serverHostUrl更改为:client?.serverHostUrl = "192.168.1.59:8080"
另一个变量是:
static NSString *kARDRoomServerRegisterFormat = @"%@/?room=%@";
但是当我尝试提交网址时出现错误:
Client Connecting
2016-10-17 19:24:51.151795 WebRTC iOS Swift[3944:1036130] Registering with room server.
2016-10-17 19:24:51.151900 WebRTC iOS Swift[3944:1036130] url = 192.168.1.59:8080/?room=123
2016-10-17 19:24:51.207496 WebRTC iOS Swift[3944:1036130] Error posting data: unsupported URL
Client Disconnected
我已经搜了几个小时为什么会这样。但我找不到问题。非常感谢你!
修改
错误的代码:
roomURL是:192.168.1.59:8080 /?room = 123当时。
[NSURLConnection sendAsyncPostToURL:roomURL
withData:nil
completionHandler:^(BOOL succeeded, NSData *data) {
ARDAppClient *strongSelf = weakSelf;
if (!succeeded) {
NSError *error = [self roomServerNetworkError];
[strongSelf.delegate appClient:strongSelf didError:error];
completionHandler(nil);
return;
}
ARDRegisterResponse *response =
[ARDRegisterResponse responseFromJSONData:data];
completionHandler(response);
}];