当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript phoenix.Socket类代码示例

本文整理汇总了TypeScript中phoenix.Socket的典型用法代码示例。如果您正苦于以下问题:TypeScript Socket类的具体用法?TypeScript Socket怎么用?TypeScript Socket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_presence

function test_presence() {
  const socket = new Socket('/ws', {params: {userToken: '123'}});

  const channel = socket.channel('room:123', {token: '123'});
  const presence = new Presence(channel);

  let presenceState = {};

  const logState = (state: Object) => {
    Presence.list(state, (id: string) => id).forEach(console.log);
  };

  channel.on('presence_state', (state) => {
    presenceState = Presence.syncState(presenceState, state);
    logState(presenceState);
  });

  channel.on('presence_diff', (diff) => {
    presenceState = Presence.syncState(presenceState, diff);
    logState(presenceState);
  });

  socket.connect();

  channel.join();
}
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:26,代码来源:phoenix-tests.ts

示例2: Socket

 return Observable.create((observer: Observer<string>) => {
   const options = { params: { token }};
   this.socket = new Socket('/socket', options);
   this.socket.onOpen(() => {
     observer.next(null);
   });
   this.socket.onError((err: Error) => {
     this.socket.disconnect();
     return observer.error(err);
   });
   this.socket.connect();
 })
开发者ID:akeating,项目名称:peap,代码行数:12,代码来源:socket.service.ts

示例3: test_hooks

function test_hooks() {
  const socket = new Socket("/ws", {params: {userToken: "123"}});
  socket.connect();

  socket.onError(() => console.log("there was an error with the connection!"));
  socket.onClose(() => console.log("the connection dropped"));

  const channel = socket.channel("room:123", {token: '123'});

  channel.onError(() => console.log("there was an error!"));
  channel.onClose(() => console.log("the channel has gone away gracefully"))
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:12,代码来源:phoenix-tests.ts

示例4: test_hooks

function test_hooks() {
  const socket = new Socket('/ws', {params: {userToken: '123'}});
  socket.connect();

  socket.onError(() => console.log('there was an error with the connection!'));
  socket.onClose(() => console.log('the connection dropped'));

  const channel = socket.channel('room:123', {token: '123'});

  channel.onError(() => console.log('there was an error!'));
  channel.onClose(() => console.log('the channel has gone away gracefully'));
}
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:12,代码来源:phoenix-tests.ts

示例5: test_channel

function test_channel() {
  const socket = new Socket("/ws", {params: {userToken: "123"}});
  socket.connect();

  const channel = socket.channel("room:123", {token: '123'});

  channel.on("new_msg", msg => console.log("Got message", msg));

  channel.push("new_msg", {body: 'some value'}, 10000)
   .receive("ok", (msg) => console.log("created message", msg))
   .receive("error", (reasons) => console.log("create failed", reasons))
   .receive("timeout", () => console.log("Networking issue..."));

  channel.join()
    .receive("ok", ({messages}) => console.log("catching up", messages))
    .receive("error", ({reason}) => console.log("failed join", reason))
    .receive("timeout", () => console.log("Networking issue. Still waiting..."));
}
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:18,代码来源:phoenix-tests.ts

示例6: inquiriesChannel

function inquiriesChannel(){
  let inquiriesChannel = socket.channel("inquiries")
  join(inquiriesChannel)
  inquiriesChannel.on("artworkinquiryrequest.inquired", payload => {

    if (payload.partner_locations.length && payload.user.location) {
      // Use the furthest away location
      let partnerLoc = payload.partner_locations[0]
      payload.partner_locations.forEach(loc => {
        if (getDistance(payload.user.location, loc) > getDistance(payload.user.location, partnerLoc)) {
          partnerLoc = loc
        }
      });

      addArc(map, allArcs, payload.user.location, partnerLoc)

      const distance =  Math.round(getDistance(payload.user.location, partnerLoc))

      const thumbnail = generateAThumbnail(
        payload.artwork.images[0].image_urls.medium,
        `${payload.properties.inquireable.name}</span> from <span>${payload.partner.name}</span>.`,
        `${shortDateString(payload.user.location)} ✈ ${shortDateString(partnerLoc)} (${distance}km)`
      )

      messagesContainer.insertBefore(thumbnail, messagesContainer.firstChild);
    }
  })
}
开发者ID:artsy,项目名称:APR,代码行数:28,代码来源:socket.ts

示例7: purchasesChannel

function purchasesChannel() {
  let purchaseChannel = socket.channel("purchases")
  join(purchaseChannel)

  purchaseChannel.on("purchase.purchased", payload => {
    if (payload.partner_locations.length && payload.user.location) {
      // Use the furthest away location
      let partnerLoc = payload.partner_locations[0]
      payload.partner_locations.forEach(loc => {
        if (getDistance(payload.user.location, loc) > getDistance(payload.user.location, partnerLoc)) {
          partnerLoc = loc
        }
      });

      addArc(map, allArcs, partnerLoc, payload.user.location, { strokeWidth: 2, strokeColor: '#6E1FFF', greatArc: true} )

      const distance =  Math.round(getDistance(payload.user.location, partnerLoc))

      const thumbnail = generateAThumbnail(
        payload.artwork.images[0].image_urls.medium,
        `${payload.properties.inquireable.name}</span> from <span>${payload.properties.partner.name}</span>.`,
        `${shortDateString(payload.user.location)} ✈ ${shortDateString(partnerLoc)} (${distance}km)`
      )

      messagesContainer.insertBefore(thumbnail, messagesContainer.firstChild);
    }
  })
}
开发者ID:artsy,项目名称:APR,代码行数:28,代码来源:socket.ts

示例8: joinChannel

 joinChannel(channelName: string): Observable<any> {
   this.channel = this.socket.channel(channelName, {});
   return Observable.create((observer: Observer<string>) => {
     this.channel.on('new_message', payload => {
       this.dataService.receiveAlertMessage(payload.body);
     });
     this.channel.on('current_count', payload => {
       this.dataService.setCurrentCount(payload.body);
     });
     this.channel.join()
       .receive('ok', resp => {
         observer.next(resp);
       })
       .receive('error', err => {
         return observer.error(err);
       });
   });
 }
开发者ID:akeating,项目名称:peap,代码行数:18,代码来源:socket.service.ts

示例9: join

 join(topic, params?) {
   this.channel = this.socket.channel(topic, params);
   return this.channel.join();
 }
开发者ID:mciastek,项目名称:emotions-wheel-app,代码行数:4,代码来源:socket.service.ts


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