yirtc-sdk-web
Version:
基于WebRTC的实时音视频SDK
77 lines (76 loc) • 2.48 kB
JavaScript
import { WebSocketSignaling } from './signaling/websocket';
import { SocketIOSignaling } from './signaling/socketio';
import { WebRTCAdapter } from './rtc/web';
import { WebMediaAdapter } from './media/web';
/**
* 信令适配器类型
*/
export var SignalingType;
(function (SignalingType) {
SignalingType["WEBSOCKET"] = "websocket";
SignalingType["SOCKET_IO"] = "socket.io";
SignalingType["CUSTOM"] = "custom";
})(SignalingType || (SignalingType = {}));
/**
* 平台类型
*/
export var PlatformType;
(function (PlatformType) {
PlatformType["WEB"] = "web";
PlatformType["ANDROID"] = "android";
PlatformType["IOS"] = "ios";
})(PlatformType || (PlatformType = {}));
/**
* 适配器工厂类
*/
export class AdapterFactory {
/**
* 创建信令适配器
* @param type 信令适配器类型
* @param config 信令配置
* @returns SignalingInterface
*/
static createSignalingAdapter(type, config) {
switch (type) {
case SignalingType.WEBSOCKET:
return new WebSocketSignaling(config);
// Socket.IO信令适配器
case SignalingType.SOCKET_IO:
return new SocketIOSignaling(config);
default:
throw new Error(`不支持的信令适配器类型: ${type}`);
}
}
/**
* 创建RTC适配器
* @param platform 平台类型
* @returns RTCInterface
*/
static createRTCAdapter(platform) {
switch (platform) {
case PlatformType.WEB:
return new WebRTCAdapter();
// 可以在这里添加其他平台的RTC适配器实现
// case PlatformType.ANDROID:
// return new AndroidRTCAdapter();
default:
throw new Error(`不支持的平台类型: ${platform}`);
}
}
/**
* 创建媒体适配器
* @param platform 平台类型
* @returns MediaInterface
*/
static createMediaAdapter(platform) {
switch (platform) {
case PlatformType.WEB:
return new WebMediaAdapter();
// 可以在这里添加其他平台的媒体适配器实现
// case PlatformType.ANDROID:
// return new AndroidMediaAdapter();
default:
throw new Error(`不支持的平台类型: ${platform}`);
}
}
}