• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang channelling.Session类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/strukturag/spreed-webrtc/go/channelling.Session的典型用法代码示例。如果您正苦于以下问题:Golang Session类的具体用法?Golang Session怎么用?Golang Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Session类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: HandleSessions

func (api *channellingAPI) HandleSessions(session *channelling.Session, sessions *channelling.DataSessionsRequest) (*channelling.DataSessions, error) {
	switch sessions.Type {
	case "contact":
		if !api.config.WithModule("contacts") {
			return nil, channelling.NewDataError("contacts_not_enabled", "incoming contacts session request with contacts disabled")
		}
		userID, err := api.ContactManager.GetContactID(session, sessions.Token)
		if err != nil {
			return nil, err
		}
		return &channelling.DataSessions{
			Type:     "Sessions",
			Users:    api.SessionManager.GetUserSessions(session, userID),
			Sessions: sessions,
		}, nil
	case "session":
		id, err := session.DecodeAttestation(sessions.Token)
		if err != nil {
			return nil, channelling.NewDataError("bad_attestation", err.Error())
		}
		session, ok := api.Unicaster.GetSession(id)
		if !ok {
			return nil, channelling.NewDataError("no_such_session", "cannot retrieve session")
		}
		return &channelling.DataSessions{
			Type:     "Sessions",
			Users:    []*channelling.DataSession{session.Data()},
			Sessions: sessions,
		}, nil
	default:
		return nil, channelling.NewDataError("bad_request", "unknown sessions request type")
	}
}
开发者ID:strukturag,项目名称:spreed-webrtc,代码行数:33,代码来源:handle_sessions.go


示例2: HandleRoom

func (api *channellingAPI) HandleRoom(session *channelling.Session, room *channelling.DataRoom) (*channelling.DataRoom, error) {
	room, err := api.RoomStatusManager.UpdateRoom(session, room)
	if err == nil {
		session.Broadcast(room)
	}

	return room, err
}
开发者ID:strukturag,项目名称:spreed-webrtc,代码行数:8,代码来源:handle_room.go


示例3: HandleAuthentication

func (api *channellingAPI) HandleAuthentication(session *channelling.Session, st *channelling.SessionToken) (*channelling.DataSelf, error) {
	if err := api.SessionManager.Authenticate(session, st, ""); err != nil {
		log.Println("Authentication failed", err, st.Userid, st.Nonce)
		return nil, err
	}

	log.Println("Authentication success", session.Userid())
	self, err := api.HandleSelf(session)
	if err == nil {
		session.BroadcastStatus()
	}

	return self, err
}
开发者ID:strukturag,项目名称:spreed-webrtc,代码行数:14,代码来源:handle_authentication.go


示例4: HandleConference

func (api *channellingAPI) HandleConference(session *channelling.Session, conference *channelling.DataConference) {
	if room, ok := api.RoomStatusManager.Get(session.Roomid); ok && room.GetType() == channelling.RoomTypeConference {
		log.Println("Refusing client-side conference update for server-managed conferences.")
		return
	}

	// Check conference maximum size.
	if len(conference.Conference) > maxConferenceSize {
		log.Println("Refusing to create conference above limit.", len(conference.Conference))
		return
	}

	// Send conference update to anyone.
	for _, id := range conference.Conference {
		if id != session.Id {
			session.Unicast(id, conference, nil)
		}
	}
}
开发者ID:strukturag,项目名称:spreed-webrtc,代码行数:19,代码来源:handle_conference.go


示例5: HandleHello

func (api *channellingAPI) HandleHello(session *channelling.Session, hello *channelling.DataHello, sender channelling.Sender) (*channelling.DataWelcome, error) {
	// TODO(longsleep): Filter room id and user agent.
	session.Update(&channelling.SessionUpdate{Types: []string{"Ua"}, Ua: hello.Ua})

	// Compatibily for old clients.
	roomName := hello.Name
	if roomName == "" {
		roomName = hello.Id
	}

	room, err := session.JoinRoom(roomName, hello.Type, hello.Credentials, sender)
	if err != nil {
		return nil, err
	}

	return &channelling.DataWelcome{
		Type:  "Welcome",
		Room:  room,
		Users: api.RoomStatusManager.RoomUsers(session),
	}, nil
}
开发者ID:strukturag,项目名称:spreed-webrtc,代码行数:21,代码来源:handle_hello.go


示例6: HandleChat

func (api *channellingAPI) HandleChat(session *channelling.Session, chat *channelling.DataChat) {
	// TODO(longsleep): Limit sent chat messages per incoming connection.
	msg := chat.Chat
	to := chat.To

	if !msg.NoEcho {
		session.Unicast(session.Id, chat, nil)
	}
	msg.Time = time.Now().Format(time.RFC3339)
	if to == "" {
		// TODO(longsleep): Check if chat broadcast is allowed.
		if session.Hello {
			api.StatsCounter.CountBroadcastChat()
			session.Broadcast(chat)
		}
	} else {
		if msg.Status != nil {
			if msg.Status.ContactRequest != nil {
				if !api.config.WithModule("contacts") {
					return
				}
				if err := api.ContactManager.ContactrequestHandler(session, to, msg.Status.ContactRequest); err != nil {
					log.Println("Ignoring invalid contact request.", err)
					return
				}
				msg.Status.ContactRequest.Userid = session.Userid()
			}
		} else {
			api.StatsCounter.CountUnicastChat()
		}

		session.Unicast(to, chat, nil)
		if msg.Mid != "" {
			// Send out delivery confirmation status chat message.
			session.Unicast(session.Id, &channelling.DataChat{To: to, Type: "Chat", Chat: &channelling.DataChatMessage{Mid: msg.Mid, Status: &channelling.DataChatStatus{State: "sent"}}}, nil)
		}
	}
}
开发者ID:strukturag,项目名称:spreed-webrtc,代码行数:38,代码来源:handle_chat.go


示例7: HandleSelf

func (api *channellingAPI) HandleSelf(session *channelling.Session) (*channelling.DataSelf, error) {
	token, err := api.SessionEncoder.EncodeSessionToken(session)
	if err != nil {
		log.Println("Error in OnRegister", err)
		return nil, err
	}

	log.Println("Created new session token", len(token), token)
	self := &channelling.DataSelf{
		Type:       "Self",
		Id:         session.Id,
		Sid:        session.Sid,
		Userid:     session.Userid(),
		Suserid:    api.SessionEncoder.EncodeSessionUserID(session),
		Token:      token,
		Version:    api.config.Version,
		ApiVersion: apiVersion,
		Turn:       api.TurnDataCreator.CreateTurnData(session),
		Stun:       api.config.StunURIs,
	}
	api.BusManager.Trigger(channelling.BusManagerSession, session.Id, session.Userid(), nil, nil)

	return self, nil
}
开发者ID:strukturag,项目名称:spreed-webrtc,代码行数:24,代码来源:handle_self.go


示例8: HandleLeave

func (api *channellingAPI) HandleLeave(session *channelling.Session) error {
	session.LeaveRoom()

	return nil
}
开发者ID:strukturag,项目名称:spreed-webrtc,代码行数:5,代码来源:handle_leave.go


示例9: OnIncoming

func (api *channellingAPI) OnIncoming(sender channelling.Sender, session *channelling.Session, msg *channelling.DataIncoming) (interface{}, error) {
	var pipeline *channelling.Pipeline
	switch msg.Type {
	case "Self":
		return api.HandleSelf(session)
	case "Hello":
		if msg.Hello == nil {
			return nil, channelling.NewDataError("bad_request", "message did not contain Hello")
		}

		return api.HandleHello(session, msg.Hello, sender)
	case "Offer":
		if msg.Offer == nil || msg.Offer.Offer == nil {
			log.Println("Received invalid offer message.", msg)
			break
		}
		if _, ok := msg.Offer.Offer["_token"]; !ok {
			pipeline = api.PipelineManager.GetPipeline(channelling.PipelineNamespaceCall, sender, session, msg.Offer.To)
			// Trigger offer event when offer has no token, so this is
			// not triggered for peerxfer and peerscreenshare offers.
			api.BusManager.Trigger(channelling.BusManagerOffer, session.Id, msg.Offer.To, nil, pipeline)
		}

		session.Unicast(msg.Offer.To, msg.Offer, pipeline)
	case "Candidate":
		if msg.Candidate == nil || msg.Candidate.Candidate == nil {
			log.Println("Received invalid candidate message.", msg)
			break
		}

		pipeline = api.PipelineManager.GetPipeline(channelling.PipelineNamespaceCall, sender, session, msg.Candidate.To)
		session.Unicast(msg.Candidate.To, msg.Candidate, pipeline)
	case "Answer":
		if msg.Answer == nil || msg.Answer.Answer == nil {
			log.Println("Received invalid answer message.", msg)
			break
		}
		if _, ok := msg.Answer.Answer["_token"]; !ok {
			pipeline = api.PipelineManager.GetPipeline(channelling.PipelineNamespaceCall, sender, session, msg.Answer.To)
			// Trigger answer event when answer has no token. so this is
			// not triggered for peerxfer and peerscreenshare answers.
			api.BusManager.Trigger(channelling.BusManagerAnswer, session.Id, msg.Answer.To, nil, pipeline)
		}

		session.Unicast(msg.Answer.To, msg.Answer, pipeline)
	case "Users":
		return api.HandleUsers(session)
	case "Authentication":
		if msg.Authentication == nil || msg.Authentication.Authentication == nil {
			return nil, channelling.NewDataError("bad_request", "message did not contain Authentication")
		}

		return api.HandleAuthentication(session, msg.Authentication.Authentication)
	case "Bye":
		if msg.Bye == nil {
			log.Println("Received invalid bye message.", msg)
			break
		}
		pipeline = api.PipelineManager.GetPipeline(channelling.PipelineNamespaceCall, sender, session, msg.Bye.To)
		api.BusManager.Trigger(channelling.BusManagerBye, session.Id, msg.Bye.To, nil, pipeline)

		session.Unicast(msg.Bye.To, msg.Bye, pipeline)
		if pipeline != nil {
			pipeline.Close()
		}
	case "Status":
		if msg.Status == nil {
			log.Println("Received invalid status message.", msg)
			break
		}

		//log.Println("Status", msg.Status)
		session.Update(&channelling.SessionUpdate{Types: []string{"Status"}, Status: msg.Status.Status})
		session.BroadcastStatus()
	case "Chat":
		if msg.Chat == nil || msg.Chat.Chat == nil {
			log.Println("Received invalid chat message.", msg)
			break
		}

		api.HandleChat(session, msg.Chat)
	case "Conference":
		if msg.Conference == nil {
			log.Println("Received invalid conference message.", msg)
			break
		}

		api.HandleConference(session, msg.Conference)
	case "Alive":
		return msg.Alive, nil
	case "Sessions":
		if msg.Sessions == nil || msg.Sessions.Sessions == nil {
			return nil, channelling.NewDataError("bad_request", "message did not contain Sessions")
		}

		return api.HandleSessions(session, msg.Sessions.Sessions)
	case "Room":
		if msg.Room == nil {
			return nil, channelling.NewDataError("bad_request", "message did not contain Room")
		}
//.........这里部分代码省略.........
开发者ID:strukturag,项目名称:spreed-webrtc,代码行数:101,代码来源:api.go



注:本文中的github.com/strukturag/spreed-webrtc/go/channelling.Session类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang mux.Vars函数代码示例发布时间:2022-05-29
下一篇:
Golang templates.RenderContext类代码示例发布时间:2022-05-29
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap